Skip to content

Commit 306325c

Browse files
guangyaoguangyao
authored andcommitted
1、优化录音按钮点击 2、修复表情页发送按钮的问题
1 parent eaecf08 commit 306325c

File tree

7 files changed

+135
-183
lines changed

7 files changed

+135
-183
lines changed

ios/RCTAuroraIMUI/DWCustomView/DWEmoticonView/NIMInputEmoticonContainerView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@property (nonatomic, strong) NIMInputEmoticonTabView *tabView;
3232
@property (nonatomic, weak) id<NIMInputEmoticonProtocol> delegate;
3333
//@property (nonatomic, weak) id<NIMSessionConfig> config;
34+
- (void)setupSendBtnCanSend:(BOOL)enabled;
3435

3536
@end
3637

ios/RCTAuroraIMUI/DWCustomView/DWEmoticonView/NIMInputEmoticonContainerView.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ - (void)pageViewScrollEnd: (NIMPageView *)pageView
284284
#pragma mark - EmoticonButtonTouchDelegate
285285
- (void)selectedEmoticon:(NIMInputEmoticon*)emoticon catalogID:(NSString*)catalogID{
286286
if ([self.delegate respondsToSelector:@selector(selectedEmoticon:catalog:description:)]) {
287+
if ((catalogID) && (!self.tabView.sendButton.enabled)){//非删除按钮
288+
[self setupSendBtnCanSend:YES];
289+
}
287290
[self.delegate selectedEmoticon:emoticon.emoticonID catalog:catalogID description:emoticon.tag];
288291
}
289292
}
@@ -340,5 +343,17 @@ - (NIMInputEmoticonTabView *)tabView
340343
return _tabView;
341344
}
342345

346+
#pragma mark --set sendBtn
347+
- (void)setupSendBtnCanSend:(BOOL)enabled{
348+
self.tabView.sendButton.enabled = enabled;
349+
if (enabled) {
350+
[self.tabView.sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
351+
[self.tabView.sendButton setBackgroundColor:[UIColor blueColor]];
352+
}else{
353+
[self.tabView.sendButton setTitleColor:[UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1.0] forState:UIControlStateNormal];
354+
[self.tabView.sendButton setBackgroundColor:[UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1.0]];
355+
}
356+
}
357+
343358
@end
344359

ios/RCTAuroraIMUI/DWCustomView/InputView/DWAudioRecorderManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ - (void)audioRecorderStop
183183
[fileMgr removeItemAtPath:self.filePath error:&err];
184184
}
185185
}else{
186-
[[NSNotificationCenter defaultCenter]postNotificationName:@"FinishAudioRecordNotification" object:nil];
186+
[[NSNotificationCenter defaultCenter]postNotificationName:@"FinishAudioRecordNotification" object:self.filePath];
187187
}
188188
}
189189

ios/RCTAuroraIMUI/DWCustomView/InputView/DWInputBarControl.m

Lines changed: 14 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
#import "UIView+Extend.h"
1111
#import "NIMInputEmoticonManager.h"
1212
#import "NIMInputAtCache.h"
13-
#import "DWAudioRecorderManager.h"
13+
//#import "DWAudioRecorderManager.h"
1414
#import <AVFoundation/AVFoundation.h>
1515

1616
#define toolBackColor [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1.0];
1717

18-
@interface DWInputBarControl ()<HPGrowingTextViewDelegate,DWRecordDelegate,NIMInputEmoticonProtocol>{
18+
@interface DWInputBarControl ()<HPGrowingTextViewDelegate,NIMInputEmoticonProtocol>{
1919
UIView *line;
2020
CGFloat tmpGrowViewH;
21-
BOOL isHasVoiceAuth;
2221
}
2322
@property (nonatomic, strong) NIMInputAtCache *atCache;
24-
@property (copy, nonatomic) NSString *strRecordPath;
23+
//@property (copy, nonatomic) NSString *strRecordPath;
2524
@end
2625

2726
@implementation DWInputBarControl
@@ -42,7 +41,7 @@ - (void)addNotification{
4241
//监听选择@人的回调
4342
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickGetAtPerson:) name:@"GetAtPersonNotification" object:nil];
4443
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(growingTextViewDeleteBackward) name:@"GrowTextViewDeleteBackWard" object:nil];
45-
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickSendRecordMessage) name:@"FinishAudioRecordNotification" object:nil];//录音结束,发送录音message
44+
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickSendRecordMessage:) name:@"FinishAudioRecordNotification" object:nil];//录音结束,发送录音message
4645
}
4746

