Skip to content

Commit 1761553

Browse files
guangyaoguangyao
authored andcommitted
优化录音按钮,使用YYLabel代替M80AttributedLabel,增加了电话链接和优化url链接点击跳转
1 parent 306325c commit 1761553

File tree

69 files changed

+20295
-1992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+20295
-1992
lines changed

ios/RCTAuroraIMUI.xcodeproj/project.pbxproj

Lines changed: 210 additions & 58 deletions
Large diffs are not rendered by default.

ios/RCTAuroraIMUI/DWCustomView/InputView/DWRecordButton.m

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
@interface DWRecordButton (){
1616
BOOL isTouchOut;
1717
BOOL isHasVoiceAuth;
18+
BOOL isBegin;//是否开始录音
1819
}
1920
@property (copy, nonatomic) NSString *strRecordPath;
21+
@property (strong, nonatomic) UILongPressGestureRecognizer *btnTap;
2022
@end
2123

2224

@@ -35,13 +37,13 @@ - (instancetype)init
3537
self.layer.cornerRadius = 5.0f;
3638
self.layer.borderWidth = 0.5;
3739
self.layer.borderColor = [UIColor colorWithWhite:0.6 alpha:1.0].CGColor;
38-
40+
self.btnTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(clickLongGest:)];
41+
self.btnTap.cancelsTouchesInView = NO;
42+
[self addGestureRecognizer:_btnTap];
3943
// [self addTarget:self action:@selector(recordTouchDown) forControlEvents:UIControlEventTouchDown];
4044
// [self addTarget:self action:@selector(recordTouchUpOutside) forControlEvents:UIControlEventTouchUpOutside];
4145
// [self addTarget:self action:@selector(recordTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
4246
// [self addTarget:self action:@selector(recordTouchDragEnter) forControlEvents:UIControlEventTouchDragEnter];
43-
// [self addTarget:self action:@selector(recordTouchDragInside) forControlEvents:UIControlEventTouchDragInside];
44-
// [self addTarget:self action:@selector(recordTouchDragOutside) forControlEvents:UIControlEventTouchDragOutside];
4547
// [self addTarget:self action:@selector(recordTouchDragExit) forControlEvents:UIControlEventTouchDragExit];
4648

4749
}
@@ -80,6 +82,14 @@ - (void)setButtonStateWithCancel
8082
[self setTitle:strCancel forState:UIControlStateNormal];
8183
}
8284

85+
//长按
86+
- (void)clickLongGest:(UILongPressGestureRecognizer *)gest{
87+
if (gest.state == UIGestureRecognizerStateBegan){
88+
isBegin = YES;
89+
[self recordTouchDown];
90+
}
91+
}
92+
8393
#pragma mark -- 事件方法回调
8494
//开始录音
8595
- (void)recordTouchDown
@@ -88,9 +98,9 @@ - (void)recordTouchDown
8898
if ([self getVoiceAVAuthorizationStatus]) {
8999
isTouchOut = NO;
90100
if (!self.selected) {
101+
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Start"];
91102
self.selected = YES;
92103
[self setButtonStateWithRecording];
93-
[[NSNotificationCenter defaultCenter]postNotificationName:@"RecordChangeNotification" object:@"Start"];
94104
_strRecordPath = [self getSaveRecordPath];
95105
[[DWAudioRecorderManager shareManager] audioRecorderStartWithFilePath:_strRecordPath ];
96106
}
@@ -135,36 +145,44 @@ - (void)recordTouchDragExit{
135145
}
136146

137147
#pragma mark touch--
138-
139148
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
140-
[self recordTouchDown];
149+
NSLog(@"touchesBegan~~~~~~~~~~~~~");
141150
}
142151

143152
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
144-
UITouch *touch = [touches anyObject];
145-
CGPoint touchPoint = [touch locationInView:self];
146-
if (touchPoint.y > 0) {//结束
147-
[self recordTouchUpInside];
148-
}else{//取消
149-
[self recordTouchUpOutside];
153+
NSLog(@"touchesEnded~~~~~~~~~~~~~");
154+
if (isBegin) {
155+
isBegin = NO;
156+
UITouch *touch = [touches anyObject];
157+
CGPoint touchPoint = [touch locationInView:self];
158+
if (touchPoint.y > 0) {//结束
159+
[self recordTouchUpInside];
160+
}else{//取消
161+
[self recordTouchUpOutside];
162+
}
150163
}
151164
}
152165

