Commit 63316063 by Daniel Dahan

reworked MatchPreprocessor

parent 936c5b62
...@@ -44,7 +44,7 @@ public protocol MotionAnimator: class { ...@@ -44,7 +44,7 @@ public protocol MotionAnimator: class {
func canAnimate(view: UIView, isAppearing: Bool) -> Bool func canAnimate(view: UIView, isAppearing: Bool) -> Bool
/** /**
Animates the from-views to the to-views. Animates the fromViews to the toViews.
- Parameter fromViews: An Array of UIViews. - Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews. - Parameter toViews: An Array of UIViews.
- Returns: A TimeInterval. - Returns: A TimeInterval.
......
...@@ -81,7 +81,7 @@ extension MotionDefaultAnimator { ...@@ -81,7 +81,7 @@ extension MotionDefaultAnimator {
} }
/** /**
Animates the from-views to the to-views. Animates the fromViews to the toViews.
- Parameter fromViews: An Array of UIViews. - Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews. - Parameter toViews: An Array of UIViews.
- Returns: A TimeInterval. - Returns: A TimeInterval.
......
...@@ -27,6 +27,6 @@ ...@@ -27,6 +27,6 @@
*/ */
internal protocol MotionHasInsertOrder: class { internal protocol MotionHasInsertOrder: class {
/// A boolean indicating whether to insert the to-view first or not. /// A boolean indicating whether to insert the toView first or not.
var insertToViewFirst: Bool { get set } var insertToViewFirst: Bool { get set }
} }
...@@ -174,7 +174,7 @@ public class Motion: MotionController { ...@@ -174,7 +174,7 @@ public class Motion: MotionController {
*/ */
internal var forceNonInteractive = false internal var forceNonInteractive = false
/// Inserts the to-views first. /// Inserts the toViews first.
internal var insertToViewFirst = false internal var insertToViewFirst = false
/// Indicates whether a UINavigationController is transitioning. /// Indicates whether a UINavigationController is transitioning.
...@@ -198,12 +198,12 @@ public class Motion: MotionController { ...@@ -198,12 +198,12 @@ public class Motion: MotionController {
return !isContainerController && (.overFullScreen == toViewController!.modalPresentationStyle || .overCurrentContext == toViewController!.modalPresentationStyle) return !isContainerController && (.overFullScreen == toViewController!.modalPresentationStyle || .overCurrentContext == toViewController!.modalPresentationStyle)
} }
/// A reference to the from-view, fromViewController.view. /// A reference to the fromView, fromViewController.view.
internal var fromView: UIView { internal var fromView: UIView {
return fromViewController!.view return fromViewController!.view
} }
/// A reference to the to-view, toViewController.view. /// A reference to the toView, toViewController.view.
internal var toView: UIView { internal var toView: UIView {
return toViewController!.view return toViewController!.view
} }
......
...@@ -70,7 +70,7 @@ public class MotionContext { ...@@ -70,7 +70,7 @@ public class MotionContext {
internal extension MotionContext { internal extension MotionContext {
/** /**
Sets the from-views and to-views within the transition context. Sets the fromViews and toViews within the transition context.
- Parameter fromViews: An Array of UIViews. - Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews. - Parameter toViews: An Array of UIViews.
*/ */
......
...@@ -115,7 +115,7 @@ public class MotionController: NSObject { ...@@ -115,7 +115,7 @@ public class MotionController: NSObject {
/// An Array of MotionPlugins used during a transition. /// An Array of MotionPlugins used during a transition.
internal var plugins: [MotionPlugin]! internal var plugins: [MotionPlugin]!
/// The matching from-views to to-views based on the motionIdentifier value. /// The matching fromViews to toViews based on the motionIdentifier value.
internal var transitionPairs: [(fromViews: [UIView], toViews: [UIView])]! internal var transitionPairs: [(fromViews: [UIView], toViews: [UIView])]!
/// Plugins that are enabled during the transition. /// Plugins that are enabled during the transition.
...@@ -320,7 +320,7 @@ internal extension MotionController { ...@@ -320,7 +320,7 @@ internal extension MotionController {
preparePlugins() preparePlugins()
} }
/// Prepares the transition from-view & to-view pairs. /// Prepares the transition fromView & toView pairs.
func prepareTransitionPairs() { func prepareTransitionPairs() {
guard isTransitioning else { guard isTransitioning else {
fatalError() fatalError()
......
...@@ -33,45 +33,50 @@ class MatchPreprocessor: MotionPreprocessor { ...@@ -33,45 +33,50 @@ class MatchPreprocessor: MotionPreprocessor {
weak var context: MotionContext! weak var context: MotionContext!
/** /**
Implementation for processor. Processes the transitionary views.
- Parameter fromViews: An Array of UIViews. - Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews. - Parameter toViews: An Array of UIViews.
*/ */
func process(fromViews: [UIView], toViews: [UIView]) { func process(fromViews: [UIView], toViews: [UIView]) {
for tv in toViews { for tv in toViews {
guard let id = tv.motionIdentifier, let fv = context.sourceView(for: id) else { continue } guard let i = tv.motionIdentifier, let fv = context.sourceView(for: i) else { continue }
var tvState = context[tv] ?? MotionTransitionState() var tvState = context[tv] ?? MotionTransitionState()
var fvState = context[fv] ?? MotionTransitionState() var fvState = context[fv] ?? MotionTransitionState()
if let beginStateIfMatched = tvState.beginStateIfMatched { if let v = tvState.beginStateIfMatched {
tvState.append(.beginWith(transitions: beginStateIfMatched)) tvState.append(.beginWith(transitions: v))
} }
if let beginStateIfMatched = fvState.beginStateIfMatched {
fvState.append(.beginWith(transitions: beginStateIfMatched)) if let v = fvState.beginStateIfMatched {
fvState.append(.beginWith(transitions: v))
} }
// match is just a two-way source effect tvState.motionIdentifier = i
tvState.motionIdentifier = id tvState.opacity = 0
fvState.motionIdentifier = id
fvState.motionIdentifier = i
fvState.arc = tvState.arc fvState.arc = tvState.arc
fvState.duration = tvState.duration fvState.duration = tvState.duration
fvState.timingFunction = tvState.timingFunction fvState.timingFunction = tvState.timingFunction
fvState.delay = tvState.delay fvState.delay = tvState.delay
fvState.spring = tvState.spring fvState.spring = tvState.spring
tvState.opacity = 0
let forceNonFade = tvState.nonFade || fvState.nonFade let forceNonFade = tvState.nonFade || fvState.nonFade
let isNonOpaque = !fv.isOpaque || fv.alpha < 1 || !tv.isOpaque || tv.alpha < 1 let isNonOpaque = !fv.isOpaque || fv.alpha < 1 || !tv.isOpaque || tv.alpha < 1
if !forceNonFade && isNonOpaque { if !forceNonFade && isNonOpaque {
// cross fade if from/toViews are not opaque // Cross fade if from/toViews are not opaque.
fvState.opacity = 0 fvState.opacity = 0
} else { } else {
// no cross fade in this case, fromView is always displayed during the transition. // No cross fade in this case, fromView is always displayed during the transition.
fvState.opacity = nil fvState.opacity = nil
// we dont want two shadows showing up. Therefore we disable toView's shadow when fromView is able to display its shadow /**
We dont want two shadows showing up. Therefore we disable toView's
shadow when fromView is able to display its shadow.
*/
if !fv.layer.masksToBounds && fvState.displayShadow { if !fv.layer.masksToBounds && fvState.displayShadow {
tvState.displayShadow = false tvState.displayShadow = false
} }
......
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