diff --git a/app/src/examples/SetNativePropsExample.tsx b/app/src/examples/SetNativePropsExample.tsx new file mode 100644 index 000000000000..d3ae75960abd --- /dev/null +++ b/app/src/examples/SetNativePropsExample.tsx @@ -0,0 +1,70 @@ +import Animated, { + runOnJS, + setNativeProps, + useAnimatedRef, +} from 'react-native-reanimated'; +import { Button, StyleSheet } from 'react-native'; +import { + Gesture, + GestureDetector, + GestureHandlerRootView, + TextInput, +} from 'react-native-gesture-handler'; + +import React from 'react'; + +const AnimatedTextInput = Animated.createAnimatedComponent(TextInput); + +function delay(ms: number) { + const start = performance.now(); + while (performance.now() - start < ms) {} +} + +export default function SetNativePropsExample() { + const [text, setText] = React.useState('Hello'); + + const animatedRef = useAnimatedRef(); + + const send = () => { + delay(500); + console.log('SEND', text); + setText(''); // calling setText affects the JS state but doesn't update the native view + }; + + const tap = Gesture.Tap().onEnd(() => { + 'worklet'; + setNativeProps(animatedRef, { + text: '', + backgroundColor: `hsl(${Math.random() * 360}, 100%, 50%)`, + }); + runOnJS(send)(); + }); + + return ( + + + +