Commit a77657d6 by Daniel Dahan

updated RootController transition method to use Motion transitions

parent 4d0b9240
...@@ -415,8 +415,8 @@ open class NavigationDrawerController: RootController { ...@@ -415,8 +415,8 @@ open class NavigationDrawerController: RootController {
prepare() prepare()
} }
open override func transition(to viewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { open override func transition(to viewController: UIViewController, completion: ((Bool) -> Void)? = nil) {
super.transition(to: viewController, duration: duration, options: options, animations: animations) { [weak self, completion = completion] (result) in super.transition(to: viewController) { [weak self, completion = completion] (result) in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -452,6 +452,8 @@ open class NavigationDrawerController: RootController { ...@@ -452,6 +452,8 @@ open class NavigationDrawerController: RootController {
vc.view.center = CGPoint(x: rightViewWidth / 2, y: v.bounds.height / 2) vc.view.center = CGPoint(x: rightViewWidth / 2, y: v.bounds.height / 2)
} }
} }
rootViewController.view.frame = container.bounds
} }
open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
...@@ -976,7 +978,7 @@ extension NavigationDrawerController { ...@@ -976,7 +978,7 @@ extension NavigationDrawerController {
/// Prepares the contentViewController. /// Prepares the contentViewController.
fileprivate func prepareContentViewController() { fileprivate func prepareContentViewController() {
contentViewController.view.backgroundColor = .black contentViewController.view.backgroundColor = .black
prepare(viewController: contentViewController, withContainer: view) prepare(viewController: contentViewController, in: view)
view.sendSubview(toBack: contentViewController.view) view.sendSubview(toBack: contentViewController.view)
} }
...@@ -986,7 +988,7 @@ extension NavigationDrawerController { ...@@ -986,7 +988,7 @@ extension NavigationDrawerController {
return return
} }
prepare(viewController: leftViewController, withContainer: v) prepare(viewController: leftViewController, in: v)
} }
/// A method that prepares the rightViewController. /// A method that prepares the rightViewController.
...@@ -995,7 +997,7 @@ extension NavigationDrawerController { ...@@ -995,7 +997,7 @@ extension NavigationDrawerController {
return return
} }
prepare(viewController: rightViewController, withContainer: v) prepare(viewController: rightViewController, in: v)
} }
/// A method that prepares the leftView. /// A method that prepares the leftView.
......
...@@ -45,6 +45,9 @@ open class RootController: UIViewController { ...@@ -45,6 +45,9 @@ open class RootController: UIViewController {
} }
} }
/// A reference to the container view.
open let container = UIView()
/** /**
A UIViewController property that references the active A UIViewController property that references the active
main UIViewController. To swap the rootViewController, it main UIViewController. To swap the rootViewController, it
...@@ -53,6 +56,9 @@ open class RootController: UIViewController { ...@@ -53,6 +56,9 @@ open class RootController: UIViewController {
*/ */
open fileprivate(set) var rootViewController: UIViewController! open fileprivate(set) var rootViewController: UIViewController!
/// The transition type used during a transition.
open var motionTransitionType = MotionTransitionType.fade
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -93,39 +99,26 @@ open class RootController: UIViewController { ...@@ -93,39 +99,26 @@ open class RootController: UIViewController {
A method to swap rootViewController objects. A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap - Parameter toViewController: The UIViewController to swap
with the active rootViewController. with the active rootViewController.
- Parameter duration: A TimeInterval that sets the
animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active rootViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active rootViewController
to the toViewController.
- Parameter completion: A completion block that is execited after - Parameter completion: A completion block that is execited after
the transition animation from the active rootViewController the transition animation from the active rootViewController
to the toViewController has completed. to the toViewController has completed.
*/ */
open func transition(to viewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { open func transition(to viewController: UIViewController, completion: ((Bool) -> Void)? = nil) {
rootViewController.willMove(toParentViewController: nil) let fvc = rootViewController!
addChildViewController(viewController) let tvc = viewController
viewController.view.frame = rootViewController.view.frame
transition(from: rootViewController, tvc.view.frame.size = view.bounds.size
to: viewController, tvc.motionModalTransitionType = motionTransitionType
duration: duration,
options: options, view.isUserInteractionEnabled = false
animations: animations) { [weak self, viewController = viewController, completion = completion] (result) in Motion.shared.transition(from: fvc, to: tvc, in: container) { [weak self, completion = completion] (isFinished) in
guard let s = self else { guard let s = self else {
return return
} }
viewController.didMove(toParentViewController: s) s.rootViewController = tvc
s.rootViewController.removeFromParentViewController() s.view.isUserInteractionEnabled = true
s.rootViewController = viewController completion?(isFinished)
s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
s.rootViewController.view.contentScaleFactor = Screen.scale
s.view.sendSubview(toBack: s.rootViewController.view)
completion?(result)
} }
} }
...@@ -147,14 +140,24 @@ open class RootController: UIViewController { ...@@ -147,14 +140,24 @@ open class RootController: UIViewController {
view.clipsToBounds = true view.clipsToBounds = true
view.backgroundColor = .white view.backgroundColor = .white
view.contentScaleFactor = Screen.scale view.contentScaleFactor = Screen.scale
prepareContainer()
prepareRootViewController() prepareRootViewController()
} }
} }
extension RootController { internal extension RootController {
/// Prepares the container view.
func prepareContainer() {
container.frame = view.bounds
container.contentScaleFactor = Screen.scale
container.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(container)
}
/// A method that prepares the rootViewController. /// A method that prepares the rootViewController.
internal func prepareRootViewController() { func prepareRootViewController() {
prepare(viewController: rootViewController, withContainer: view) prepare(viewController: rootViewController, in: container)
} }
/** /**
...@@ -162,10 +165,10 @@ extension RootController { ...@@ -162,10 +165,10 @@ extension RootController {
the BarController within the passed in the BarController within the passed in
container view. container view.
- Parameter viewController: A UIViewController to add as a child. - Parameter viewController: A UIViewController to add as a child.
- Parameter withContainer container: A UIView that is the parent of the - Parameter in container: A UIView that is the parent of the
passed in controller view within the view hierarchy. passed in controller view within the view hierarchy.
*/ */
internal func prepare(viewController: UIViewController?, withContainer container: UIView) { func prepare(viewController: UIViewController?, in container: UIView) {
guard let v = viewController else { guard let v = viewController else {
return return
} }
......
...@@ -64,11 +64,13 @@ open class SearchBarController: StatusBarController { ...@@ -64,11 +64,13 @@ open class SearchBarController: StatusBarController {
switch displayStyle { switch displayStyle {
case .partial: case .partial:
let h = y + searchBar.height let h = y + searchBar.height
rootViewController.view.y = h container.y = h
rootViewController.view.height = view.height - h container.height = view.height - h
case .full: case .full:
rootViewController.view.frame = view.bounds container.frame = view.bounds
} }
rootViewController.view.frame = container.bounds
} }
/** /**
...@@ -81,6 +83,7 @@ open class SearchBarController: StatusBarController { ...@@ -81,6 +83,7 @@ open class SearchBarController: StatusBarController {
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
displayStyle = .partial displayStyle = .partial
prepareStatusBar() prepareStatusBar()
prepareSearchBar() prepareSearchBar()
} }
......
...@@ -94,6 +94,7 @@ open class StatusBarController: RootController { ...@@ -94,6 +94,7 @@ open class StatusBarController: RootController {
*/ */
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if shouldHideStatusBarOnRotation { if shouldHideStatusBarOnRotation {
statusBar.isHidden = Application.shouldStatusBarBeHidden statusBar.isHidden = Application.shouldStatusBarBeHidden
} }
...@@ -103,11 +104,13 @@ open class StatusBarController: RootController { ...@@ -103,11 +104,13 @@ open class StatusBarController: RootController {
switch displayStyle { switch displayStyle {
case .partial: case .partial:
let h = statusBar.height let h = statusBar.height
rootViewController.view.y = h container.y = h
rootViewController.view.height = view.height - h container.height = view.height - h
case .full: case .full:
rootViewController.view.frame = view.bounds container.frame = view.bounds
} }
rootViewController.view.frame = container.bounds
} }
/** /**
......
...@@ -65,11 +65,13 @@ open class ToolbarController: StatusBarController { ...@@ -65,11 +65,13 @@ open class ToolbarController: StatusBarController {
switch displayStyle { switch displayStyle {
case .partial: case .partial:
let h = y + toolbar.height let h = y + toolbar.height
rootViewController.view.y = h container.y = h
rootViewController.view.height = view.height - h container.height = view.height - h
case .full: case .full:
rootViewController.view.frame = view.bounds container.frame = view.bounds
} }
rootViewController.view.frame = container.bounds
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment