This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Proposal: add setNativeProps to Group, Shape, Text #41
Open
MorganIsBatman
wants to merge
4
commits into
react-native-art:master
Choose a base branch
from
MorganIsBatman:feature/add-setNativeProps-to-components
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Proposal: add setNativeProps to Group, Shape, Text #41
MorganIsBatman
wants to merge
4
commits into
react-native-art:master
from
MorganIsBatman:feature/add-setNativeProps-to-components
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- new `translatePropsToNativeProps` helper to return required nativeProps translated from props - change render method of `<Group/>`, `<Shape/>`, `<Text/>` to use the method above to translate props to nativeProps - implement `setNativeProps` in the above three components, using the same helper to translate changed and existing props into nativeProps.
Sorry for the delay on this one. It seems like a valid use case. I'll make sure to check it out in a day or two. Can you also include some example Animations in the example app? |
All good! Absolutely - I'll sort those out this weekend :) |
A simple 3-flashing circle animation to demonstrate animation. Note: this animation would still be possible without the addition of `setNativeProps`, however it would trigger a rerender of the Shape component for each step of the animation.
MorganIsBatman
force-pushed
the
feature/add-setNativeProps-to-components
branch
from
December 22, 2019 23:04
c73f3a2
to
c69c501
Compare
@Esemesek - is there anything more you need me to do with this? I have a few days spare next week that I can work on it if there's anything that needs doing. |
@MorganIsBatman It seems alright. I am quite hesitant because I don't want to break anything. The example looks really cool C: Will try to progress this as soon as I find more time. |
Great. Thanks for your response @Esemesek :) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
)