Commit 430cc140 by Daniel Dahan

updated container and transitionContainer in MotionController to no longer use unwrapped optionals

parent 650dd64c
...@@ -282,6 +282,15 @@ internal extension Motion { ...@@ -282,6 +282,15 @@ internal extension Motion {
return return
} }
guard let c = container else {
return
}
guard let tc = transitionContainer else {
return
}
context.clean() context.clean()
if isFinished && isPresenting && toOverFullScreen { if isFinished && isPresenting && toOverFullScreen {
...@@ -292,7 +301,7 @@ internal extension Motion { ...@@ -292,7 +301,7 @@ internal extension Motion {
fromViewController!.motionStoredSnapshot = container fromViewController!.motionStoredSnapshot = container
fromView.removeFromSuperview() fromView.removeFromSuperview()
fromView.addSubview(container) fromView.addSubview(c)
} else if !isFinished && !isPresenting && fromOverFullScreen { } else if !isFinished && !isPresenting && fromOverFullScreen {
// cancelled dismissing a overFullScreen VC // cancelled dismissing a overFullScreen VC
context.unhide(rootView: fromView) context.unhide(rootView: fromView)
...@@ -301,19 +310,19 @@ internal extension Motion { ...@@ -301,19 +310,19 @@ internal extension Motion {
toViewController!.motionStoredSnapshot = container toViewController!.motionStoredSnapshot = container
toView.removeFromSuperview() toView.removeFromSuperview()
toView.addSubview(container) toView.addSubview(c)
} else { } else {
context.unhideAll() context.unhideAll()
context.removeAllSnapshots() context.removeAllSnapshots()
container.removeFromSuperview() c.removeFromSuperview()
} }
// move fromView & toView back from our container back to the one supplied by UIKit // move fromView & toView back from our container back to the one supplied by UIKit
if (toOverFullScreen && isFinished) || (fromOverFullScreen && !isFinished) { if (toOverFullScreen && isFinished) || (fromOverFullScreen && !isFinished) {
transitionContainer.addSubview(isFinished ? fromView : toView) tc.addSubview(isFinished ? fromView : toView)
} }
transitionContainer.addSubview(isFinished ? toView : fromView) tc.addSubview(isFinished ? toView : fromView)
if isPresenting != isFinished, !isContainerController { if isPresenting != isFinished, !isContainerController {
// only happens when present a .overFullScreen VC // only happens when present a .overFullScreen VC
...@@ -365,8 +374,12 @@ fileprivate extension Motion { ...@@ -365,8 +374,12 @@ fileprivate extension Motion {
/// Prepares the snapshot view, which hides any flashing that may occur. /// Prepares the snapshot view, which hides any flashing that may occur.
func prepareSnapshotView() { func prepareSnapshotView() {
fullScreenSnapshot = transitionContainer.window?.snapshotView(afterScreenUpdates: true) ?? fromView.snapshotView(afterScreenUpdates: true) guard let v = transitionContainer else {
(transitionContainer.window ?? transitionContainer)?.addSubview(fullScreenSnapshot) return
}
fullScreenSnapshot = v.window?.snapshotView(afterScreenUpdates: true) ?? fromView.snapshotView(afterScreenUpdates: true)
(v.window ?? transitionContainer)?.addSubview(fullScreenSnapshot)
if let v = fromViewController?.motionStoredSnapshot { if let v = fromViewController?.motionStoredSnapshot {
v.removeFromSuperview() v.removeFromSuperview()
...@@ -381,10 +394,14 @@ fileprivate extension Motion { ...@@ -381,10 +394,14 @@ fileprivate extension Motion {
/// Prepares the MotionContext instance. /// Prepares the MotionContext instance.
func prepareContext() { func prepareContext() {
guard let v = container else {
return
}
context.loadViewAlpha(rootView: toView) context.loadViewAlpha(rootView: toView)
context.loadViewAlpha(rootView: fromView) context.loadViewAlpha(rootView: fromView)
container.addSubview(toView) v.addSubview(toView)
container.addSubview(fromView) v.addSubview(fromView)
} }
/// Prepares the toView instance. /// Prepares the toView instance.
...@@ -541,9 +558,9 @@ fileprivate extension Motion { ...@@ -541,9 +558,9 @@ fileprivate extension Motion {
/// Updates the container background color. /// Updates the container background color.
func updateContainerBackgroundColor() { func updateContainerBackgroundColor() {
if let v = containerBackgroundColor { if let v = containerBackgroundColor {
container.backgroundColor = v container?.backgroundColor = v
} else if !toOverFullScreen && !fromOverFullScreen { } else if !toOverFullScreen && !fromOverFullScreen {
container.backgroundColor = toView.backgroundColor container?.backgroundColor = toView.backgroundColor
} }
} }
......
...@@ -64,10 +64,10 @@ public class MotionController: NSObject { ...@@ -64,10 +64,10 @@ public class MotionController: NSObject {
A view container used to hold all the animating views during a A view container used to hold all the animating views during a
transition. transition.
*/ */
public internal(set) var container: UIView! public internal(set) var container: UIView?
/// UIKit's supplied transition container. /// UIKit's supplied transition container.
internal var transitionContainer: UIView! internal var transitionContainer: UIView?
/// An optional completion callback. /// An optional completion callback.
internal var completionCallback: ((Bool) -> Void)? internal var completionCallback: ((Bool) -> Void)?
...@@ -259,7 +259,7 @@ public extension MotionController { ...@@ -259,7 +259,7 @@ public extension MotionController {
} }
guard isAnimated else { guard isAnimated else {
complete(isFinished:false) complete(isFinished: false)
return return
} }
...@@ -455,16 +455,24 @@ internal extension MotionController { ...@@ -455,16 +455,24 @@ internal extension MotionController {
fileprivate extension MotionController { fileprivate extension MotionController {
/// Prepares the transition container. /// Prepares the transition container.
func prepareTransitionContainer() { func prepareTransitionContainer() {
transitionContainer.isUserInteractionEnabled = false guard let v = transitionContainer else {
return
}
v.isUserInteractionEnabled = false
// a view to hold all the animating views // a view to hold all the animating views
container = UIView(frame: transitionContainer.bounds) container = UIView(frame: v.bounds)
transitionContainer.addSubview(container) v.addSubview(container!)
} }
/// Prepares the context. /// Prepares the context.
func prepareContext() { func prepareContext() {
context = MotionContext(container:container) guard let v = container else {
return
}
context = MotionContext(container: v)
} }
/// Prepares the preprocessors. /// Prepares the preprocessors.
......
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