153166
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
154167
NSLog(@"touchesMoved~~~~~~");
155-
UITouch *touch = [touches anyObject];
156-
CGPoint touchPoint = [touch locationInView:self];
157-
if ((touchPoint.y < 0) && (!isTouchOut)) {//移出按钮范围
158-
isTouchOut = YES;
159-
[self recordTouchDragExit];
160-
}else if((touchPoint.y > 0) && isTouchOut){//进入按钮范围
161-
isTouchOut = NO;
162-
[self recordTouchDragEnter];
168+
if (isBegin) {
169+
UITouch *touch = [touches anyObject];
170+
CGPoint touchPoint = [touch locationInView:self];
171+
if ((touchPoint.y < 0) && (!isTouchOut)) {//移出按钮范围
172+
isTouchOut = YES;
173+
[self recordTouchDragExit];
174+
}else if((touchPoint.y > 0) && isTouchOut){//进入按钮范围
175+
isTouchOut = NO;
176+
[self recordTouchDragEnter];
177+
}
163178
}
164179
}
165180

166181
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{//取消录音
167-
[self recordTouchUpOutside];
182+
NSLog(@"touchesCancelled~~~~~~");
183+
if (isBegin) {
184+
[self recordTouchUpOutside];
185+
}
168186
}
169187