4847
#pragma mark -- 监听键盘
@@ -58,8 +57,6 @@ - (void)clickKeyBoardChange:(NSNotification *)noti{
5857
self.onShowKeyboard(@{@"inputHeight":@(tmpH),@"showType":@(0)});
5958
}
6059
// [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeMessageListHeightNotification" object:@{@"listViewHeight":@(screenH - 60 - tmpH)}];
61-
62-
6360
}
6461

6562
- (void)hidenFeatureView{
@@ -143,15 +140,16 @@ - (void)setDefaultToolHeight:(CGFloat)defaultToolHeight{
143140
[self creatUI];
144141
}
145142
//发送录音message
146-
- (void)clickSendRecordMessage{
143+
- (void)clickSendRecordMessage:(NSNotification *)noti{
144+
NSString *strRecordPath = noti.object;
147145
dispatch_async(dispatch_get_main_queue(), ^{
148146
[_recordBtn setButtonStateWithNormal];
149147
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Complete"];
150148
if (self.onSendRecordMessage) {
151-
self.onSendRecordMessage(@{@"Path":self.strRecordPath});
149+
self.onSendRecordMessage(@{@"Path":strRecordPath});
152150
}
153151
});
154-
NSLog(@"strRecordPath:%@",self.strRecordPath);
152+
NSLog(@"strRecordPath:%@",strRecordPath);
155153
}
156154

157155

@@ -188,7 +186,6 @@ - (void)addSubContentView{
188186
_recordBtn = [[DWRecordButton alloc]init];
189187
_recordBtn.textArr = @[@"按住 说话",@"松开 结束",@"松开 取消"];
190188
_recordBtn.hidden = YES;
191-
_recordBtn.delegate = self;
192189
[_toolView addSubview:_recordBtn];
193190

194191
_showExpressionBtn = [[UIButton alloc]init];
@@ -204,6 +201,8 @@ - (void)addSubContentView{
204201
_expressionView.delegate = self;
205202
[self addSubview:_expressionView];
206203
_expressionView.hidden = YES;
204+
NIMInputEmoticonTabView *tab = _expressionView.tabView;
205+
207206

208207
self.functionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenW, menuViewH)];
209208
[self addSubview:_functionView];
@@ -263,88 +262,6 @@ - (void)clickControlBtn:(UIButton *)btn{
263262
}
264263
}
265264

266-
//获取保存录音路径
267-
- (NSString *)getSaveRecordPath{
268-
NSString *dirPath = NSTemporaryDirectory();
269-
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
270-
NSString *recordName = [NSString stringWithFormat:@"%.0f.aac",interval];
271-
NSString *soundFilePath = [dirPath stringByAppendingPathComponent:recordName];
272-
return soundFilePath;
273-
}
274-
275-
- (BOOL)getVoiceAVAuthorizationStatus{
276-
[AVCaptureDevice requestAccessForMediaType:
277-
AVMediaTypeAudio completionHandler:^(BOOL granted)
278-
{//麦克风权限
279-
if (granted) {
280-
isHasVoiceAuth = YES;
281-
}else{
282-
isHasVoiceAuth = NO;
283-
UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请您设置允许APP访问您的麦克风\n设置>隐私>麦克风" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
284-
[alart show];
285-
}
286-
}];
287-
return isHasVoiceAuth;
288-
}
289-
290-
291-
#pragma mark DWRecordButton录音按钮代理方法
292-
- (void)recordTouchDownAction:(DWRecordButton *)btn{
293-
NSLog(@"开始录音");
294-
if ([self getVoiceAVAuthorizationStatus]) {
295-
if (!btn.selected) {
296-
btn.selected = YES;
297-
[btn setButtonStateWithRecording];
298-
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Start"];
299-
_strRecordPath = [self getSaveRecordPath];
300-
[[DWAudioRecorderManager shareManager] audioRecorderStartWithFilePath:_strRecordPath ];
301-
}
302-
}
303-
}
304-
- (void)recordTouchUpOutsideAction:(DWRecordButton *)btn{
305-
if (isHasVoiceAuth) {
306-
NSLog(@"取消录音");
307-
[btn setButtonStateWithNormal];
308-
[[DWAudioRecorderManager shareManager] audioRecorderCancel];
309-
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Canceled"];
310-
}
311-
}
312-
- (void)recordTouchUpInsideAction:(DWRecordButton *)btn{
313-
if (isHasVoiceAuth) {
314-
NSLog(@"完成录音");
315-
[btn setButtonStateWithNormal];
316-
[[DWAudioRecorderManager shareManager] audioRecorderStop];
317-
}
318-
}
319-
320-
- (void)recordTouchDragInsideAction:(DWRecordButton *)btn{
321-
//持续调用
322-
323-
}
324-
- (void)recordTouchDragOutsideAction:(DWRecordButton *)btn{
325-
//持续调用
326-
327-
}
328-
//中间状态 从 TouchDragOutside ---> TouchDragInside
329-
- (void)recordTouchDragEnterAction:(DWRecordButton *)btn{
330-
if (isHasVoiceAuth) {
331-
if (btn.selected) {
332-
NSLog(@"继续录音");
333-
[btn setButtonStateWithRecording];
334-
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Continue"];
335-
}
336-
}
337-
}
338-
//中间状态 从 TouchDragInside ---> TouchDragOutside
339-
- (void)recordTouchDragExitAction:(DWRecordButton *)btn{
340-
if (isHasVoiceAuth) {
341-
if (btn.selected) {
342-
NSLog(@"将要取消录音");
343-
[btn setButtonStateWithCancel];
344-
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Move"];
345-
}
346-
}
347-
}
348265

349266
#pragma mark - HPGrowingTextViewDelegate
350267
- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height {
@@ -408,7 +325,6 @@ - (void)selectedEmoticon:(NSString*)emoticonID catalog:(NSString*)emotCatalogID
408325
self.inputGrowView.text = [NSString stringWithFormat:@"%@%@",_inputGrowView.text,description];
409326
}else{
410327
//发送贴图消息
411-
412328
}
413329
}
414330
}
@@ -417,6 +333,7 @@ - (void)didPressSend:(id)sender{
417333
NSArray *uuidArr = [self.atCache allAtUid:self.inputGrowView.text];
418334
self.onSendTextMessage(@{@"text":self.inputGrowView.text,@"IDArr":uuidArr});
419335
self.inputGrowView.text = @"";
336+
[self.expressionView setupSendBtnCanSend:NO];
420337
}
421338

