From e8ea04496d314f0f81cafb0b0e6c3ac810f1f643 Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Tue, 3 Oct 2017 03:36:28 -0500 Subject: [PATCH] [Added] additionalTopContentInset property --- CHANGELOG.md | 3 +++ Sources/MessagesViewController.swift | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d3d2b4e..3cfa2b14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa - `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). +- `additionalTopContentInset` property to `MessagesColectionViewController` to allow users to account for extra subviews. +[#218](https://github.com/MessageKit/MessageKit/pull/218) by [@SD10](https://github.com/SD10). + ### Fixed - `MessageInputBar` now correctly sizes itself when breaking its max height or pasting in large amounts of text diff --git a/Sources/MessagesViewController.swift b/Sources/MessagesViewController.swift index 2f76533c..f612baa6 100644 --- a/Sources/MessagesViewController.swift +++ b/Sources/MessagesViewController.swift @@ -34,6 +34,13 @@ open class MessagesViewController: UIViewController { open var scrollsToBottomOnFirstLayout: Bool = false + open var additionalTopContentInset: CGFloat = 0 { + didSet { + let inset = topLayoutGuide.length + additionalTopContentInset + messagesCollectionView.contentInset.top = inset + } + } + private var isFirstLayout: Bool = true open override var canBecomeFirstResponder: Bool { @@ -69,6 +76,7 @@ open class MessagesViewController: UIViewController { // Hack to prevent animation of the contentInset after viewDidAppear if isFirstLayout { addKeyboardObservers() + messagesCollectionView.contentInset.top = additionalTopContentInset + topLayoutGuide.length messagesCollectionView.contentInset.bottom = messageInputBar.frame.height messagesCollectionView.scrollIndicatorInsets.bottom = messageInputBar.frame.height isFirstLayout = false