Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cancel animation work from JS thread. #1043

Merged
merged 1 commit into from Jul 30, 2020
Merged

Make cancel animation work from JS thread. #1043

merged 1 commit into from Jul 30, 2020

Conversation

kmagiera
Copy link
Member

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 for cancelAnimation 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 call cancelAnimation on rotation SV. I also tried wrapping that call with runOnUI to verify it works on both threads.

@kmagiera
Copy link
Member Author

Also cc @wcandillon who pointed out this issue.

@wcandillon
Copy link
Contributor

yes that works 🙌🏻

@kmagiera kmagiera merged commit 058ecdf into master Jul 30, 2020
@kmagiera kmagiera deleted the fix_cancel branch July 30, 2020 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants