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 setNativeProps helper function on UI runtime #4595

Merged
merged 13 commits into from
Aug 7, 2023

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Jun 20, 2023

Summary

Currently, there is no way to update props from a worklet imperatively (except for calling JSI bindings _updatePropsPaper or _updatePropsFabric directly, but they are implementation-detail and meant to be private).

This PR adds setNativeProps helper function available on the UI runtime which accepts an animated ref (created with useAnimatedRef()) along with a plain JS object with props to be updated.

At the moment, both Paper and Fabric is supported as well as basic web support works. Proper web support is doable but requires a refactor of useAnimatedRef.

Test plan

SetNativePropsExample.tsx 🆕

@tomekzaw tomekzaw changed the title Implement setNativeProps on Paper and Fabric Add setNativeProps helper function on UI runtime Jun 20, 2023
@tomekzaw tomekzaw marked this pull request as ready for review August 3, 2023 12:49
@tomekzaw tomekzaw requested a review from piaskowyk August 3, 2023 12:49
src/reanimated2/NativeMethods.ts Outdated Show resolved Hide resolved
src/reanimated2/NativeMethods.ts Outdated Show resolved Hide resolved
src/reanimated2/NativeMethods.ts Outdated Show resolved Hide resolved
src/reanimated2/NativeMethods.ts Outdated Show resolved Hide resolved
@tomekzaw tomekzaw requested a review from piaskowyk August 7, 2023 10:43
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.

🚀

@tomekzaw tomekzaw added this pull request to the merge queue Aug 7, 2023
Merged via the queue into main with commit dac030d Aug 7, 2023
6 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/set-native-props branch August 7, 2023 12:55
github-merge-queue bot pushed a commit that referenced this pull request Sep 12, 2023
# Motivation

This PR documents the new `setNativeProps` function added in
#4595


https://github.com/software-mansion/react-native-reanimated/assets/39658211/32ab57fa-37a5-4e3e-abfb-2afdf1a99157

# Testing

```sh
cd docs
yarn
yarn start
```
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