This repository was archived by the owner on Oct 8, 2021. It is now read-only.
Proposal: add setNativeProps to Group, Shape, Text #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds setNativeProps methods to the
<Group/>
,<Shape/>
, and<Text/>
components provided by art to allow direct manipulation of the native component, as per https://facebook.github.io/react-native/docs/direct-manipulation.A benefit of this change is that we can use
Animated.Value
s to animate props like opacity without the animation calling the render method each frame (currentlyforceUpdate
is fired to update the component, causing a rerender).My personal motivation is to use react-native-reanimated with art, which requires this change to work, but I believe it has value more generally.
Notes/discussion points:
render
andsetNativeProps
methods for each component. This may differ from what a user would expect, wheresetNativeProps
suggests passing its arguments straight to the native component. I've done this because I think most users are going to want to set props in the render method, and then directly manipulate them in a consistent manner, relying on art to translate the props to what the native component requires. If we were to pass the arguments directly through, many of them would need to be a different format to their equivalent prop, which I think adds unnecessary complexitysetNativeProps
merges existing props into the new props before translation. The method we use does provide for only translating the props that would change as a result of the new props passed in (we pass an array of the props required to be translated), but I suspect the logic to work out what those props would be would be as expensive to compute as the 'over computing' we are undertaking by translating all props, every time.Test Plan
I've tested (on iOS simulator, Android emulator and real iPhone 8) that:
<Shape/>
component without firing the render methodWhat's required for testing (prerequisites)?
What are the steps to reproduce (after prerequisites)?
Compatibility
Checklist
README.md
CHANGELOG.md
example/App.js
)