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

Use compiler-safe Reanimated get/set APIs #6391

Merged
merged 10 commits into from
Nov 17, 2024
Merged

Use compiler-safe Reanimated get/set APIs #6391

merged 10 commits into from
Nov 17, 2024

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Nov 15, 2024

Manually went through our codebase and fixed up all cases. I used find-all search for useSharedValue, useDerivedValue, and .value accessors.

Ran into a Reanimated bug with set() functions, but it was easy to work around: software-mansion/react-native-reanimated#6613 (comment). You just have to add () => when setting it to animations, like set(() => withStuff()).

Review without whitespace

Test Plan

Tried to find each of these components on iOS, verified common interactions work. Tried most of these Android, wouldn't expect platform differences with this API switch.

Look closely through the code: set(withFoo()) would fail. It has to be set(() => withFoo()). However, set(x) is fine.

Copy link

Old size New size Diff
8.02 MB 8.02 MB 3 KB (0.04%)

}))

return (
<AnimatedPressable
accessibilityRole="button"
onPressIn={e => {
'worklet'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This wasn't a worklet. onPressIn/onPressOut run on JS already.

if (isFairlyCloseToBottom) {
runOnUI(() => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've refactored this to run the entire parent block on the UI thread since we've learned that otherwise every .value access does a thread hop. Might as well run everything on UI.

@arcalinea arcalinea temporarily deployed to reanimated-value - social-app PR #6391 November 15, 2024 21:19 — with Render Destroyed
Comment on lines 44 to +45
cancelAnimation(scale)
scale.value = withTiming(targetScale, {duration: 100})
scale.set(() => withTiming(targetScale, {duration: 100}))
Copy link
Member

Choose a reason for hiding this comment

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

is cancelAnimation blocking? do they need to be grouped together into a single runOnUI call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think it is. don't want to change this right now, i need to better understand what cancelAnimation does. we've heard we're not supposed to use it like this but i do remember some need for it. let's not touch for now?

Copy link
Member

@mozzius mozzius left a comment

Choose a reason for hiding this comment

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

Changes look good. Clicked around the app a bit and didn't run into any problems

@gaearon gaearon merged commit 474c4ef into main Nov 17, 2024
6 checks passed
@gaearon gaearon deleted the reanimated-value branch November 17, 2024 15:06
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.

3 participants