From d287203c245619ddb4064d01ec878d0d4fabb37a Mon Sep 17 00:00:00 2001 From: Katerina Petrova <91kathrin@gmail.com> Date: Mon, 24 Jul 2017 13:00:40 +0300 Subject: [PATCH 1/2] Fix inputContainer position when presenting BaseChatViewController as childViewController --- .../Source/ChatController/BaseChatViewController.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Chatto/Source/ChatController/BaseChatViewController.swift b/Chatto/Source/ChatController/BaseChatViewController.swift index e8703b283..e0b5d74ea 100644 --- a/Chatto/Source/ChatController/BaseChatViewController.swift +++ b/Chatto/Source/ChatController/BaseChatViewController.swift @@ -186,7 +186,15 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource, // If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin // because it has incorrect value when we actually have a bottom bar (tabbar) - if self.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == self { + // Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self + let navigatedCtrl: UIViewController + if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) { + navigatedCtrl = parent + } else { + navigatedCtrl = self + } + + if navigatedCtrl.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedCtrl { self.inputContainerBottomConstraint.constant = 0 } else { self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length From b1d11b6bdc6f25b1aa437a37adea8581aeea92a5 Mon Sep 17 00:00:00 2001 From: Katerina Petrova <91kathrin@gmail.com> Date: Tue, 25 Jul 2017 11:46:49 +0300 Subject: [PATCH 2/2] Move setup of inputContainerBottomConstraint to separated function --- .../BaseChatViewController.swift | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Chatto/Source/ChatController/BaseChatViewController.swift b/Chatto/Source/ChatController/BaseChatViewController.swift index e0b5d74ea..a4d74ffce 100644 --- a/Chatto/Source/ChatController/BaseChatViewController.swift +++ b/Chatto/Source/ChatController/BaseChatViewController.swift @@ -156,6 +156,23 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource, self.inputContainer.addConstraint(NSLayoutConstraint(item: self.inputContainer, attribute: .bottom, relatedBy: .equal, toItem: inputView, attribute: .bottom, multiplier: 1, constant: 0)) self.inputContainer.addConstraint(NSLayoutConstraint(item: self.inputContainer, attribute: .trailing, relatedBy: .equal, toItem: inputView, attribute: .trailing, multiplier: 1, constant: 0)) } + private func setupInputContainerBottomConstraint() { + // If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin + // because it has incorrect value when we actually have a bottom bar (tabbar) + // Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self + let navigatedController: UIViewController + if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) { + navigatedController = parent + } else { + navigatedController = self + } + + if navigatedController.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedController { + self.inputContainerBottomConstraint.constant = 0 + } else { + self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length + } + } var isAdjustingInputContainer: Bool = false open func setupKeyboardTracker() { @@ -183,22 +200,7 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource, if self.isFirstLayout { self.updateQueue.start() self.isFirstLayout = false - // If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin - // because it has incorrect value when we actually have a bottom bar (tabbar) - - // Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self - let navigatedCtrl: UIViewController - if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) { - navigatedCtrl = parent - } else { - navigatedCtrl = self - } - - if navigatedCtrl.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedCtrl { - self.inputContainerBottomConstraint.constant = 0 - } else { - self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length - } + self.setupInputContainerBottomConstraint() } }