Skip to content

Commit 723113a

Browse files
guangyaoguangyao
authored andcommitted
增加查看历史时收到新消息不滚动,修复发红包后输入栏不正确的问题
1 parent c397b97 commit 723113a

11 files changed

Lines changed: 80 additions & 45 deletions

File tree

ios/RCTAuroraIMUI/DWCustomView/InputView/DWInputBarControl.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ - (void)addNotification{
4545
#pragma mark -- 监听键盘
4646
- (void)clickKeyBoardChange:(NSNotification *)noti{
4747
NSDictionary *userInfo = noti.userInfo;
48-
// NSLog(@"clickKeyBoardChange:%@",userInfo);
48+
NSLog(@"clickKeyBoardChange:%@",userInfo);
4949
CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
5050
// self.height = screenH - endFrame.origin.y+self.inputViewHeight;
51-
NSLog(@"----height:%f",self.height);
51+
NSLog(@"----height:%f ----y:%f",self.height,endFrame.origin.y);
5252
CGFloat tmpH = screenH - endFrame.origin.y+self.inputViewHeight;
5353
CGFloat keyboardY = screenH - 20;
5454
if (!(self.showExpressionBtn.selected || self.showMenuBtn.selected) || (keyboardY > endFrame.origin.y)) {
55+
NSLog(@"进来了~~~~~");
5556
if(!self.onShowKeyboard) { return; }
5657
self.onShowKeyboard(@{@"inputHeight":@(tmpH),@"showType":@(0)});
5758
}

ios/RCTAuroraIMUI/IMUIMessageCollectionView/M80AttributedLabel/M80AttributedLabel/M80AttributedLabel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ - (CGSize)getTheLabelSize:(CGSize)maxSize{
654654
tmpW = 30;
655655
}
656656
if (tmpH < 30) {
657-
tmpH = 18;
657+
tmpH = 15;
658658
}
659659
return CGSizeMake(tmpW, tmpH );
660660
}

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Protocol/IMUIMessageMessageCollectionViewDelegate.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import UIKit
2727
@objc optional func messageCollectionView(didShowMenuStr: String, model: IMUIMessageModelProtocol)
2828
@objc optional func messageCollectionView(openMessageBubbleUrl: String)
2929
@objc optional func messageCollectionView(reloadMoreData:String)
30-
@objc optional func messageCollectionView(tapCellView:UICollectionViewCell)
30+
@objc optional func messageCollectionView(tapCellView:String)
31+
@objc optional func messageCollectionView(changeAutoScroll:Bool)
32+
3133

3234

3335
/**

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUIBaseMessageCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,14 @@ open class IMUIBaseMessageCell: UICollectionViewCell, IMUIMessageCellProtocal,Me
207207

208208
func tapBubbleView() {
209209
if self.message?.type == .text {
210-
self.delegate?.messageCollectionView?(tapCellView: self)
210+
self.delegate?.messageCollectionView?(tapCellView: "")
211211
}else{
212212
self.delegate?.messageCollectionView?(didTapMessageBubbleInCell: self, model: self.message!)
213213
}
214214
}
215215

216216
func tapCellView(){//点击整个cell,隐藏键盘
217-
self.delegate?.messageCollectionView?(tapCellView: self)
217+
self.delegate?.messageCollectionView?(tapCellView: "")
218218
}
219219

220220
func longTapBubbleView(sender : UILongPressGestureRecognizer) {

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUIMessageCollectionView.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ open class IMUIMessageCollectionView: UIView {
1414
@IBOutlet var view: UIView!
1515
@IBOutlet open weak var messageCollectionView: UICollectionView!
1616
var isPull = false
17+
var isAutoScroll = true //自动刷新
18+
var isInsert = false //是不是插入数据
19+
var cellGesture = UITapGestureRecognizer.init() //点击collectionView隐藏
1720
var viewCache = IMUIReuseViewCache()
1821
var headView = IMUIBaseMessageHeadCell()
1922

@@ -85,10 +88,15 @@ open class IMUIMessageCollectionView: UIView {
8588
self.messageCollectionView.register(IMUIBaseMessageHeadCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headView")
8689

8790
self.messageCollectionView.isScrollEnabled = true
88-
8991
NotificationCenter.default.addObserver(self, selector: #selector(clickStopPlayActivity(notification:)), name: NSNotification.Name(rawValue: "StopPlayActivity"), object: nil)
92+
self.cellGesture.addTarget(self, action: #selector(self.tapCollectionView))
93+
self.messageCollectionView.addGestureRecognizer(self.cellGesture)
9094
}
9195

96+
func tapCollectionView(){//点击整个cell,隐藏键盘
97+
self.delegate?.messageCollectionView?(tapCellView: "")
98+
}
99+
92100
open subscript(index: Int) -> IMUIMessageModelProtocol {
93101
return chatDataManager[index]
94102
}
@@ -139,6 +147,7 @@ open class IMUIMessageCollectionView: UIView {
139147

140148
open func insertMessage(with message: IMUIMessageModel) {
141149
self.chatDataManager.insertMessage(with: message)
150+
isInsert = true
142151
self.messageCollectionView.reloadData()
143152
}
144153

@@ -150,6 +159,7 @@ open class IMUIMessageCollectionView: UIView {
150159
// if scrollIndex>1 {
151160
// scrollIndex = scrollIndex
152161
// }
162+
isInsert = true
153163
self.scrollTo(index: scrollIndex)
154164

155165
}
@@ -297,6 +307,18 @@ extension IMUIMessageCollectionView: UIScrollViewDelegate {
297307
self.headView.stopActView()
298308
})
299309
}
310+
let tmpH = scrollView.contentSize.height - scrollView.contentOffset.y
311+
if ((tmpH > 800) && isAutoScroll){
312+
isAutoScroll = false
313+
self.delegate?.messageCollectionView?(changeAutoScroll:isAutoScroll)
314+
}else if ((tmpH < 800) && !isAutoScroll ){
315+
if isInsert {
316+
isInsert = false
317+
}else{
318+
isAutoScroll = true
319+
self.delegate?.messageCollectionView?(changeAutoScroll:isAutoScroll)
320+
}
321+
}
300322
}
301323

302324
}

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUITextMessageCell.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ open class IMUITextMessageCell: IMUIBaseMessageCell {
1414
open static var inComingTextColor = UIColor.white
1515
open static let screenW = UIScreen.main.bounds.size.width
1616

17-
open static var outGoingTextFont = UIFont.systemFont(ofSize: (screenW * 16 / 375))
18-
open static var inComingTextFont = UIFont.systemFont(ofSize: (screenW * 16 / 375))
17+
open static var outGoingTextFont = UIFont.systemFont(ofSize: (screenW * 14 / 375))
18+
open static var inComingTextFont = UIFont.systemFont(ofSize: (screenW * 14 / 375))
1919

2020
// var textMessageLable = IMUITextView()
2121
var textMessageLable = M80AttributedLabel()
@@ -30,7 +30,7 @@ open class IMUITextMessageCell: IMUIBaseMessageCell {
3030
textMessageLable.backgroundColor = UIColor.clear
3131
textMessageLable.underLineForLink = true
3232
textMessageLable.autoDetectLinks = true
33-
textMessageLable.font = UIFont.systemFont(ofSize: (IMUITextMessageCell.screenW * 16 / 375))
33+
textMessageLable.font = IMUITextMessageCell.inComingTextFont
3434
NotificationCenter.default.addObserver(self, selector: #selector(clickOpenLink(notification:)), name: NSNotification.Name(rawValue: "OpenUrlNotification"), object: nil)
3535

3636
}
@@ -55,8 +55,8 @@ open class IMUITextMessageCell: IMUIBaseMessageCell {
5555
tmpContentInset.right = message.isOutGoing ? 10 : 5
5656
self.textMessageLable.textAlignment = CTTextAlignment.left
5757
}else{
58-
tmpContentInset.left = message.isOutGoing ? 0 : 10
59-
tmpContentInset.right = message.isOutGoing ? 10 : 5
58+
tmpContentInset.left = message.isOutGoing ? 0 : 5
59+
tmpContentInset.right = message.isOutGoing ? 5 : 0
6060
self.textMessageLable.textAlignment = CTTextAlignment.center
6161
}
6262
tmpContentInset.top = 8

ios/RCTAuroraIMUI/MyMessageModel.swift

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,7 @@ open class RCTMessageModel: IMUIMessageModel {
4343
static let kUserKeyUerId = "_id"
4444
static let kUserKeyDisplayName = "name"
4545
static let kUserAvatarPath = "avatar"
46-
static let kMsgKeyNotiObj = "notiObj"
47-
static let kMsgKeyImgObj = "imgObj"
48-
static let kMsgKeyVoiceObj = "voiceObj"
49-
static let kMsgKeyLocationObj = "locationObj"
50-
static let kMsgKeyRedPacketObj = "redPacketObj"
51-
static let kMsgKeyBankTransferObj = "bankTransferObj"
52-
static let kMsgKeyUrlObj = "urlObj"
53-
static let kMsgKeyAccountNoticeObj = "accountNoticeObj"
54-
static let kMsgKeyRedpacketOpenObj = "redpacketOpenObj"
46+
static let kMsgKeyExtend = "extend"
5547

5648
static let ktimeString = "timeString"
5749
static let kisShowTime = "isShowTime"
@@ -172,12 +164,12 @@ open class RCTMessageModel: IMUIMessageModel {
172164
let isOutgoing = messageDic.object(forKey: RCTMessageModel.kMsgKeyisOutgoing) as? Bool
173165
let timeString = messageDic.object(forKey: RCTMessageModel.ktimeString) as? String
174166
let timeStamp = messageDic.object(forKey: RCTMessageModel.ktimeString) as? String
175-
// let isShowTime = messageDic.object(forKey: RCTMessageModel.kisShowTime) as? Bool
176-
let isShowTime = true
167+
let isShowTime = messageDic.object(forKey: RCTMessageModel.kisShowTime) as? Bool
168+
// let isShowTime = true
177169
let needShowTime = isShowTime
178170
var strTime = ""
179171
var customDict: NSMutableDictionary = NSMutableDictionary()
180-
if isShowTime{
172+
if needShowTime!{
181173
if let timeString = timeString {
182174
if timeString != "" {
183175
strTime = RCTMessageModel.timeStampToString(timeStamp:timeString)
@@ -210,43 +202,43 @@ open class RCTMessageModel: IMUIMessageModel {
210202
if typeString == RCTMessageModel.kMsgTypeText {
211203
msgType = .text
212204
textLayout = MyMessageCellLayout(isOutGoingMessage: isOutgoing!,
213-
isNeedShowTime: needShowTime,
205+
isNeedShowTime: needShowTime!,
214206
bubbleContentSize: RCTMessageModel.calculateTextContentSize(text: text!, isOutGoing: isOutgoing!), bubbleContentInsets: UIEdgeInsets.zero, showAvatar:true)
215207
}
216208

217209
if typeString == RCTMessageModel.kMsgTypeImage {
218210
msgType = .image
219-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyImgObj) as! NSMutableDictionary
211+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
220212
}
221213

222214
if typeString == RCTMessageModel.kMsgTypeVoice {
223215

224216
msgType = .voice
225-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyVoiceObj) as! NSMutableDictionary
217+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
226218
}
227219

228220
if typeString == RCTMessageModel.kMsgTypeVideo {
229221
msgType = .video
230222
}
231223
if typeString == RCTMessageModel.kMsgTypeLocation {
232224
msgType = .location
233-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyLocationObj) as! NSMutableDictionary
225+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
234226
}
235227
if typeString == RCTMessageModel.kMsgTypeNotification {
236228
msgType = .notification
237-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyNotiObj) as! NSMutableDictionary
229+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
238230
}
239231
if typeString == RCTMessageModel.kMsgTypeRedpacket {
240232
msgType = .redpacket
241-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyRedPacketObj) as! NSMutableDictionary
233+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
242234
}
243235
if typeString == RCTMessageModel.kMsgTypeTransfer {
244236
msgType = .transfer
245-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyBankTransferObj) as! NSMutableDictionary
237+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
246238
}
247239
if typeString == RCTMessageModel.kMsgTypeRedpacketOpen {
248240
msgType = .redpacketOpen
249-
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyRedpacketOpenObj) as! NSMutableDictionary
241+
customDict = messageDic.object(forKey: RCTMessageModel.kMsgKeyExtend) as! NSMutableDictionary
250242
}
251243
}
252244

@@ -332,13 +324,13 @@ open class RCTMessageModel: IMUIMessageModel {
332324
case .image:
333325
messageDic.setValue(RCTMessageModel.kMsgTypeImage, forKey: RCTMessageModel.kMsgKeyMsgType)
334326
messageDic.setValue(self.mediaPath, forKey: RCTMessageModel.kMsgKeyMediaFilePath)
335-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyImgObj)
327+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
336328
break
337329
case .voice:
338330
messageDic.setValue(RCTMessageModel.kMsgTypeVoice, forKey: RCTMessageModel.kMsgKeyMsgType)
339331
messageDic.setValue(self.mediaPath, forKey: RCTMessageModel.kMsgKeyMediaFilePath)
340332
messageDic.setValue(self.duration, forKey: RCTMessageModel.kMsgKeyDuration)
341-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyVoiceObj)
333+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
342334
break
343335
case .video:
344336
messageDic.setValue(RCTMessageModel.kMsgTypeVideo, forKey: RCTMessageModel.kMsgKeyMsgType)
@@ -347,31 +339,31 @@ open class RCTMessageModel: IMUIMessageModel {
347339
break
348340
case .location:
349341
messageDic.setValue(RCTMessageModel.kMsgTypeLocation, forKey: RCTMessageModel.kMsgKeyMsgType)
350-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyLocationObj)
342+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
351343
break
352344
case .notification:
353345
messageDic.setValue(RCTMessageModel.kMsgTypeNotification, forKey: RCTMessageModel.kMsgKeyMsgType)
354-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyNotiObj)
346+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
355347
break
356348
case .redpacket:
357349
messageDic.setValue(RCTMessageModel.kMsgTypeRedpacket, forKey: RCTMessageModel.kMsgKeyMsgType)
358-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyRedPacketObj)
350+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
359351
break
360352
case .transfer:
361353
messageDic.setValue(RCTMessageModel.kMsgTypeTransfer, forKey: RCTMessageModel.kMsgKeyMsgType)
362-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyBankTransferObj)
354+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
363355
break
364356
case .url:
365357
messageDic.setValue(RCTMessageModel.kMsgTypeUrl, forKey: RCTMessageModel.kMsgKeyMsgType)
366-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyUrlObj)
358+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
367359
break
368360
case .account_notice:
369361
messageDic.setValue(RCTMessageModel.kMsgTypeAccountNotifce, forKey: RCTMessageModel.kMsgKeyMsgType)
370-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyAccountNoticeObj)
362+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
371363
break
372364
case .redpacketOpen:
373365
messageDic.setValue(RCTMessageModel.kMsgTypeRedpacketOpen, forKey: RCTMessageModel.kMsgKeyMsgType)
374-
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyRedpacketOpenObj)
366+
messageDic.setValue(self.customDict, forKey: RCTMessageModel.kMsgKeyExtend)
375367
break
376368
case .custom:
377369
break

ios/RCTAuroraIMUI/RCTMessageListView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
@property(nonatomic, copy) RCTBubblingEventBlock onBeginDragMessageList;
3131
@property (nonatomic, copy) RCTBubblingEventBlock onClickLoadMessages;
32+
@property (nonatomic, copy) RCTBubblingEventBlock onClickChangeAutoScroll;
3233

3334
// custom layout
3435
@property(strong, nonatomic) NSDictionary *sendBubble;

ios/RCTAuroraIMUI/RCTMessageListView.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
5555
- (id)initWithCoder:(NSCoder *)aDecoder {
5656
self = [super initWithCoder:aDecoder];
5757
if (self) {
58+
self.frame = CGRectMake(0, 0, screenW, screenH-60-50);//60为导航栏高度,50为输入栏默认高度
5859
[[NSNotificationCenter defaultCenter] addObserver:self
5960
selector:@selector(appendMessages:)
6061
name:kAppendMessages object:nil];

ios/RCTAuroraIMUI/RCTMessageListViewManager.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ @interface RCTMessageListViewManager : RCTViewManager <IMUIMessageMessageCollect
1919
/// Tells the delegate that user tap message cell
2020
- (void)messageCollectionView:(UICollectionView * _Nonnull)_ forItemAt:(NSIndexPath * _Nonnull)forItemAt model:(id <IMUIMessageModelProtocol> _Nonnull)model;
2121
/// Tells the delegate that user tap message bubble
22-
- (void)messageCollectionViewWithTapCellView:(UICollectionViewCell * _Nonnull)tapCellView;
22+
- (void)messageCollectionViewWithTapCellView:(NSString * )tapCellView;
2323
- (void)messageCollectionViewWithDidTapMessageBubbleInCell:(UICollectionViewCell * _Nonnull)didTapMessageBubbleInCell;
2424

2525
- (void)messageCollectionViewWithOpenMessageBubbleUrl:(NSString *)url;
2626

2727

2828
- (void)messageCollectionViewWithDidShowMenuStr:(NSString *)strMenu model:(id <IMUIMessageModelProtocol> _Nonnull)model;
2929
- (void)messageCollectionViewWithReloadMoreData:(NSString *)data;
30+
- (void)messageCollectionViewWithChangeAutoScroll:(BOOL *)isAutoScroll;
31+
3032

3133
/// Tells the delegate that user tap header image in message cell
3234
- (void)messageCollectionViewWithDidTapHeaderImageInCell:(UICollectionViewCell * _Nonnull)didTapHeaderImageInCell model:(id <IMUIMessageModelProtocol> _Nonnull)model;
@@ -52,6 +54,7 @@ @implementation RCTMessageListViewManager
5254

5355
RCT_EXPORT_VIEW_PROPERTY(onBeginDragMessageList, RCTBubblingEventBlock)
5456
RCT_EXPORT_VIEW_PROPERTY(onClickLoadMessages, RCTBubblingEventBlock)
57+
RCT_EXPORT_VIEW_PROPERTY(onClickChangeAutoScroll, RCTBubblingEventBlock)
5558

5659

5760
RCT_EXPORT_MODULE()
@@ -222,7 +225,7 @@ - (void)messageCollectionViewWithDidTapMessageBubbleInCell:(UICollectionViewCell
222225
_messageList.onMsgClick((@{@"message": messageDic}));
223226
}
224227

225-
- (void)messageCollectionViewWithTapCellView:(UICollectionViewCell *)tapCellView{//隐藏键盘
228+
- (void)messageCollectionViewWithTapCellView:(NSString *)tapCellView{//隐藏键盘
226229
if(!_messageList.onBeginDragMessageList) { return; }
227230
_messageList.onBeginDragMessageList(@{});
228231
}
@@ -277,14 +280,18 @@ - (void)messageCollectionView:(UICollectionView * _Nonnull)willBeginDragging {
277280
_messageList.onBeginDragMessageList(@{});
278281
}
279282

280-
- (void)messageCollectionViewWithReloadMoreData:(NSString *)data{
281-
NSLog(@"刷新数据");
283+
- (void)messageCollectionViewWithReloadMoreData:(NSString *)data{//刷新数据
282284
if(!_messageList.onClickLoadMessages) { return; }
283285

284286
_messageList.onClickLoadMessages(@{});
285287

286288
}
287289

290+
- (void)messageCollectionViewWithChangeAutoScroll:(BOOL *)isAutoScroll{//改变自动滚动状态
291+
if(!_messageList.onClickChangeAutoScroll) { return; }
292+
_messageList.onClickChangeAutoScroll(@{ @"isAutoScroll": [NSNumber numberWithBool:isAutoScroll]});
293+
}
294+
288295

289296
//- (void)onPullToRefreshMessageList {
290297
//

0 commit comments

Comments
 (0)