Skip to content
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
2 changes: 2 additions & 0 deletions Example/ChatExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -521,6 +522,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
3 changes: 1 addition & 2 deletions Example/Sources/ConversationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class ConversationViewController: MessagesViewController {
messagesCollectionView.messageCellDelegate = self
messagesCollectionView.messageLabelDelegate = self
messageInputBar.delegate = self

setupInputBar()
//setupInputBar()
}

func setupInputBar() {
Expand Down
1 change: 0 additions & 1 deletion Sources/Bundle+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ extension Bundle {
return Bundle(url: resourceUrl)!
}


}
4 changes: 3 additions & 1 deletion Sources/InputBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ open class InputBarButtonItem: UIButton {
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
super.init(coder: aDecoder)
setup()
}

open func setup() {

contentVerticalAlignment = .center
contentHorizontalAlignment = .center
imageView?.contentMode = .scaleAspectFit
Expand Down
9 changes: 8 additions & 1 deletion Sources/InputTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ open class InputTextView: UITextView {
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()

open override var text: String! {
didSet {
placeholderLabel.isHidden = !text.isEmpty
}
}

private var placeholderLabelConstraintSet: NSLayoutConstraintSet?

Expand Down Expand Up @@ -84,7 +90,8 @@ open class InputTextView: UITextView {
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
super.init(coder: aDecoder)
setup()

@SD10 SD10 Sep 3, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathantannar4 Is this part of the workaround? There was a problem with unarchiving?

}

open func setup() {
Expand Down
11 changes: 9 additions & 2 deletions Sources/MessageInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ open class MessageInputBar: UIView {
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
super.init(coder: aDecoder)
setup()
}

deinit {
Expand All @@ -218,7 +219,7 @@ open class MessageInputBar: UIView {
open func setup() {

backgroundColor = .inputBarGray
autoresizingMask = [.flexibleHeight, .flexibleBottomMargin]
autoresizingMask = [.flexibleHeight]
setupSubviews()
setupConstraints()
setupObservers()
Expand Down Expand Up @@ -448,5 +449,11 @@ open class MessageInputBar: UIView {
delegate?.messageInputBar(self, didPressSendButtonWith: inputTextView.text)
textViewDidChange()
}
}

extension MessageInputBar {

func createCopy() -> MessageInputBar? {
return NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: self)) as? MessageInputBar
}
}
34 changes: 26 additions & 8 deletions Sources/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ open class MessagesViewController: UIViewController {

open var messagesCollectionView = MessagesCollectionView(frame: .zero, collectionViewLayout: MessagesCollectionViewFlowLayout())

open var messageInputBar = MessageInputBar()
open var messageInputBar = MessageInputBar()

private var messageInputBarCopy: MessageInputBar?

override open var canBecomeFirstResponder: Bool {
return true
}

override open var inputAccessoryView: UIView? {
return messageInputBar
return messageInputBar
}

open override var shouldAutorotate: Bool {
Expand All @@ -61,20 +63,22 @@ open class MessagesViewController: UIViewController {
registerReusableFooters()

setupDelegates()

// https://stackoverflow.com/questions/31049651/uitextview-as-inputaccessoryview-doesnt-render-text-until-after-animation
// Calling this on the root view avoids a side effect where the inputAccessoryView dissapears after tap
//view.snapshotView(afterScreenUpdates: true)

}

override open func viewDidLayoutSubviews() {
messagesCollectionView.contentInset = UIEdgeInsets(top: topLayoutGuide.length, left: 0, bottom: messageInputBar.frame.height, right: 0)
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupMessageInputBarCopy()
}

open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
addKeyboardObservers()
removeMessageInputBarCopy()
}

override open func viewDidLayoutSubviews() {
messagesCollectionView.contentInset = UIEdgeInsets(top: topLayoutGuide.length, left: 0, bottom: messageInputBar.frame.height, right: 0)
}

// MARK: - Initializers
Expand Down Expand Up @@ -127,6 +131,20 @@ open class MessagesViewController: UIViewController {
toItem: bottomLayoutGuide, attribute: .top, multiplier: 1, constant: 0))
}

// MARK: - MessageInputBar
// Fixes bug where MessageInputBar text renders after viewDidAppear

private func setupMessageInputBarCopy() {
messageInputBarCopy = messageInputBar.createCopy()
guard let copy = messageInputBarCopy else { return }
view.addSubview(copy)
copy.addConstraints(nil, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 0)

@SD10 SD10 Sep 3, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind splitting this up onto multiple lines?

}

private func removeMessageInputBarCopy() {
messageInputBarCopy?.removeFromSuperview()
messageInputBarCopy = nil
}
}

// MARK: - UICollectionViewDelegate & UICollectionViewDelegateFlowLayout Conformance
Expand Down