Make cancel animation work from JS thread. #1043
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Update implementation of
cancelAnimation
to make it work from both UI and JS threads. Before this change, cancelling animation would only work from UI thread. Now, we use a simple trick of assigning the current (static) value to the shared value which results in the animation being cancelled.Changes
This PR updates the implementation of
cancelAniamtion
to make the provided sharedValue reassign its.value
prop to its current.value
. This results in the animation (if it is running on the shared value) to stop at the current point. This change isn't ideal as it may have a side-effect of triggering mappers that depend on the provided value. The previous implementation wouldn't trigger mapper updates as it wasn't modifying the.value
prop but only some underlying animation-related data kept in the shared value object. I think, however, this side-effect shouldn't be critical and we don't really have enough usecases forcancelAnimation
to be able to tell if this causes any problems.Testing
I tested this by extending the number of loops in WobbleExample to
70
. Then I added a button that'd callcancelAnimation
onrotation
SV. I also tried wrapping that call withrunOnUI
to verify it works on both threads.