Spreading animated style into style prop removes all styles
See original GitHub issueDescription
Passing animated style via spread operator doesn’t work.
Expected behavior
animated style should be applied
Actual behavior & steps to reproduce
Style doesn’t take any effect and being ignored. Additionally all other style of the element is gone.
Snack or minimal code example
Given
const offset = useSharedValue(buffer);
const animatedStyles = useAnimatedStyle(() => ({
transform: [{ translateX: offset.value }],
}));
adding an animated style like this lets all the styles on the element disappear:
<Animated.View
style={{
width: 90,
height: 90,
backgroundColor: 'red',
...animatedStyles,
}}
/>
See this expo snack
Package versions
- React Native: 0.66.3
- React Native Reanimated: 2.3.0
- NodeJS: v12.22.7
- Xcode: 12.5.1
Affected platforms
Tested on iOS, but seems like a general issue to me.
- Android
- iOS
- Web
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Spreading animated style into style prop removes all styles ... - GitHub
Spreading animated style into style prop removes all styles Spreading animated style into style prop removes all styles. Check for reproduction #548 Check ......
Read more >javascript - Loosing component props when using 'as' styled ...
I had to spread all the props via {...props} on my CallToAction component (which is ... text={`I have my text and my styles...
Read more >FAQs - styled-components
Inline styles will always take precedence over external CSS, so you cannot override it by simply increasing specificity. There is a neat trick...
Read more >How To Use Styled-Components In React - Smashing Magazine
Elimination of dead styles Styled components remove unused styles, even if they're declared in your code. and many more.
Read more >React Project Tutorial with Advanced CSS Animations and ...
Go step-by-step in creating a fun, easy React project while you learn about using Styled Components, making emojis accessible, writing CSS ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It’s because
useAnimatedStylereturns a special object that’s not just style properties: https://github.com/software-mansion/react-native-reanimated/blob/main/src/reanimated2/hook/useAnimatedStyle.ts#L536 (which is then interpreted in createAnimatedComponent)Resolved, closing.