Commit 5653affe by Daniel Dahan

reworked SourcePreprocessor

parent 63316063
...@@ -32,64 +32,90 @@ class SourcePreprocessor: MotionPreprocessor { ...@@ -32,64 +32,90 @@ class SourcePreprocessor: MotionPreprocessor {
/// A reference to a MotionContext. /// A reference to a MotionContext.
weak var context: MotionContext! weak var context: MotionContext!
func process(fromViews: [UIView], toViews: [UIView]) { /**
for fv in fromViews { Processes the transitionary views.
guard let id = context[fv]?.motionIdentifier, - Parameter fromViews: An Array of UIViews.
let tv = context.destinationView(for: id) else { continue } - Parameter toViews: An Array of UIViews.
prepareFor(view: fv, targetView: tv) */
func process(fromViews: [UIView], toViews: [UIView]) {
for fv in fromViews {
guard let i = context[fv]?.motionIdentifier, let tv = context.destinationView(for: i) else {
continue
}
prepare(view: fv, for: tv)
}
for tv in toViews {
guard let i = context[tv]?.motionIdentifier, let fv = context.sourceView(for: i) else {
continue
}
prepare(view: tv, for: fv)
}
} }
for tv in toViews {
guard let id = context[tv]?.motionIdentifier,
let fv = context.sourceView(for: id) else { continue }
prepareFor(view: tv, targetView: fv)
}
}
func prepareFor(view: UIView, targetView: UIView) { /**
let targetPos = context.container.convert(targetView.layer.position, from: targetView.superview!) Prepares a given view for a target view.
- Parameter view: A UIView.
- Parameter for targetView: A UIView.
*/
func prepare(view: UIView, for targetView: UIView) {
let targetPos = context.container.convert(targetView.layer.position, from: targetView.superview!)
var state = context[view]!
var state = context[view]! /**
Use global coordinate space since over target position is
converted from the global container
*/
state.coordinateSpace = .global
// use global coordinate space since over target position is converted from the global container // Remove incompatible options.
state.coordinateSpace = .global state.position = targetPos
state.transform = nil
state.size = nil
state.cornerRadius = nil
// remove incompatible options if view.bounds.size != targetView.bounds.size {
state.position = targetPos state.size = targetView.bounds.size
state.transform = nil }
state.size = nil
state.cornerRadius = nil
if view.bounds.size != targetView.bounds.size { if view.layer.cornerRadius != targetView.layer.cornerRadius {
state.size = targetView.bounds.size state.cornerRadius = targetView.layer.cornerRadius
} }
if view.layer.cornerRadius != targetView.layer.cornerRadius {
state.cornerRadius = targetView.layer.cornerRadius if view.layer.transform != targetView.layer.transform {
} state.transform = targetView.layer.transform
if view.layer.transform != targetView.layer.transform { }
state.transform = targetView.layer.transform
} if view.layer.shadowColor != targetView.layer.shadowColor {
if view.layer.shadowColor != targetView.layer.shadowColor { state.shadowColor = targetView.layer.shadowColor
state.shadowColor = targetView.layer.shadowColor }
}
if view.layer.shadowOpacity != targetView.layer.shadowOpacity { if view.layer.shadowOpacity != targetView.layer.shadowOpacity {
state.shadowOpacity = targetView.layer.shadowOpacity state.shadowOpacity = targetView.layer.shadowOpacity
} }
if view.layer.shadowOffset != targetView.layer.shadowOffset {
state.shadowOffset = targetView.layer.shadowOffset if view.layer.shadowOffset != targetView.layer.shadowOffset {
} state.shadowOffset = targetView.layer.shadowOffset
if view.layer.shadowRadius != targetView.layer.shadowRadius { }
state.shadowRadius = targetView.layer.shadowRadius
} if view.layer.shadowRadius != targetView.layer.shadowRadius {
if view.layer.shadowPath != targetView.layer.shadowPath { state.shadowRadius = targetView.layer.shadowRadius
state.shadowPath = targetView.layer.shadowPath }
}
if view.layer.contentsRect != targetView.layer.contentsRect { if view.layer.shadowPath != targetView.layer.shadowPath {
state.contentsRect = targetView.layer.contentsRect state.shadowPath = targetView.layer.shadowPath
} }
if view.layer.contentsScale != targetView.layer.contentsScale {
state.contentsScale = targetView.layer.contentsScale if view.layer.contentsRect != targetView.layer.contentsRect {
} state.contentsRect = targetView.layer.contentsRect
}
if view.layer.contentsScale != targetView.layer.contentsScale {
state.contentsScale = targetView.layer.contentsScale
}
context[view] = state context[view] = state
} }
} }
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