Skip to content

Instantly share code, notes, and snippets.

@bartkozal
Created September 16, 2016 20:45
Show Gist options
  • Save bartkozal/880d535b35c6399f22d49d95b81065ee to your computer and use it in GitHub Desktop.
Save bartkozal/880d535b35c6399f22d49d95b81065ee to your computer and use it in GitHub Desktop.
class CompactViewController: UIViewController {
// ...
}
class ExpandedViewController: UIViewController {
// ...
}
class MessagesViewController: MSMessagesAppViewController {
override func willBecomeActive(with conversation: MSConversation) {
super.willBecomeActive(with: conversation)
presentVC(for: conversation, with: presentationStyle)
}
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
guard let conversation = activeConversation else {
fatalError("Expected the active conversation")
}
presentVC(for: conversation, with: presentationStyle)
}
private func presentVC(for conversation: MSConversation, with presentationStyle: MSMessagesAppPresentationStyle) {
let controller: UIViewController
if presentationStyle == .compact {
controller = instantiateCompactVC()
} else {
controller = instantiateExpandedVC()
}
addChildViewController(controller)
// ...constraints and view setup...
view.addSubview(controller.view)
controller.didMove(toParentViewController: self)
}
private func instantiateCompactVC() -> UIViewController {
guard let compactVC = storyboard?.instantiateViewController(withIdentifier: "CompactVC") as? CompactViewController else {
fatalError("Can't instantiate CompactViewController")
}
return compactVC
}
private func instantiateExpandedVC() -> UIViewController {
guard let expandedVC = storyboard?.instantiateViewController(withIdentifier: "ExpandedVC") as? ExpandedViewController else {
fatalError("Can't instantiate ExpandedViewController")
}
return expandedVC
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment