- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: Add support for boxShadow #6749
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix CI and we are good to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go a bit further. Let's see how boxShadow
fares in both Jest and our runtime tests.
...
…Shadow Runtime test is disabled for now
400f0ce
to
5fa603a
Compare
8f2f601
to
e43a655
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go!! 🥳
apps/common-app/src/examples/RuntimeTests/tests/props/boxShadow.test.tsx
Outdated
Show resolved
Hide resolved
## Summary This PR introduces support for boxShadow - a new feature from React Native 0.76+ NewArch. At the same time it address #6687 . * Adds parser for `boxShadow` prop, that transforms string into a `boxShadow` object. * Adds Jest tests * Fix colors flickering when run with `withSpring` Runtime test are added for future fabric support in RuntimeTests. Fixes #6687 https://github.com/user-attachments/assets/9051d98f-cfb0-41b0-a2b4-6a8c11b477da ## Test plan To test, paste this code snippet to `EmptyExample` and run. <details> <summary>EmptyExample code</summary> ```js import React from 'react'; import { Pressable, SafeAreaView, ScrollView, Text, View } from 'react-native'; import Animated, { Easing, interpolate, interpolateColor, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated'; import processBoxShadow from 'react-native-reanimated/src/processBoxShadow'; const AnimatedPressable = Animated.createAnimatedComponent(Pressable); const BUTTON_TRANSITION_TIME = 500; const EmptyExample = () => { const pressed = useSharedValue<number>(0); const animatedBoxShadow = useAnimatedStyle(() => { const blurRadius = interpolate(pressed.value, [0, 1], [10, 0]); const color = interpolateColor( pressed.value, [0, 1], ['#57b495', '#31775d'] ); const boxShadow = `0px 4px ${blurRadius} 0px ${color}`; return { boxShadow, }; }); const backgroundColorStyle = useAnimatedStyle(() => { const backgroundColor = interpolateColor( pressed.value, [0, 1], ['#b1dfd0', '#57b495'] ); return { backgroundColor, }; }); const handlePressIn = () => { pressed.value = withTiming(1, { duration: BUTTON_TRANSITION_TIME, easing: Easing.out(Easing.ease), }); }; const handlePressOut = () => { pressed.value = withTiming(0, { duration: BUTTON_TRANSITION_TIME, easing: Easing.out(Easing.ease), }); }; return ( <SafeAreaView style={backgroundStyle}> <ScrollView style={backgroundStyle}> <View style={{ padding: 24, }}> <Text style={{ fontSize: 18, color: '#001a72', fontWeight: 'bold', textAlign: 'center', marginBottom: 16, }}> The background color animation will work and so will the shadow ✨ </Text> <Text style={{ fontSize: 14, color: '#001a72', marginBottom: 8, }}> BoxShadow is officially supported by Reanimated 💅 </Text> <AnimatedPressable style={[ backgroundColorStyle, animatedBoxShadow, { padding: 16, borderRadius: 100, marginVertical: 16, }, ]} onPressIn={handlePressIn} onPressOut={handlePressOut}> <Text style={{ color: '#001a72' }}> Hello I am button with shadow </Text> </AnimatedPressable> </View> </ScrollView> </SafeAreaView> ); }; const backgroundStyle = { backgroundColor: '#f8f9ff', flex: 1, }; export default EmptyExample; ``` </details>
## Summary This PR introduces support for boxShadow - a new feature from React Native 0.76+ NewArch. At the same time it address #6687 . * Adds parser for `boxShadow` prop, that transforms string into a `boxShadow` object. * Adds Jest tests * Fix colors flickering when run with `withSpring` Runtime test are added for future fabric support in RuntimeTests. Fixes #6687 https://github.com/user-attachments/assets/9051d98f-cfb0-41b0-a2b4-6a8c11b477da ## Test plan To test, paste this code snippet to `EmptyExample` and run. <details> <summary>EmptyExample code</summary> ```js import React from 'react'; import { Pressable, SafeAreaView, ScrollView, Text, View } from 'react-native'; import Animated, { Easing, interpolate, interpolateColor, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated'; import processBoxShadow from 'react-native-reanimated/src/processBoxShadow'; const AnimatedPressable = Animated.createAnimatedComponent(Pressable); const BUTTON_TRANSITION_TIME = 500; const EmptyExample = () => { const pressed = useSharedValue<number>(0); const animatedBoxShadow = useAnimatedStyle(() => { const blurRadius = interpolate(pressed.value, [0, 1], [10, 0]); const color = interpolateColor( pressed.value, [0, 1], ['#57b495', '#31775d'] ); const boxShadow = `0px 4px ${blurRadius} 0px ${color}`; return { boxShadow, }; }); const backgroundColorStyle = useAnimatedStyle(() => { const backgroundColor = interpolateColor( pressed.value, [0, 1], ['#b1dfd0', '#57b495'] ); return { backgroundColor, }; }); const handlePressIn = () => { pressed.value = withTiming(1, { duration: BUTTON_TRANSITION_TIME, easing: Easing.out(Easing.ease), }); }; const handlePressOut = () => { pressed.value = withTiming(0, { duration: BUTTON_TRANSITION_TIME, easing: Easing.out(Easing.ease), }); }; return ( <SafeAreaView style={backgroundStyle}> <ScrollView style={backgroundStyle}> <View style={{ padding: 24, }}> <Text style={{ fontSize: 18, color: '#001a72', fontWeight: 'bold', textAlign: 'center', marginBottom: 16, }}> The background color animation will work and so will the shadow ✨ </Text> <Text style={{ fontSize: 14, color: '#001a72', marginBottom: 8, }}> BoxShadow is officially supported by Reanimated 💅 </Text> <AnimatedPressable style={[ backgroundColorStyle, animatedBoxShadow, { padding: 16, borderRadius: 100, marginVertical: 16, }, ]} onPressIn={handlePressIn} onPressOut={handlePressOut}> <Text style={{ color: '#001a72' }}> Hello I am button with shadow </Text> </AnimatedPressable> </View> </ScrollView> </SafeAreaView> ); }; const backgroundStyle = { backgroundColor: '#f8f9ff', flex: 1, }; export default EmptyExample; ``` </details>
This PR introduces support for boxShadow - a new feature from React Native 0.76+ NewArch. At the same time it address #6687 . * Adds parser for `boxShadow` prop, that transforms string into a `boxShadow` object. * Adds Jest tests * Fix colors flickering when run with `withSpring` Runtime test are added for future fabric support in RuntimeTests. Fixes #6687 https://github.com/user-attachments/assets/9051d98f-cfb0-41b0-a2b4-6a8c11b477da To test, paste this code snippet to `EmptyExample` and run. <details> <summary>EmptyExample code</summary> ```js import React from 'react'; import { Pressable, SafeAreaView, ScrollView, Text, View } from 'react-native'; import Animated, { Easing, interpolate, interpolateColor, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated'; import processBoxShadow from 'react-native-reanimated/src/processBoxShadow'; const AnimatedPressable = Animated.createAnimatedComponent(Pressable); const BUTTON_TRANSITION_TIME = 500; const EmptyExample = () => { const pressed = useSharedValue<number>(0); const animatedBoxShadow = useAnimatedStyle(() => { const blurRadius = interpolate(pressed.value, [0, 1], [10, 0]); const color = interpolateColor( pressed.value, [0, 1], ['#57b495', '#31775d'] ); const boxShadow = `0px 4px ${blurRadius} 0px ${color}`; return { boxShadow, }; }); const backgroundColorStyle = useAnimatedStyle(() => { const backgroundColor = interpolateColor( pressed.value, [0, 1], ['#b1dfd0', '#57b495'] ); return { backgroundColor, }; }); const handlePressIn = () => { pressed.value = withTiming(1, { duration: BUTTON_TRANSITION_TIME, easing: Easing.out(Easing.ease), }); }; const handlePressOut = () => { pressed.value = withTiming(0, { duration: BUTTON_TRANSITION_TIME, easing: Easing.out(Easing.ease), }); }; return ( <SafeAreaView style={backgroundStyle}> <ScrollView style={backgroundStyle}> <View style={{ padding: 24, }}> <Text style={{ fontSize: 18, color: '#001a72', fontWeight: 'bold', textAlign: 'center', marginBottom: 16, }}> The background color animation will work and so will the shadow ✨ </Text> <Text style={{ fontSize: 14, color: '#001a72', marginBottom: 8, }}> BoxShadow is officially supported by Reanimated 💅 </Text> <AnimatedPressable style={[ backgroundColorStyle, animatedBoxShadow, { padding: 16, borderRadius: 100, marginVertical: 16, }, ]} onPressIn={handlePressIn} onPressOut={handlePressOut}> <Text style={{ color: '#001a72' }}> Hello I am button with shadow </Text> </AnimatedPressable> </View> </ScrollView> </SafeAreaView> ); }; const backgroundStyle = { backgroundColor: '#f8f9ff', flex: 1, }; export default EmptyExample; ``` </details>
Summary
This PR introduces support for boxShadow - a new feature from React Native 0.76+ NewArch. At the same time it address #6687 .
boxShadow
prop, that transforms string into aboxShadow
object.withSpring
Runtime test are added for future fabric support in RuntimeTests.
Fixes #6687
Screen.Recording.2024-11-22.at.16.23.44.mov
Test plan
To test, paste this code snippet to
EmptyExample
and run.EmptyExample code