From 600da97e13e7eed343869f57644bc2e8667c8a26 Mon Sep 17 00:00:00 2001 From: Igor Kashkuta Date: Mon, 4 Jul 2016 16:18:21 +0100 Subject: [PATCH] Revert "Preserve height of ChatInputItem if keyboard item was previously opened. (#170)" (#172) This reverts commit b2fcf7b7fc3386d9926e13cc99a6309d4e36817b. --- .../Source/Input/ChatInputBarPresenter.swift | 50 +------------------ 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift b/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift index adcd434..dee4133 100644 --- a/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift +++ b/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift @@ -35,28 +35,15 @@ protocol ChatInputBarPresenter: class { @objc public class BasicChatInputBarPresenter: NSObject, ChatInputBarPresenter { let chatInputBar: ChatInputBar let chatInputItems: [ChatInputItemProtocol] - let notificationCenter: NSNotificationCenter - public init(chatInputBar: ChatInputBar, - chatInputItems: [ChatInputItemProtocol], - chatInputBarAppearance: ChatInputBarAppearance, - notificationCenter: NSNotificationCenter = NSNotificationCenter.defaultCenter()) { + public init(chatInputBar: ChatInputBar, chatInputItems: [ChatInputItemProtocol], chatInputBarAppearance: ChatInputBarAppearance) { self.chatInputBar = chatInputBar self.chatInputItems = chatInputItems self.chatInputBar.setAppearance(chatInputBarAppearance) - self.notificationCenter = notificationCenter super.init() self.chatInputBar.presenter = self self.chatInputBar.inputItems = self.chatInputItems - self.notificationCenter.addObserver(self, - selector: #selector(BasicChatInputBarPresenter.keyboardDidChangeFrame), - name: UIKeyboardDidChangeFrameNotification, - object: nil) - } - - deinit { - self.notificationCenter.removeObserver(self) } private(set) var focusedItem: ChatInputItemProtocol? { @@ -70,9 +57,7 @@ protocol ChatInputBarPresenter: class { private func updateFirstResponderWithInputItem(inputItem: ChatInputItemProtocol) { let responder = self.chatInputBar.textView - let inputView = inputItem.inputView - self.setHeight(forInputView: inputView) - responder.inputView = inputView + responder.inputView = inputItem.inputView if responder.isFirstResponder() { responder.reloadInputViews() } else { @@ -90,37 +75,6 @@ protocol ChatInputBarPresenter: class { } return firstKeyboardInputItem } - - private func setHeight(forInputView inputView: UIView?) { - guard let inputView = inputView else { return } - - var mask = inputView.autoresizingMask - mask.remove(.FlexibleHeight) - inputView.autoresizingMask = mask - - if let heightConstraint = inputView.constraints.filter({ $0.firstAttribute == .Height }).first { - heightConstraint.constant = self.inputViewHeight - } else { - inputView.frame.size.height = self.inputViewHeight - } - } - - private var lastKnownKeyboardHeight: CGFloat? - private let defaultKeyboardHeight: CGFloat = 216 - private var inputViewHeight: CGFloat { - let accessoryViewHeight = self.chatInputBar.textView.inputAccessoryView?.bounds.height ?? 0 - if let lastKnownKeyboardHeight = self.lastKnownKeyboardHeight { - return lastKnownKeyboardHeight - accessoryViewHeight - } else { - return self.defaultKeyboardHeight - } - } - - @objc - private func keyboardDidChangeFrame(notification: NSNotification) { - guard let value = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return } - self.lastKnownKeyboardHeight = value.CGRectValue().height - } } // MARK: ChatInputBarPresenter