Skip to content

Commit e165035

Browse files
author
Vitaliy G
committed
added the documentation for QMInputToolbar
1 parent 19bbaba commit e165035

3 files changed

Lines changed: 81 additions & 30 deletions

File tree

QMChatViewController/QMChatViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ - (void)viewDidLoad {
8888
//Customize your toolbar buttons
8989
self.inputToolbar.contentView.leftBarButtonItem = [self accessoryButtonItem];
9090
self.inputToolbar.contentView.rightBarButtonItem = [self sendButtonItem];
91-
self.inputToolbar.audioRecordingIsEnabled = YES;
91+
self.inputToolbar.audioRecordingEnabled = YES;
9292

9393
__weak __typeof(self) weakSelf = self;
9494
self.systemInputToolbar = [[QMKVOView alloc] init];

QMChatViewController/Views/CustomUI/InputToolBar/QMInputToolbar.h

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,56 @@
4141

4242
@optional
4343

44-
- (BOOL)messagesInputToolbarAudioRecordingEnabled:(QMInputToolbar *)toolbar;
44+
/**
45+
Asks the delegate if it can start the audio recording by touching the audio record button.
46+
47+
@param toolbar An instance of `QBChatMessageInputToolbar`
48+
@return YES if the audio recording should start or NO if it should not.
49+
*/
50+
- (BOOL)messagesInputToolbarAudioRecordingShouldStart:(QMInputToolbar *)toolbar;
51+
52+
/**
53+
This method is called when an audio recording has started.
54+
55+
@param toolbar An instance of `QBChatMessageInputToolbar`
56+
*/
4557
- (void)messagesInputToolbarAudioRecordingStart:(QMInputToolbar *)toolbar;
58+
59+
/**
60+
This method is called when an audio recording has cancelled.
61+
62+
@param toolbar An instance of `QBChatMessageInputToolbar`
63+
*/
4664
- (void)messagesInputToolbarAudioRecordingCancel:(QMInputToolbar *)toolbar;
65+
66+
/**
67+
This method is called when an audio recording has completed.
68+
69+
@param toolbar An instance of `QBChatMessageInputToolbar`
70+
*/
4771
- (void)messagesInputToolbarAudioRecordingComplete:(QMInputToolbar *)toolbar;
72+
73+
/**
74+
This method is called when an audio recording has paused because of timeout.
75+
@discussion: This mehod will be called only if 'inputPanelAudioRecordingMaximumDuration:' is adopted.
76+
@param toolbar An instance of `QBChatMessageInputToolbar`.
77+
*/
4878
- (void)messagesInputToolbarAudioRecordingPausedByTimeOut:(QMInputToolbar *)toolbar;
4979

80+
/**
81+
Tells the delegate to return the current duration.
82+
83+
@param toolbar An instance of `QBChatMessageInputToolbar`
84+
@return Current duration of the audio recorder.
85+
*/
5086
- (NSTimeInterval)inputPanelAudioRecordingDuration:(QMInputToolbar *)toolbar;
87+
88+
/**
89+
Tells the delegate to return the maximum duration.
90+
91+
@param toolbar An instance of `QBChatMessageInputToolbar`
92+
@return The maximum duration of the recorded audio.
93+
*/
5194
- (NSTimeInterval)inputPanelAudioRecordingMaximumDuration:(QMInputToolbar *)toolbar;
5295

5396
@end
@@ -102,11 +145,22 @@
102145
*/
103146
- (QMToolbarContentView *)loadToolbarContentView;
104147

105-
@property (assign, nonatomic) BOOL audioRecordingIsEnabled;
148+
/**
149+
Enables ability to record and send audio attachments.
150+
@default NO
151+
@discussion: If YES, the 'audio record' button is enabled on the 'send button' side.
152+
@warning: Methods of delegate for audio recording should be adopted.
153+
*/
154+
@property (assign, nonatomic) BOOL audioRecordingEnabled;
155+
156+
/**
157+
Cancels current audio recording and calls the delegate method 'messagesInputToolbarAudioRecordingCancel:'
158+
*/
159+
- (void)cancelAudioRecording;
106160

107-
- (void)startAudioRecording;
108-
- (void)finishAudioRecording;
109-
- (void)forceFinishRecording;
161+
/**
162+
Performs the shake animation for audio record button.
163+
*/
110164
- (void)shakeControls;
111165

112166
@end

QMChatViewController/Views/CustomUI/InputToolBar/QMInputToolbar.m

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ - (instancetype)init {
5151
return self;
5252
}
5353

54-
- (void)setAudioRecordingIsEnabled:(BOOL)audioRecordingIsEnabled {
54+
- (void)setAudioRecordingEnabled:(BOOL)audioRecordingEnabled {
5555

56-
if (_audioRecordingIsEnabled != audioRecordingIsEnabled) {
57-
58-
_audioRecordingIsEnabled = audioRecordingIsEnabled;
56+
if (_audioRecordingEnabled != audioRecordingEnabled) {
57+
_audioRecordingEnabled = audioRecordingEnabled;
5958
[self toggleSendButtonEnabled];
6059
}
6160
}
@@ -126,28 +125,26 @@ - (void)toggleButtons {
126125
BOOL hasTextAttachment = [self.contentView.textView hasTextAttachment];
127126
BOOL hasDataToSend = hasText || hasTextAttachment;
128127

128+
UIButton *buttonToUpdate;
129+
UIView *buttonContainer;
129130
if (self.sendButtonOnRight) {
130-
131-
self.contentView.rightBarButtonItem.hidden = !hasDataToSend;
132-
self.contentView.rightBarButtonItem.enabled = [self.contentView.textView hasText];
133-
134-
if (!self.audioRecordButtonItem.superview) {
135-
[self.contentView.rightBarButtonContainerView addSubview:[self audioRecordButtonItem]];
136-
137-
[self audioRecordButtonItem].translatesAutoresizingMaskIntoConstraints = false;
138-
[self addCenterConstraintsToItem:self.contentView.rightBarButtonContainerView];
139-
}
131+
buttonToUpdate = self.contentView.rightBarButtonItem;
132+
buttonContainer = self.contentView.rightBarButtonContainerView;
140133
}
141134
else {
135+
buttonToUpdate = self.contentView.leftBarButtonItem;
136+
buttonContainer = self.contentView.leftBarButtonContainerView;
137+
}
138+
139+
buttonToUpdate.hidden = !hasDataToSend;
140+
buttonToUpdate.enabled = [self.contentView.textView hasText];
141+
142+
if (!self.audioRecordButtonItem.superview) {
142143

143-
self.contentView.leftBarButtonItem.hidden = !hasDataToSend;
144-
self.contentView.leftBarButtonItem.enabled = [self.contentView.textView hasText];
144+
[buttonContainer addSubview:[self audioRecordButtonItem]];
145145

146-
if (!self.audioRecordButtonItem.superview) {
147-
[self.contentView.leftBarButtonContainerView addSubview:[self audioRecordButtonItem]];
148-
[self audioRecordButtonItem].translatesAutoresizingMaskIntoConstraints = false;
149-
[self addCenterConstraintsToItem:self.contentView.leftBarButtonContainerView];
150-
}
146+
[self audioRecordButtonItem].translatesAutoresizingMaskIntoConstraints = false;
147+
[self addCenterConstraintsToItem:buttonContainer];
151148
}
152149

153150
self.audioRecordButtonItem.hidden = hasDataToSend;
@@ -174,7 +171,7 @@ - (void)addCenterConstraintsToItem:(UIView *)itemToAdd {
174171

175172
- (void)toggleSendButtonEnabled {
176173

177-
if (self.audioRecordingIsEnabled) {
174+
if (self.audioRecordingEnabled) {
178175

179176
[self toggleButtons];
180177
return;
@@ -326,7 +323,7 @@ - (void)finishAudioRecording {
326323

327324
- (void)recordButtonInteractionDidBegin {
328325

329-
if ([self.delegate messagesInputToolbarAudioRecordingEnabled:self]) {
326+
if ([self.delegate messagesInputToolbarAudioRecordingShouldStart:self]) {
330327

331328
self.recording = YES;
332329
[self setShowRecordingInterface:true velocity:0.0f];
@@ -346,7 +343,7 @@ - (void)recordButtonInteractionDidCancel:(CGFloat)velocity {
346343
}
347344
}
348345

349-
- (void)forceFinishRecording {
346+
- (void)cancelAudioRecording {
350347

351348
if (self.isRecording) {
352349
self.recording = NO;

0 commit comments

Comments
 (0)