170188
//判断录音权限
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// YYTextContainerView.h
3+
// YYText <https://github.com/ibireme/YYText>
4+
//
5+
// Created by ibireme on 15/4/21.
6+
// Copyright (c) 2015 ibireme.
7+
//
8+
// This source code is licensed under the MIT-style license found in the
9+
// LICENSE file in the root directory of this source tree.
10+
//
11+
12+
#import <UIKit/UIKit.h>
13+
14+
#if __has_include(<YYText/YYText.h>)
15+
#import <YYText/YYTextLayout.h>
16+
#else
17+
#import "YYTextLayout.h"
18+
#endif
19+
20+
NS_ASSUME_NONNULL_BEGIN
21+
22+
/**
23+
A simple view to diaplay `YYTextLayout`.
24+
25+
@discussion This view can become first responder. If this view is first responder,
26+
all the action (such as UIMenu's action) would forward to the `hostView` property.
27+
Typically, you should not use this class directly.
28+
29+
@warning All the methods in this class should be called on main thread.
30+
*/
31+
@interface YYTextContainerView : UIView
32+
33+
/// First responder's aciton will forward to this view.
34+
@property (nullable, nonatomic, weak) UIView *hostView;
35+
36+
/// Debug option for layout debug. Set this property will let the view redraw it's contents.
37+
@property (nullable, nonatomic, copy) YYTextDebugOption *debugOption;
38+
39+
/// Text vertical alignment.
40+
@property (nonatomic) YYTextVerticalAlignment textVerticalAlignment;
41+
42+
/// Text layout. Set this property will let the view redraw it's contents.
43+
@property (nullable, nonatomic, strong) YYTextLayout *layout;
44+
45+
/// The contents fade animation duration when the layout's contents changed. Default is 0 (no animation).
46+
@property (nonatomic) NSTimeInterval contentsFadeDuration;
47+
48+
/// Convenience method to set `layout` and `contentsFadeDuration`.
49+
/// @param layout Same as `layout` property.
50+
/// @param fadeDuration Same as `contentsFadeDuration` property.
51+
- (void)setLayout:(nullable YYTextLayout *)layout withFadeDuration:(NSTimeInterval)fadeDuration;
52+
53+
@end
54+
55+
NS_ASSUME_NONNULL_END
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//
2+
// YYTextContainerView.m
3+
// YYText <https://github.com/ibireme/YYText>
4+
//
5+
// Created by ibireme on 15/4/21.
6+
// Copyright (c) 2015 ibireme.
7+
//
8+
// This source code is licensed under the MIT-style license found in the
9+
// LICENSE file in the root directory of this source tree.
10+
//
11+
12+
#import "YYTextContainerView.h"
13+
14+
@implementation YYTextContainerView {
15+
BOOL _attachmentChanged;
16+
NSMutableArray *_attachmentViews;
17+
NSMutableArray *_attachmentLayers;
18+
}
19+
20+
- (instancetype)initWithFrame:(CGRect)frame {
21+
self = [super initWithFrame:frame];
22+
if (!self) return nil;
23+
self.backgroundColor = [UIColor clearColor];
24+
_attachmentViews = [NSMutableArray array];
25+
_attachmentLayers = [NSMutableArray array];
26+
return self;
27+
}
28+
29+
- (void)setDebugOption:(YYTextDebugOption *)debugOption {
30+
BOOL needDraw = _debugOption.needDrawDebug;
31+
_debugOption = debugOption.copy;
32+
if (_debugOption.needDrawDebug != needDraw) {
33+
[self setNeedsDisplay];
34+
}
35+
}
36+
37+
- (void)setTextVerticalAlignment:(YYTextVerticalAlignment)textVerticalAlignment {
38+
if (_textVerticalAlignment == textVerticalAlignment) return;
39+
_textVerticalAlignment = textVerticalAlignment;
40+
[self setNeedsDisplay];
41+
}
42+
43+
- (void)setContentsFadeDuration:(NSTimeInterval)contentsFadeDuration {
44+
if (_contentsFadeDuration == contentsFadeDuration) return;
45+
_contentsFadeDuration = contentsFadeDuration;
46+
if (contentsFadeDuration <= 0) {
47+
[self.layer removeAnimationForKey:@"contents"];
48+
}
49+
}
50+
51+
- (void)setLayout:(YYTextLayout *)layout {
52+
if (_layout == layout) return;
53+
_layout = layout;
54+
_attachmentChanged = YES;
55+
[self setNeedsDisplay];
56+
}
57+
58+
- (void)setLayout:(YYTextLayout *)layout withFadeDuration:(NSTimeInterval)fadeDuration {
59+
self.contentsFadeDuration = fadeDuration;
60+
self.layout = layout;
61+
}
62+
63+
- (void)drawRect:(CGRect)rect {
64+
// fade content
65+
[self.layer removeAnimationForKey:@"contents"];
66+
if (_contentsFadeDuration > 0) {
67+
CATransition *transition = [CATransition animation];
68+
transition.duration = _contentsFadeDuration;
69+
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
70+
transition.type = kCATransitionFade;
71+
[self.layer addAnimation:transition forKey:@"contents"];
72+
}
73+
74+
// update attachment
75+
if (_attachmentChanged) {
76+
for (UIView *view in _attachmentViews) {
77+
if (view.superview == self) [view removeFromSuperview];
78+
}
79+
for (CALayer *layer in _attachmentLayers) {
80+
if (layer.superlayer == self.layer) [layer removeFromSuperlayer];
81+
}
82+
[_attachmentViews removeAllObjects];
83+
[_attachmentLayers removeAllObjects];
84+
}
85+
86+
// draw layout
87+
CGSize boundingSize = _layout.textBoundingSize;
88+
CGPoint point = CGPointZero;
89+
if (_textVerticalAlignment == YYTextVerticalAlignmentCenter) {
90+
if (_layout.container.isVerticalForm) {
91+
point.x = -(self.bounds.size.width - boundingSize.width) * 0.5;
92+
} else {
93+
point.y = (self.bounds.size.height - boundingSize.height) * 0.5;
94+
}
95+
} else if (_textVerticalAlignment == YYTextVerticalAlignmentBottom) {
96+
if (_layout.container.isVerticalForm) {
97+
point.x = -(self.bounds.size.width - boundingSize.width);
98+
} else {
99+
point.y = (self.bounds.size.height - boundingSize.height);
100+
}
101+
}
102+
[_layout drawInContext:UIGraphicsGetCurrentContext() size:self.bounds.size point:point view:self layer:self.layer debug:_debugOption cancel:nil];
103+
104+
// update attachment
105+
if (_attachmentChanged) {
106+
_attachmentChanged = NO;
107+
for (YYTextAttachment *a in _layout.attachments) {
108+
if ([a.content isKindOfClass:[UIView class]]) [_attachmentViews addObject:a.content];
109+
if ([a.content isKindOfClass:[CALayer class]]) [_attachmentLayers addObject:a.content];
110+
}
111+
}
112+
}
113+
114+
- (void)setFrame:(CGRect)frame {
115+
CGSize oldSize = self.bounds.size;
116+
[super setFrame:frame];
117+
if (!CGSizeEqualToSize(oldSize, self.bounds.size)) {
118+
[self setNeedsLayout];
119+
}
120+
}
121+
122+
- (void)setBounds:(CGRect)bounds {
123+
CGSize oldSize = self.bounds.size;
124+
[super setBounds:bounds];
125+
if (!CGSizeEqualToSize(oldSize, self.bounds.size)) {
126+
[self setNeedsLayout];
127+
}
128+
}
129+
130+
#pragma mark - UIResponder forward
131+
132+
- (BOOL)canBecomeFirstResponder {
133+
return YES;
134+
}
135+
136+
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
137+
return [self.hostView canPerformAction:action withSender:sender];
138+
}
139+
140+
- (id)forwardingTargetForSelector:(SEL)aSelector {
141+
return self.hostView;
142+
}
143+
144+
@end

0 commit comments

Comments
 (0)