From ea00a643ca7c5cabda2b8451b3777e59c2fb10c5 Mon Sep 17 00:00:00 2001 From: Francesco Deliro Date: Tue, 3 Oct 2017 01:47:48 +0200 Subject: [PATCH] - added open var scrollsToBottomOnFirstLayout (#213) Added open var scrollsToBottomOnFirstLayout --- CHANGELOG.md | 9 +++++++-- Example/Sources/ConversationViewController.swift | 1 + Sources/MessagesViewController.swift | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0129c603..6d3d2b4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa -------------------------------------- ## Upcoming release + ### Added + - **Breaking Change** `.custom((MessageContainerView)->Void)` case to `MessageStyle` enum. [#163](https://github.com/MessageKit/MessageKit/pull/163) by [@SD10](https://github.com/SD10). @@ -21,6 +23,9 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa - `animationBlockForLocation(message:indexPath:messagesCollectionView)` method to `LocationMessageDisplayDelegate` to customize the display animation of the location message's map. [#210](https://github.com/MessageKit/MessageKit/pull/210) by [@etoledom](https://github.com/etoledom). +- `scrollsToBottomOnFirstLayout` property to automatically scroll to the bottom of `MessagesCollectionView` on first load. +[#213](https://github.com/MessageKit/MessageKit/pull/213) by [@FraDeliro](https://github.com/FraDeliro). + ### Fixed - `MessageInputBar` now correctly sizes itself when breaking its max height or pasting in large amounts of text @@ -36,6 +41,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa [#174](https://github.com/MessageKit/MessageKit/pull/174) by [@etoledom](https://github.com/etoledom). ### Changed + - **Breaking Change** `snapshotOptionsForLocation` method is now part of `LocationMessageDisplayDelegate`. [#150](https://github.com/MessageKit/MessageKit/pull/150) by [@etoledom](https://github.com/etoledom). @@ -62,11 +68,10 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa [#177](https://github.com/MessageKit/MessageKit/pull/177) by [@cwalo](https://github.com/cwalo). ### Removed + - **Breaking Change** `cellTopLabelInsets` and `cellBottomLabelInsets` from `MessagesCollectionViewFlowLayout`. [#166](https://github.com/MessageKit/MessageKit/pull/166) by [@SD10](https://github.com/SD10). ----------------- - ## [[Prerelease] 0.8.2](https://github.com/MessageKit/MessageKit/releases/tag/0.8.2) ### Added - Support for Swift 4 diff --git a/Example/Sources/ConversationViewController.swift b/Example/Sources/ConversationViewController.swift index 71b1bf56..6fdf2d0c 100644 --- a/Example/Sources/ConversationViewController.swift +++ b/Example/Sources/ConversationViewController.swift @@ -39,6 +39,7 @@ class ConversationViewController: MessagesViewController { messagesCollectionView.messagesDisplayDelegate = self messagesCollectionView.messageCellDelegate = self messageInputBar.delegate = self + scrollsToBottomOnFirstLayout = true //default false navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "ic_keyboard"), style: .plain, diff --git a/Sources/MessagesViewController.swift b/Sources/MessagesViewController.swift index 42019be6..2f76533c 100644 --- a/Sources/MessagesViewController.swift +++ b/Sources/MessagesViewController.swift @@ -31,6 +31,8 @@ open class MessagesViewController: UIViewController { open var messagesCollectionView = MessagesCollectionView(frame: .zero, collectionViewLayout: MessagesCollectionViewFlowLayout()) open var messageInputBar = MessageInputBar() + + open var scrollsToBottomOnFirstLayout: Bool = false private var isFirstLayout: Bool = true @@ -70,6 +72,11 @@ open class MessagesViewController: UIViewController { messagesCollectionView.contentInset.bottom = messageInputBar.frame.height messagesCollectionView.scrollIndicatorInsets.bottom = messageInputBar.frame.height isFirstLayout = false + + //Scroll to bottom at first load + if scrollsToBottomOnFirstLayout { + messagesCollectionView.scrollToBottom(animated: false) + } } }