You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.9 KiB

5 years ago
  1. //
  2. // SlackTextViewController
  3. // https://github.com/slackhq/SlackTextViewController
  4. //
  5. // Copyright 2014-2016 Slack Technologies, Inc.
  6. // Licence: MIT-Licence
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class SLKTextView;
  10. @class SLKInputAccessoryView;
  11. typedef NS_ENUM(NSUInteger, SLKCounterStyle) {
  12. SLKCounterStyleNone,
  13. SLKCounterStyleSplit,
  14. SLKCounterStyleCountdown,
  15. SLKCounterStyleCountdownReversed
  16. };
  17. typedef NS_ENUM(NSUInteger, SLKCounterPosition) {
  18. SLKCounterPositionTop,
  19. SLKCounterPositionBottom
  20. };
  21. typedef NS_ENUM(NSUInteger, SLKInputBarState) {
  22. SLKInputBarStateNormal,
  23. SLKInputBarStateHighlight,
  24. SLKInputBarStateDisabled
  25. };
  26. @protocol SLKInputBarViewDelegate <NSObject>
  27. - (void)barStateDidChange:(SLKInputBarState)state;
  28. @end
  29. NS_ASSUME_NONNULL_BEGIN
  30. /** @name A custom tool bar encapsulating messaging controls. */
  31. @interface SLKTextInputbar : UIToolbar
  32. @property (nonatomic, assign) SLKInputBarState barState;
  33. @property (nonatomic, weak) id<SLKInputBarViewDelegate> barDelegate;
  34. /** The centered text input view.
  35. The maximum number of lines is configured by default, to best fit each devices dimensions.
  36. For iPhone 4 (<=480pts): 4 lines
  37. For iPhone 5 & 6 (>=568pts): 6 lines
  38. For iPad (>=768pts): 8 lines
  39. */
  40. @property (nonatomic, readonly, strong) SLKTextView *textView;
  41. /** Optional view to host outlets under the text view, adjusting its height based on its subviews. Non-visible by default. Subviews' layout should be configured using auto-layout as well. */
  42. @property (nonatomic, readonly, strong) UIView *contentView;
  43. /** The custom input accessory view, used as empty achor view to detect the keyboard frame. */
  44. @property (nonatomic, readonly, strong) SLKInputAccessoryView *inputAccessoryView;
  45. /** The left action button action. */
  46. @property (nonatomic, strong) UIButton *leftButton;
  47. /** The right action button action. */
  48. @property (nonatomic, strong) UIButton *rightButton;
  49. /** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
  50. @property (nonatomic, readwrite) BOOL autoHideRightButton;
  51. /** YES if animations should have bouncy effects. Default is YES. */
  52. @property (nonatomic, assign) BOOL bounces;
  53. /** The inner padding to use when laying out content in the view. Default is {5, 8, 5, 8}. */
  54. @property (nonatomic, assign) UIEdgeInsets contentInset;
  55. /** The minimum height based on the intrinsic content size's. */
  56. @property (nonatomic, readonly) CGFloat minimumInputbarHeight;
  57. /** The most appropriate height calculated based on the amount of lines of text and other factors. */
  58. @property (nonatomic, readonly) CGFloat appropriateHeight;
  59. /** Hide input buttons **/
  60. - (void)hideLeftButton;
  61. - (void)hideRightButton;
  62. - (void)hideAllButtons;
  63. - (void)setButtonsHidden:(BOOL)hidden;
  64. #pragma mark - Initialization
  65. ///------------------------------------------------
  66. /// @name Initialization
  67. ///------------------------------------------------
  68. /**
  69. Initializes a text input bar with a class to be used for the text view
  70. @param textViewClass The class to be used when creating the text view. May be nil. If provided, the class must be a subclass of SLKTextView
  71. @return An initialized SLKTextInputbar object or nil if the object could not be created.
  72. */
  73. - (instancetype)initWithTextViewClass:(Class)textViewClass;
  74. #pragma mark - Text Editing
  75. ///------------------------------------------------
  76. /// @name Text Editing
  77. ///------------------------------------------------
  78. /** The view displayed on top if the text input bar, containing the button outlets, when editing is enabled. */
  79. @property (nonatomic, strong) UIView *editorContentView;
  80. /** The title label displayed in the middle of the accessoryView. */
  81. @property (nonatomic, strong) UILabel *editorTitle;
  82. /** The 'cancel' button displayed left in the accessoryView. */
  83. @property (nonatomic, strong) UIButton *editorLeftButton;
  84. /** The 'accept' button displayed right in the accessoryView. */
  85. @property (nonatomic, strong) UIButton *editorRightButton;
  86. /** The accessory view's maximum height. Default is 38 pts. */
  87. @property (nonatomic, assign) CGFloat editorContentViewHeight;
  88. /** A Boolean value indicating whether the control is in edit mode. */
  89. @property (nonatomic, getter = isEditing) BOOL editing;
  90. /**
  91. Verifies if the text can be edited.
  92. @param text The text to be edited.
  93. @return YES if the text is editable.
  94. */
  95. - (BOOL)canEditText:(NSString *)text;
  96. /**
  97. Begins editing the text, by updating the 'editing' flag and the view constraints.
  98. */
  99. - (void)beginTextEditing;
  100. /**
  101. End editing the text, by updating the 'editing' flag and the view constraints.
  102. */
  103. - (void)endTextEdition;
  104. #pragma mark - Text Counting
  105. ///------------------------------------------------
  106. /// @name Text Counting
  107. ///------------------------------------------------
  108. /** The label used to display the character counts. */
  109. @property (nonatomic, readonly) UILabel *charCountLabel;
  110. /** The maximum character count allowed. If larger than 0, a character count label will be displayed on top of the right button. Default is 0, which means limitless.*/
  111. @property (nonatomic, readwrite) NSUInteger maxCharCount;
  112. /** The character counter formatting. Ignored if maxCharCount is 0. Default is None. */
  113. @property (nonatomic, assign) SLKCounterStyle counterStyle;
  114. /** The character counter layout style. Ignored if maxCharCount is 0. Default is SLKCounterPositionTop. */
  115. @property (nonatomic, assign) SLKCounterPosition counterPosition;
  116. /** YES if the maxmimum character count has been exceeded. */
  117. @property (nonatomic, readonly) BOOL limitExceeded;
  118. /** The normal color used for character counter label. Default is lightGrayColor. */
  119. @property (nonatomic, strong, readwrite) UIColor *charCountLabelNormalColor;
  120. /** The color used for character counter label when it has exceeded the limit. Default is redColor. */
  121. @property (nonatomic, strong, readwrite) UIColor *charCountLabelWarningColor;
  122. @end
  123. NS_ASSUME_NONNULL_END