Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Fix bug with Tossable being used with TransitionSpring instances.
Browse files Browse the repository at this point in the history
Summary:
Possible scenario (in the contextual transition demo):

1. Use a TransitionSpring with Tossable.
2. Prime Draggable with an existing gesture recognizer that is active.
3. Dismiss the photo with a drag.

Expected behavior: the photo tracks the drag's movement.
Actual behavior: the photo jumps to the final position and then starts translating.

This was happening because Draggable was reading the final value of the view before TransitionSpring had a chance to set the proper initial value, causing Draggable's initialValue to be polluted with the wrong value.

After this fix, springs will always initialize the initial state before draggable reads its initial state.

Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, markwei

Reviewed By: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D2821
  • Loading branch information
Jeff Verkoeyen committed Mar 8, 2017
1 parent 1ad75e4 commit 167b21b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/interactions/Tossable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ extension Tossable: ViewInteraction {

let gesture = runtime.get(draggable.nextGestureRecognizer)

runtime.add(draggable, to: reactiveView)
// Order matters:
//
// 1. The spring's initial velocity must be set before it's re-enabled.
// 2. The spring must be registered before draggable in case draggable's gesture is already
// active and will want to immediately read the current state of the position property.

runtime.add(gesture.velocityOnReleaseStream(in: runtime.containerView), to: spring.initialVelocity)
runtime.enable(spring, whenAtRest: gesture)
runtime.add(spring, to: position)

runtime.add(gesture.atRest(), to: spring.enabled)
runtime.add(draggable, to: reactiveView)
}
}

0 comments on commit 167b21b

Please sign in to comment.