Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS fix: messageList scrollToBottom #445

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
iOS fix: messageList scrollToBottom
  • Loading branch information
huangminlinux committed Sep 7, 2018
commit 7043687f414a9b8f27b507caeeb4c0f23003dda2
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