Commit 470bb0fb by Daniel Dahan

updated MotionContext partial changes for a larger update

parent 8e693f85
...@@ -29,9 +29,6 @@ ...@@ -29,9 +29,6 @@
import UIKit import UIKit
public class MotionContext { public class MotionContext {
/// Inserts the toViews first.
internal var insertToViewFirst = false
/// A reference of motion identifiers to source views. /// A reference of motion identifiers to source views.
internal var motionIdentifierToSourceView = [String: UIView]() internal var motionIdentifierToSourceView = [String: UIView]()
...@@ -50,6 +47,9 @@ public class MotionContext { ...@@ -50,6 +47,9 @@ public class MotionContext {
/// A reference of the superview to the subviews snapshots. /// A reference of the superview to the subviews snapshots.
internal var superviewToNoSnapshotSubviewMap = [UIView: [(Int, UIView)]]() internal var superviewToNoSnapshotSubviewMap = [UIView: [(Int, UIView)]]()
/// Inserts the toViews first.
internal var insertToViewFirst = false
/// A reference to the default coordinate space for transitions. /// A reference to the default coordinate space for transitions.
internal var defaultCoordinateSpace = MotionCoordinateSpace.local internal var defaultCoordinateSpace = MotionCoordinateSpace.local
...@@ -81,8 +81,8 @@ internal extension MotionContext { ...@@ -81,8 +81,8 @@ internal extension MotionContext {
self.fromViews = fromViews self.fromViews = fromViews
self.toViews = toViews self.toViews = toViews
map(views: fromViews, identifierMap: &motionIdentifierToSourceView) process(views: fromViews, identifierMap: &motionIdentifierToSourceView)
map(views: toViews, identifierMap: &motionIdentifierToDestinationView) process(views: toViews, identifierMap: &motionIdentifierToDestinationView)
} }
/** /**
...@@ -90,7 +90,7 @@ internal extension MotionContext { ...@@ -90,7 +90,7 @@ internal extension MotionContext {
- Parameter views: An Array of UIViews. - Parameter views: An Array of UIViews.
- Parameter identifierMap: A Dicionary of String to UIView pairs. - Parameter identifierMap: A Dicionary of String to UIView pairs.
*/ */
func map(views: [UIView], identifierMap: inout [String: UIView]) { func process(views: [UIView], identifierMap: inout [String: UIView]) {
for v in views { for v in views {
v.layer.removeAllAnimations() v.layer.removeAllAnimations()
...@@ -156,12 +156,12 @@ public extension MotionContext { ...@@ -156,12 +156,12 @@ public extension MotionContext {
- Returns: An optional UIView. - Returns: An optional UIView.
*/ */
func pairedView(for view: UIView) -> UIView? { func pairedView(for view: UIView) -> UIView? {
if let i = view.motionIdentifier { if let motionIdentifier = view.motionIdentifier {
if view == sourceView(for: i) { if view == sourceView(for: motionIdentifier) {
return destinationView(for: i) return destinationView(for: motionIdentifier)
} else if view == destinationView(for: i) { } else if view == destinationView(for: motionIdentifier) {
return sourceView(for: i) return sourceView(for: motionIdentifier)
} }
} }
...@@ -186,7 +186,7 @@ public extension MotionContext { ...@@ -186,7 +186,7 @@ public extension MotionContext {
case .local: case .local:
containerView = view containerView = view
while containerView != container, viewToSnapshot[containerView] == nil, let superview = containerView.superview { while containerView != container, nil == viewToSnapshot[containerView], let superview = containerView.superview {
containerView = superview containerView = superview
} }
...@@ -365,8 +365,8 @@ public extension MotionContext { ...@@ -365,8 +365,8 @@ public extension MotionContext {
/// Restores the transition subview map with its superview. /// Restores the transition subview map with its superview.
func clean() { func clean() {
for (superview, subviews) in superviewToNoSnapshotSubviewMap { for (superview, subviews) in superviewToNoSnapshotSubviewMap {
for (index, view) in subviews.reversed() { for (k, v) in subviews.reversed() {
superview.insertSubview(view, at: index) superview.insertSubview(v, at: k)
} }
} }
} }
...@@ -434,9 +434,11 @@ internal extension MotionContext { ...@@ -434,9 +434,11 @@ internal extension MotionContext {
/// Removes all snapshots that are not using .useNoSnapshot. /// Removes all snapshots that are not using .useNoSnapshot.
func removeAllSnapshots() { func removeAllSnapshots() {
for (k, v) in viewToSnapshot { for (view, snapshot) in viewToSnapshot {
if k != v { if view != snapshot {
v.removeFromSuperview() snapshot.removeFromSuperview()
} else {
view.layer.removeAllAnimations()
} }
} }
} }
...@@ -446,8 +448,12 @@ internal extension MotionContext { ...@@ -446,8 +448,12 @@ internal extension MotionContext {
- Parameter rootView: A UIVIew. - Parameter rootView: A UIVIew.
*/ */
func removeSnapshots(rootView: UIView) { func removeSnapshots(rootView: UIView) {
if let v = viewToSnapshot[rootView], v != rootView { if let snapshot = viewToSnapshot[rootView] {
v.removeFromSuperview() if rootView != snapshot {
snapshot.removeFromSuperview()
} else {
rootView.layer.removeAllAnimations()
}
} }
for v in rootView.subviews { for v in rootView.subviews {
......
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