Commit a77657d6 by Daniel Dahan

updated RootController transition method to use Motion transitions

parent 4d0b9240
......@@ -415,8 +415,8 @@ open class NavigationDrawerController: RootController {
prepare()
}
open override func transition(to viewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
super.transition(to: viewController, duration: duration, options: options, animations: animations) { [weak self, completion = completion] (result) in
open override func transition(to viewController: UIViewController, completion: ((Bool) -> Void)? = nil) {
super.transition(to: viewController) { [weak self, completion = completion] (result) in
guard let s = self else {
return
}
......@@ -452,6 +452,8 @@ open class NavigationDrawerController: RootController {
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) {
......@@ -976,7 +978,7 @@ extension NavigationDrawerController {
/// Prepares the contentViewController.
fileprivate func prepareContentViewController() {
contentViewController.view.backgroundColor = .black
prepare(viewController: contentViewController, withContainer: view)
prepare(viewController: contentViewController, in: view)
view.sendSubview(toBack: contentViewController.view)
}
......@@ -986,7 +988,7 @@ extension NavigationDrawerController {
return
}
prepare(viewController: leftViewController, withContainer: v)
prepare(viewController: leftViewController, in: v)
}
/// A method that prepares the rightViewController.
......@@ -995,7 +997,7 @@ extension NavigationDrawerController {
return
}
prepare(viewController: rightViewController, withContainer: v)
prepare(viewController: rightViewController, in: v)
}
/// A method that prepares the leftView.
......
......@@ -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
main UIViewController. To swap the rootViewController, it
......@@ -53,6 +56,9 @@ open class RootController: 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.
- Parameter aDecoder: A NSCoder instance.
......@@ -93,40 +99,27 @@ open class RootController: UIViewController {
A method to swap rootViewController objects.
- Parameter toViewController: The UIViewController to swap
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
the transition animation from the active rootViewController
to the toViewController has completed.
*/
open func transition(to viewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
rootViewController.willMove(toParentViewController: nil)
addChildViewController(viewController)
viewController.view.frame = rootViewController.view.frame
transition(from: rootViewController,
to: viewController,
duration: duration,
options: options,
animations: animations) { [weak self, viewController = viewController, completion = completion] (result) in
guard let s = self else {
return
}
viewController.didMove(toParentViewController: s)
s.rootViewController.removeFromParentViewController()
s.rootViewController = viewController
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)
}
open func transition(to viewController: UIViewController, completion: ((Bool) -> Void)? = nil) {
let fvc = rootViewController!
let tvc = viewController
tvc.view.frame.size = view.bounds.size
tvc.motionModalTransitionType = motionTransitionType
view.isUserInteractionEnabled = false
Motion.shared.transition(from: fvc, to: tvc, in: container) { [weak self, completion = completion] (isFinished) in
guard let s = self else {
return
}
s.rootViewController = tvc
s.view.isUserInteractionEnabled = true
completion?(isFinished)
}
}
/**
......@@ -147,14 +140,24 @@ open class RootController: UIViewController {
view.clipsToBounds = true
view.backgroundColor = .white
view.contentScaleFactor = Screen.scale
prepareContainer()
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.
internal func prepareRootViewController() {
prepare(viewController: rootViewController, withContainer: view)
func prepareRootViewController() {
prepare(viewController: rootViewController, in: container)
}
/**
......@@ -162,10 +165,10 @@ extension RootController {
the BarController within the passed in
container view.
- 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.
*/
internal func prepare(viewController: UIViewController?, withContainer container: UIView) {
func prepare(viewController: UIViewController?, in container: UIView) {
guard let v = viewController else {
return
}
......
......@@ -64,11 +64,13 @@ open class SearchBarController: StatusBarController {
switch displayStyle {
case .partial:
let h = y + searchBar.height
rootViewController.view.y = h
rootViewController.view.height = view.height - h
container.y = h
container.height = view.height - h
case .full:
rootViewController.view.frame = view.bounds
container.frame = view.bounds
}
rootViewController.view.frame = container.bounds
}
/**
......@@ -81,6 +83,7 @@ open class SearchBarController: StatusBarController {
open override func prepare() {
super.prepare()
displayStyle = .partial
prepareStatusBar()
prepareSearchBar()
}
......
......@@ -94,6 +94,7 @@ open class StatusBarController: RootController {
*/
open override func layoutSubviews() {
super.layoutSubviews()
if shouldHideStatusBarOnRotation {
statusBar.isHidden = Application.shouldStatusBarBeHidden
}
......@@ -103,11 +104,13 @@ open class StatusBarController: RootController {
switch displayStyle {
case .partial:
let h = statusBar.height
rootViewController.view.y = h
rootViewController.view.height = view.height - h
container.y = h
container.height = view.height - h
case .full:
rootViewController.view.frame = view.bounds
container.frame = view.bounds
}
rootViewController.view.frame = container.bounds
}
/**
......
......@@ -65,11 +65,13 @@ open class ToolbarController: StatusBarController {
switch displayStyle {
case .partial:
let h = y + toolbar.height
rootViewController.view.y = h
rootViewController.view.height = view.height - h
container.y = h
container.height = view.height - h
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