forked from software-mansion/react-native-reanimated
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add inline animated props (software-mansion#4068)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Based on software-mansion#4062 Adds support for inline animated props like this: ```js const AnimatedCircle = Animated.createAnimatedComponent(Circle); export default function SvgExample() { const sv = useSharedValue('0%'); sv.value = withRepeat(withTiming('50%', { duration: 500 }), -1, true); return ( <View style={styles.container}> <Svg height="200" width="200"> <AnimatedCircle cx="50%" cy="50%" fill="lime" r={sv} /> </Svg> </View> ); } ``` This syntax is so pretty 🤩 but there is one issue with it though. We can't differentiate between a shared value and ordinary object with `value` prop. It may happen (though I think it's rather unlikely) that user doesn't want the prop to animate but just wants to pass an object or shared value. So I'm checking if it's a whitelisted prop (user had to whitelist it anyway). If that's not enough we may add whitelist/blacklist per component in `createAnimatedComponent`. Or use `animatedProps` prop but that won't be so pretty ;_;. Also I'm no adding a warning in babel plugin. Imo it would lead to too many false positives. Something like `<Component prop={obj.value} />` is normal. ## Test plan Example above. Run on ReanimatedExample, FabricExample and something similar on WebExample.
- Loading branch information
Showing
3 changed files
with
88 additions
and
48 deletions.
There are no files selected for viewing
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
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
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