question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spreading animated style into style prop removes all styles

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brianreaviscommented, Dec 13, 2021

It’s because useAnimatedStyle returns 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)

0reactions
jakub-gonetcommented, Jan 28, 2022

Resolved, closing.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found