TUIInputBar.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Created by Tencent on 2023/06/09.
  2. // Copyright © 2023 Tencent. All rights reserved.
  3. /**
  4. * This file declares the TUIInputBarDelegate protocol and the TUIInputBar class.
  5. * TUI input bar, a UI component used to detect and obtain user input.
  6. * TUIInputBar, the UI component at the bottom of the chat message. Includes text input box, emoji button, voice button, and "+" button ("More" button)
  7. * TUIInputBarDelegate provides callbacks for various situations of the input bar, including the callback for the emoticon of clicking the input bar, the
  8. * "more" view, and the voice button. And callbacks to send message, send voice, change input height.
  9. */
  10. #import <TIMCommon/TIMCommonModel.h>
  11. #import <TUICore/TUIThemeManager.h>
  12. #import <UIKit/UIKit.h>
  13. #import "TUIResponderTextView.h"
  14. #define kTUIInputNoramlFont [UIFont systemFontOfSize:16.0]
  15. #define kTUIInputNormalTextColor TUIChatDynamicColor(@"chat_input_text_color", @"#000000")
  16. @class TUIInputBar;
  17. /////////////////////////////////////////////////////////////////////////////////
  18. //
  19. // TUIInputBarDelegate
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////
  22. @protocol TUIInputBarDelegate <NSObject>
  23. /**
  24. * Callback after clicking the emoji button - "smiley" button.
  25. * You can use this callback to achieve: After clicking the emoticon button, the corresponding emoticon view is displayed.
  26. */
  27. - (void)inputBarDidTouchFace:(TUIInputBar *)textView;
  28. /**
  29. * Callback after more button - "+" is clicked.
  30. * You can use this callback to achieve: corresponding user's click operation to display more corresponding views.
  31. */
  32. - (void)inputBarDidTouchMore:(TUIInputBar *)textView;
  33. /**
  34. * Callback after clicking the voice button - "Sound Wave" icon .
  35. * You can use this callback to display the corresponding operation prompt view and start voice recording
  36. */
  37. - (void)inputBarDidTouchVoice:(TUIInputBar *)textView;
  38. /**
  39. * Callback when input bar height changes
  40. * This callback is fired when the InputBar height changes when you click the voice button, emoji button, "+" button, or call out/retract the keyboard
  41. * You can use this callback to achieve: UI layout adjustment when InputBar height changes through this callback function.
  42. * In the default implementation of TUIKit, this callback function further calls the didChangeHeight delegate in TUIInputController to adjust the height of the
  43. * UI layout after processing the appearance of the expression view and more views.
  44. */
  45. - (void)inputBar:(TUIInputBar *)textView didChangeInputHeight:(CGFloat)offset;
  46. /**
  47. * Callback when sending a text message.
  48. * This callback is fired when you send a text message through the InputBar (click the send button from the keyboard).
  49. * You can use this callback to get the content of the InputBar and send the message.
  50. * In the default implementation of TUIKit, this callback further calls the didSendMessage delegate in TUIInputController for further logical processing of
  51. * message sending after processing the appearance of the expression view and more views.
  52. */
  53. - (void)inputBar:(TUIInputBar *)textView didSendText:(NSString *)text;
  54. /**
  55. * Callback when sending voice
  56. * This callback is triggered when you long press and release the voice button.
  57. * You can use this callback to process the recorded voice information and send the voice message.
  58. * In the default implementation of TUIKit, this callback function further calls the didSendMessage delegate in TUIInputController for further logical
  59. * processing of message sending after processing the appearance of the expression view and more views.
  60. */
  61. - (void)inputBar:(TUIInputBar *)textView didSendVoice:(NSString *)path;
  62. /**
  63. * Callback after entering text containing the @ character
  64. */
  65. - (void)inputBarDidInputAt:(TUIInputBar *)textView;
  66. /**
  67. * Callback after removing text containing @ characters (e.g. removing @xxx)
  68. */
  69. - (void)inputBar:(TUIInputBar *)textView didDeleteAt:(NSString *)text;
  70. /**
  71. * Callback after keyboard button click
  72. * After clicking the emoticon button, the "smiley face" icon at the corresponding position will become the "keyboard" icon, which is the keyboard button at
  73. * this time. You can use this callback to: hide the currently displayed emoticon view or more views, and open the keyboard.
  74. */
  75. - (void)inputBarDidTouchKeyboard:(TUIInputBar *)textView;
  76. /**
  77. * Callback after clicking delete button on keyboard
  78. */
  79. - (void)inputBarDidDeleteBackward:(TUIInputBar *)textView;
  80. - (void)inputTextViewShouldBeginTyping:(UITextView *)textView;
  81. - (void)inputTextViewShouldEndTyping:(UITextView *)textView;
  82. @end
  83. /////////////////////////////////////////////////////////////////////////////////
  84. //
  85. // TUIInputBar
  86. //
  87. /////////////////////////////////////////////////////////////////////////////////
  88. @interface TUIInputBar : UIView
  89. /**
  90. * Separtor
  91. */
  92. @property(nonatomic, strong) UIView *lineView;
  93. /**
  94. * Voice button
  95. * Switch to voice input state after clicking
  96. */
  97. @property(nonatomic, strong) UIButton *micButton;
  98. /**
  99. * Keyboard button
  100. * Switch to keyboard input state after clicking
  101. */
  102. @property(nonatomic, strong) UIButton *keyboardButton;
  103. /**
  104. * Input view
  105. */
  106. @property(nonatomic, strong) TUIResponderTextView *inputTextView;
  107. /**
  108. * Emoticon button
  109. * Switch to emoji input state after clicking
  110. */
  111. @property(nonatomic, strong) UIButton *faceButton;
  112. /**
  113. * More button
  114. * A button that, when clicked, opens up more menu options
  115. */
  116. @property(nonatomic, strong) UIButton *moreButton;
  117. /**
  118. * Record button, long press the button to start recording
  119. */
  120. @property(nonatomic, strong) UIButton *recordButton;
  121. @property(nonatomic, weak) id<TUIInputBarDelegate> delegate;
  122. @property(nonatomic, copy) void (^inputBarTextChanged)(UITextView * textview);
  123. @property(nonatomic, assign) BOOL isFromReplyPage;
  124. - (void)defaultLayout;
  125. /**
  126. * Add emoticon text
  127. * Used to input emoticon text in the current text input box
  128. *
  129. * @param emoji The string representation of the emoticon to be entered.
  130. */
  131. - (void)addEmoji:(TUIFaceCellData *)emoji;
  132. - (void)backDelete;
  133. - (void)clearInput;
  134. - (NSString *)getInput;
  135. - (void)updateTextViewFrame;
  136. - (void)changeToKeyboard;
  137. - (void)addDraftToInputBar:(NSAttributedString *)draft;
  138. - (void)addWordsToInputBar:(NSAttributedString *)words;
  139. @end