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

Replace useRef with useState for useSharedValue #5458

Merged

Conversation

amadeus
Copy link
Contributor

@amadeus amadeus commented Dec 2, 2023

Summary

The general idea here is that we can avoid the makeMutable call on every single render. This change is also compatible with hot reloading.

We (at Discord) have been running this patch on top of our own reanimated now for a few weeks and haven't noticed any side effects of the change.

There has been a bit of additional discussion I've seen surrounding this issue here: #3199

Test plan

N/A

@tomekzaw
Copy link
Member

tomekzaw commented Dec 4, 2023

@amadeus Thanks a lot for submitting this PR!

The general idea here is that we can avoid the makeMutable call on every
single render.  This change is also compatible with hot reloading.
@amadeus amadeus force-pushed the shared-value-hook-improvement branch from 46a8b54 to 5304613 Compare December 6, 2023 02:57
Copy link
Member

@piaskowyk piaskowyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it and everything works as expected 🎉 Thanks for the PR!

Copy link
Member

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the PR!

@piaskowyk piaskowyk added this pull request to the merge queue Dec 6, 2023
Merged via the queue into software-mansion:main with commit b7f5805 Dec 6, 2023
7 checks passed
@amadeus amadeus deleted the shared-value-hook-improvement branch December 6, 2023 17:48
@amadeus
Copy link
Contributor Author

amadeus commented Dec 6, 2023

Yay Thanks!

useEffect(() => {
return () => {
cancelAnimation(ref.current);
cancelAnimation(mutable);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a drive-by comment but in general effects that only do cleanup usually indicate that something else is wrong. Effects should be symmetrical.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d be curious for your thoughts on how something like this should work? Assuming you have an animation in progress that needs to be cleaned up on unmount

Latropos pushed a commit that referenced this pull request Dec 12, 2023
## Summary
The general idea here is that we can avoid the `makeMutable` call on
every single render. This change is also compatible with hot reloading.

We (at Discord) have been running this patch on top of our own
reanimated now for a few weeks and haven't noticed any side effects of
the change.

There has been a bit of additional discussion I've seen surrounding this
issue here:
#3199

## Test plan
N/A
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

4 participants