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

Add Animated.useCode hook as an alternative to Animated.Code #237

Merged
merged 2 commits into from
Apr 15, 2019
Merged

Add Animated.useCode hook as an alternative to Animated.Code #237

merged 2 commits into from
Apr 15, 2019

Conversation

jeremy-deutsch
Copy link
Contributor

I'm not sure about the current stance on adding hooks to react-native-reanimated, but this adds an Animated.useCode hook with an API halfway between useEffect and Animated.Code, that serves as an alternative to Animated.Code. Instead of passing in a callback, the user passes in a reanimated node to execute, along with an array of dependencies. Since we use useEffect under the hood, any change in the dependency array also causes the node to be updated.

One piece of behavior that I'm still iffy on is what happens if a dependency array isn't passed in. The idea is that one is always passed in (the typings reflect this), but right now, not passing one in causes the node to be re-run on every render. I think this is expected enough that we can leave it as is.

Also, this is kind of obvious, but Animated.useCode is a no-op on a version of RN without hooks.

Copy link
Contributor

@osdnk osdnk left a comment

Choose a reason for hiding this comment

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

Super cool
Just add docs and ts :)

@jeremy-deutsch
Copy link
Contributor Author

Thanks! TS is in there - I'll put up some docs soon

Added a short description of Animated.useCode to the README, with both a function signature and an example of its use in a component.
@jeremy-deutsch
Copy link
Contributor Author

Docs added! Pretty short, but I think the Animated.Code description and the example get the point across.

@osdnk
Copy link
Contributor

osdnk commented Apr 15, 2019

Nice, like it! 😄

@osdnk
Copy link
Contributor

osdnk commented Apr 15, 2019

May I ask for one more thing? Could you add an example in an app showing how to use it, @jeremy-deutsch?

@osdnk
Copy link
Contributor

osdnk commented Apr 15, 2019

But I'm going to merge it now 😄

@osdnk osdnk merged commit 0882c97 into software-mansion:master Apr 15, 2019
RobertWHurst pushed a commit to hailogroup/react-native-reanimated that referenced this pull request Oct 28, 2022
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.

2 participants