Skip to content

Commit

Permalink
Merge pull request #445 from jpush/dev
Browse files Browse the repository at this point in the history
iOS fix: messageList scrollToBottom
  • Loading branch information
huangminlinux authored Sep 7, 2018
2 parents dc24f75 + 7043687 commit a18f066
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions iOS/IMUIInputView/Controllers/IMUIInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ extension IMUIInputView: IMUICustomInputViewDelegate {

public func keyBoardWillShow(height: CGFloat, durationTime: Double) {
self.currentType = .empty
self.delegate?.keyBoardWillShow?(height: height, durationTime: durationTime)
self.reloadFeaturnView()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ open class IMUIMessageCollectionView: UIView {
@objc open func scrollToBottom(with animated: Bool) {
if chatDataManager.count == 0 { return }
let endIndex = IndexPath(item: chatDataManager.endIndex - 1, section: 0)
self.messageCollectionView.scrollToItem(at: endIndex, at: .bottom, animated: animated)
DispatchQueue.main.async {
self.messageCollectionView.scrollToItem(at: endIndex, at: .bottom, animated: animated)
}

}

@objc open func appendMessage(with message: IMUIMessageProtocol) {
Expand Down
6 changes: 6 additions & 0 deletions iOS/sample/sample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.myInputView.delegate = self
// self.myInputView.inputViewDelegate = self
self.messageCollectionView.delegate = self

self.messageCollectionView.messageCollectionView.register(MessageEventCollectionViewCell.self, forCellWithReuseIdentifier: MessageEventCollectionViewCell.self.description())
Expand All @@ -61,6 +62,10 @@ class ViewController: UIViewController {
// MARK: - IMUIInputViewDelegate
extension ViewController: IMUIInputViewDelegate {

func keyBoardWillShow(height: CGFloat, durationTime: Double) {
self.messageCollectionView.scrollToBottom(with: true)
}

func sendTextMessage(_ messageText: String) {
let outGoingmessage = MyMessageModel(text: messageText, isOutGoing: true)
let inCommingMessage = MyMessageModel(text: messageText, isOutGoing: false)
Expand Down Expand Up @@ -215,3 +220,4 @@ extension ViewController: IMUIMessageMessageCollectionViewDelegate {
toast.dismiss(withClickedButtonIndex: 0, animated: true)
}
}

3 changes: 2 additions & 1 deletion iOS/sampleObjectC/sampleObjectC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ - (void)viewDidLoad {
[super viewDidLoad];
self.messageList.delegate = self;
self.imuiInputView.delegate = self;
self.imuiInputView.inputViewDelegate = self;

[self.messageList.messageCollectionView registerClass:[MessageEventCollectionViewCell class] forCellWithReuseIdentifier:[[MessageEventCollectionViewCell class] description]];

Expand Down Expand Up @@ -191,7 +192,7 @@ - (void)finishRecordVideoWithVideoPath:(NSString * _Nonnull)videoPath durationTi
}

- (void)keyBoardWillShowWithHeight:(CGFloat)height durationTime:(double)durationTime {

[_messageList scrollToBottomWith: YES];
}

- (NSString *)getPath {//"\(NSHomeDirectory())/Documents/"
Expand Down

0 comments on commit a18f066

Please sign in to comment.