422339
//删除Text
@@ -485,6 +402,9 @@ - (void)deleteText:(NSRange)range
485402
NSRange newSelectRange = NSMakeRange(range.location, 0);
486403
[self.inputGrowView setText:newText];
487404
self.inputGrowView.selectedRange = newSelectRange;
405+
if ((![self.inputGrowView.text length]) && !self.expressionView.hidden) {
406+
[self.expressionView setupSendBtnCanSend:NO];
407+
}
488408
}
489409
}
490410
//删除@的人

ios/RCTAuroraIMUI/DWCustomView/InputView/DWRecordButton.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,8 @@
99
#import <UIKit/UIKit.h>
1010
@class DWRecordButton;
1111

12-
@protocol DWRecordDelegate <NSObject>
13-
14-
@optional
15-
- (void)recordTouchDownAction:(DWRecordButton *)btn;
16-
- (void)recordTouchUpOutsideAction:(DWRecordButton *)btn;
17-
- (void)recordTouchUpInsideAction:(DWRecordButton *)btn;
18-
- (void)recordTouchDragEnterAction:(DWRecordButton *)btn;
19-
- (void)recordTouchDragInsideAction:(DWRecordButton *)btn;
20-
- (void)recordTouchDragOutsideAction:(DWRecordButton *)btn;
21-
- (void)recordTouchDragExitAction:(DWRecordButton *)btn;
22-
23-
@end
24-
25-
2612
@interface DWRecordButton : UIButton
2713

28-
@property (assign, nonatomic) id<DWRecordDelegate> delegate;
2914
@property (copy, nonatomic) NSArray *textArr;
3015
- (void)setButtonStateWithRecording;
3116
- (void)setButtonStateWithNormal;

0 commit comments

Comments
 (0)