Skip to content

Commit f9ae58f

Browse files
guangyaoguangyao
authored andcommitted
增加点击发送验证码功能 onClickSendValidation
1 parent 66c6488 commit f9ae58f

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Protocol/IMUIMessageMessageCollectionViewDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import UIKit
4444
* Tells the delegate that user tap statusView in message cell
4545
*/
4646
@objc optional func messageCollectionView(didTapStatusViewInCell: UICollectionViewCell, model: IMUIMessageModelProtocol)
47+
48+
@objc optional func messageCollectionView(didTapValidationWithModel: IMUIMessageModelProtocol)
49+
4750

4851
/**
4952
* Tells the delegate that the message cell will show in screen

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUINotificationMessageCell.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
1414
var titleLable = UILabel()
1515
var backView = UIView()
1616
let screenW = UIScreen.main.bounds.size.width
17-
// let labelGest = UITapGestureRecognizer.init()
17+
let labelGest = UITapGestureRecognizer.init()
18+
var locationIndex:Int = 0
1819

1920
override init(frame: CGRect) {
2021
super.init(frame: frame)
2122
titleLable.textColor = UIColor.white
2223
titleLable.font = UIFont.systemFont(ofSize: 12)
23-
// titleLable.font = UIFont.init(name: "helvetica", size: 12)
2424
titleLable.numberOfLines = 0
2525
titleLable.isUserInteractionEnabled = true
2626
backView.backgroundColor = UIColor.init(red: 206/255.0, green: 206/255.0, blue: 206/255.0, alpha: 1)
2727
backView.layer.cornerRadius = 5
2828
backView.clipsToBounds = true
2929
backView.addSubview(titleLable)
30-
// labelGest.addTarget(self, action: #selector(self.clickTapValidation(sender:)))
30+
labelGest.addTarget(self, action: #selector(self.clickTapValidation(sender:)))
3131
bubbleView.addSubview(backView)
3232
}
3333

@@ -56,12 +56,13 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
5656
self.backView.frame = CGRect(origin: CGPoint(x:titleX, y:titleY), size: CGSize(width:titleSize.width+10, height:titleSize.height+10))
5757
self.titleLable.frame = CGRect(origin: CGPoint(x:5, y:5), size: CGSize(width:titleSize.width, height:titleSize.height))
5858
let attString = NSMutableAttributedString.init(string: strTitle)
59-
// if strTitle.hasSuffix("发送朋友验证"){
60-
// self.titleLable.addGestureRecognizer(labelGest)
61-
// let tmpArr = rangesOf(searchString: "发送朋友验证", inString: strTitle)
62-
// let tmpR:NSRange = tmpArr.lastObject as! NSRange
63-
// attString.addAttribute(NSForegroundColorAttributeName, value: UIColor.init(red: 35/255.0, green: 141/255.0, blue: 250/255.0, alpha: 1), range: tmpR)
64-
// }
59+
if strTitle.hasSuffix("发送朋友验证"){
60+
self.titleLable.addGestureRecognizer(labelGest)
61+
let tmpArr = rangesOf(searchString: "发送朋友验证", inString: strTitle)
62+
let tmpR:NSRange = tmpArr.lastObject as! NSRange
63+
locationIndex = tmpR.location
64+
attString.addAttribute(NSForegroundColorAttributeName, value: UIColor.init(red: 35/255.0, green: 141/255.0, blue: 250/255.0, alpha: 1), range: tmpR)
65+
}
6566
self.titleLable.attributedText = attString
6667

6768
}
@@ -93,12 +94,11 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
9394
func clickTapValidation(sender : UITapGestureRecognizer){
9495
let touchPoint = sender.location(in: self.titleLable)
9596
let path:CGMutablePath = CGMutablePath()
96-
path.addRect(CGRect(x:0, y:0, width:self.titleLable.frame.size.width, height:self.titleLable.frame.size.height))
97+
path.addRect(CGRect(x:0, y:0, width:self.titleLable.frame.size.width, height:self.titleLable.frame.size.height+10))
9798
let framesetter = CTFramesetterCreateWithAttributedString(self.titleLable.attributedText!)
9899
let ctframe = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, nil)
99100
//获取行数
100101
let lines:NSArray = CTFrameGetLines(ctframe)
101-
print("line:\(CFArrayGetCount(lines)) line:\(self.titleLable.numberOfLines) height:\(self.titleLable.frame.size.height)")
102102
let numOfLine:NSInteger = self.titleLable.numberOfLines > 0 ? min(self.titleLable.numberOfLines, CFArrayGetCount(lines)) : CFArrayGetCount(lines)
103103
if numOfLine != 0 {
104104
var lineOrigins:[CGPoint] = Array(repeating:.zero,count:numOfLine)
@@ -114,7 +114,10 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
114114
let lineFrame = CGRect(x:baseLineOri.x, y:baseLineOri.y-ascent, width:lineWidth, height:ascent+descent)
115115
if lineFrame.contains(touchPoint){
116116
let index = CTLineGetStringIndexForPosition(line, touchPoint)
117-
print("index:\(index)")
117+
if index.hashValue > self.locationIndex {
118+
self.delegate?.messageCollectionView?(didTapValidationWithModel: self.message!)
119+
}
120+
118121
}
119122
}
120123
}

ios/RCTAuroraIMUI/RCTMessageListView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@property (nonatomic, copy) RCTBubblingEventBlock onClickChangeAutoScroll;
3535
@property(nonatomic, copy) RCTBubblingEventBlock onClickLongTapCell;
3636
@property(nonatomic, copy) RCTBubblingEventBlock onClickScanImageView;
37+
@property(nonatomic, copy) RCTBubblingEventBlock onClickSendValidation;
3738
//@property(nonatomic, copy) RCTBubblingEventBlock onClickTapImageMessageBubble;
3839

3940

ios/RCTAuroraIMUI/RCTMessageListViewManager.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ - (void)messageCollectionView:(UICollectionView * _Nonnull)_ didEndDisplaying:(U
4343
/// Tells the delegate when messageCollection beginDragging
4444
- (void)messageCollectionView:(UICollectionView * _Nonnull)willBeginDragging;
4545

46+
- (void)messageCollectionViewWithDidTapValidationWithModel:(id <IMUIMessageModelProtocol> _Nonnull)model;
47+
4648

4749
@end
4850

@@ -61,6 +63,8 @@ @implementation RCTMessageListViewManager
6163
RCT_EXPORT_VIEW_PROPERTY(onClickChangeAutoScroll, RCTBubblingEventBlock)
6264
RCT_EXPORT_VIEW_PROPERTY(onClickLongTapCell, RCTBubblingEventBlock)
6365
RCT_EXPORT_VIEW_PROPERTY(onClickScanImageView, RCTBubblingEventBlock)
66+
RCT_EXPORT_VIEW_PROPERTY(onClickSendValidation, RCTBubblingEventBlock)
67+
6468
//RCT_EXPORT_VIEW_PROPERTY(onClickTapImageMessageBubble, RCTBubblingEventBlock)
6569

6670
RCT_EXPORT_MODULE()
@@ -322,6 +326,12 @@ -(void)onClickScanImageView:(NSString *)strResult{
322326
_messageList.onClickScanImageView(@{ @"result": strResult});
323327
}
324328

329+
- (void)messageCollectionViewWithDidTapValidationWithModel:(id<IMUIMessageModelProtocol>)model{
330+
if(!_messageList.onClickSendValidation) { return; }
331+
_messageList.onClickSendValidation(@{@"message": @""});
332+
}
333+
334+
325335
//- (void)messageCollectionViewWithDidTapImageMessageBubbleInCell:(CGRect)rect model:(id<IMUIMessageModelProtocol> _Nonnull)model{
326336
// if (!_messageList.onClickTapImageMessageBubble) {return;}
327337
// RCTMessageModel *message = model;

messagelist.ios.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class MessageList extends Component {
7070
}
7171

7272
_onBeginDragMessageList(event: Event) {
73-
if (!this.props.onStatusViewClick) {
73+
if (!this.props.onBeginDragMessageList) {
7474
return;
7575
}
7676
this.props.onBeginDragMessageList();
@@ -95,6 +95,12 @@ export default class MessageList extends Component {
9595
}
9696
this.props.onClickScanImageView(event.nativeEvent);
9797
}
98+
_onClickSendValidation(event:Event){
99+
if(!this.props.onClickSendValidation){
100+
return;
101+
}
102+
this.props.onClickSendValidation();
103+
}
98104

99105
render() {
100106
return (
@@ -109,6 +115,7 @@ export default class MessageList extends Component {
109115
onClickLoadMessages={this._onClickLoadMessages.bind(this)}
110116
onClickChangeAutoScroll={this._onClickChangeAutoScroll.bind(this)}
111117
onClickScanImageView={this._onClickScanImageView.bind(this)}
118+
onClickSendValidation={this._onClickSendValidation.bind(this)}
112119
/>
113120
);
114121
}
@@ -127,6 +134,7 @@ MessageList.propTypes = {
127134
onClickLoadMessages:PropTypes.func,
128135
onClickChangeAutoScroll:PropTypes.func,
129136
onClickScanImageView:PropTypes.func,
137+
onClickSendValidation:PropTypes.func,
130138
sendBubble: PropTypes.string,
131139
receiveBubble: PropTypes.string,
132140
sendBubble: PropTypes.object,

0 commit comments

Comments
 (0)