Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing storyboard layout & custom main view class for BaseChatViewController #323

Merged
merged 7 commits into from
Jul 26, 2017
17 changes: 14 additions & 3 deletions Chatto/Source/ChatController/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,
}
}

// If set to false user is responsible to make sure that view provided in loadView() implements BaseChatViewContollerViewProtocol.
// Must be set before loadView is called.
public var substitutesMainViewAutomatically = true

// Custom update on setting the data source. if triggeringUpdateType is nil it won't enqueue any update (you should do it later manually)
public final func setChatDataSource(_ dataSource: ChatDataSourceProtocol?, triggeringUpdateType updateType: UpdateType?) {
self._chatDataSource = dataSource
Expand All @@ -73,8 +77,13 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,
}

open override func loadView() {
self.view = BaseChatViewControllerView() // http://stackoverflow.com/questions/24596031/uiviewcontroller-with-inputaccessoryview-is-not-deallocated
self.view.backgroundColor = UIColor.white
if substitutesMainViewAutomatically {
self.view = BaseChatViewControllerView() // http://stackoverflow.com/questions/24596031/uiviewcontroller-with-inputaccessoryview-is-not-deallocated
self.view.backgroundColor = UIColor.white
} else {
super.loadView()
}

}

override open func viewDidLoad() {
Expand Down Expand Up @@ -184,7 +193,9 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,
sSelf.isAdjustingInputContainer = false
}
self.keyboardTracker = KeyboardTracker(viewController: self, inputContainer: self.inputContainer, layoutBlock: layoutBlock, notificationCenter: self.notificationCenter)
(self.view as? BaseChatViewControllerView)?.bmaInputAccessoryView = self.keyboardTracker?.trackingView

(self.view as? BaseChatViewControllerViewProtocol)?.bmaInputAccessoryView = self.keyboardTracker?.trackingView

}

var notificationCenter = NotificationCenter.default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@

import Foundation

// If you wish to use your custom view instead of BaseChatViewControllerView, you must implement this protocol.
public protocol BaseChatViewControllerViewProtocol: class {
var bmaInputAccessoryView: UIView? { get set }
}

// http://stackoverflow.com/questions/24596031/uiviewcontroller-with-inputaccessoryview-is-not-deallocated
final class BaseChatViewControllerView: UIView {
final class BaseChatViewControllerView: UIView, BaseChatViewControllerViewProtocol {

var bmaInputAccessoryView: UIView?

Expand Down