react-native-reanimated: [3.16.1] NativeWind classes not being applied on Animated.View
Description
React-Native-Reanimated (at 3.10.1) was working with NativeWind to correctly apply classes to an Animated.View.
After upgrading Reanimated to 3.16.1 NW classnames were no longer getting applied to an Animated.View.
I opened a ticket with NativeWind too, so both teams could be notified.
| Working Project Details | Not-Working Project Details |
|---|---|
Expo 52.0.0-preview.18 |
Expo 52.0.0-preview.18 |
React NativeReanimated 3.10.1 |
React NativeReanimated at 3.16.1 |
NativeWind at 4.1.21 |
NativeWind at 4.1.21 |
| rnreanimated 3.10.1 | rnreanimated 3.16.1 |
|---|---|
Steps to reproduce
- Create a repo with
npx create-expo-stack@latest --nativewind - Upgrade Reanimated from 3.10.1 to 3.16.1
- Add classNames to an animated view. (Should work, but does not)
- Downgrade Reanimated to 3.10.1. (Works as expected)
Snack or a link to a repository
https://github.com/amandaharlin/react-native-reanimated-nativewind-classname-repro
Reanimated version
3.16.1
React Native version
0.76.1
Platforms
Web
JavaScript runtime
None
Workflow
Expo Go
Architecture
None
Build type
Debug app & dev bundle
Device
None
Device model
No response
Acknowledgements
Yes
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 29 (6 by maintainers)
Commits related to this issue
- feat: allow to specify JSX Runtime for @babel/preset-react` (#695) <!-- Please provide enough information so that others can review your pull request. --> <!-- Keep pull requests small and focused on... — committed to callstack/react-native-builder-bob by tjzel 2 years ago
- fix: restore `classic` runtime for @babel/preset-react (#6760) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so t... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: restore `classic` runtime for @babel/preset-react (#6760) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so t... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: restore `classic` runtime for @babel/preset-react (#6760) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so t... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: restore `classic` runtime for @babel/preset-react (#6760) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so t... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: restore `classic` runtime for @babel/preset-react (#6760) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so t... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- fix: restore `classic` runtime for @babel/preset-react (#6760) <!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so t... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- chore: patch bob to preserve jsx (#7266) ## Summary Fixes #6665. Read the issue for more context. `react-native-builder-bob` applies `@babel/preset-react` on the emitted code, effectively ignoring ... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- chore: patch bob to preserve jsx (#7266) Fixes #6665. Read the issue for more context. `react-native-builder-bob` applies `@babel/preset-react` on the emitted code, effectively ignoring our TSConfig... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- chore: patch bob to preserve jsx (#7266) Fixes #6665. Read the issue for more context. `react-native-builder-bob` applies `@babel/preset-react` on the emitted code, effectively ignoring our TSConfig... — committed to software-mansion/react-native-reanimated by tjzel 2 years ago
- upgrade react-native-reanimated to fix bugs resolves an incomatibility with nativewind (https://github.com/software-mansion/react-native-reanimated/issues/6665) when combining `className` with `style... — committed to pinyinlylabs/pinyinly by bradleyayers 2 years ago
This issue is an upstream bug with
react-native-builder-bobhttps://github.com/callstack/react-native-builder-bob/issues/678I’ve the issue isn’t addressed soon then I’ll probably adjust the
nativewindbabel plugin to work around itAnother workaround is to use
@marklawlor I submitted a pull request in
react-native-builder-bobto address this issue. We’ll release3.16.3with these changes. However, you should somehow migrate from relying onclassicjsx runtime asautomaticis going to be the default soon.@marklawlor @amandaharlin Thanks for troubleshooting this!
I wanted to provide a quick update here, firstly
this works just fine after testing, and should avoid the performance pitfall you mention, so I’ve updated my code snippet
That said, i’ve not yet updated my reproduction repo, but the mobile behavior has actually degraded more from the time I posted this issue. I had been using
and this was working beforehand on the mobile platforms. Now, when I use that code or if I use the css Interop approach for mobile, neither one is working. While trying to zero in on “what changed”, I can see that I haven’t changed nativewind or react-native-reanimated but expo did update. I can’t see immediately how that could cause this issue, so I am still investigating. That said, last week iOS and Android were working (and only web needed to be shimmed), now mobile doesn’t work at all, but the fix upthread for web does still work great for web builds, and seems to have no effect on mobile.
To get around this I’ve fallen back to just specifying css properties with the standard JSON syntax on the style prop for now.
Yes, this will definitely land in Reanimated 4.
@kaumac @Babettestam I totally forgot what the issue was originally about and how it was resolved (or rather not resolved).
I have created a version of Reanimated 3.17.1 that should address the underlying problem, could you try it and see if it works in your setup?
react-native-reanimated-3.17.1-jsx.tgz
Can somebody reopen the issue, since the problem is not solved?
cssInterop returns a new component. Calling it during render will always cause a remount of that component (as your rendering something different everytime)
Thanks! That works great. Here’s my full cross-platform component in typescript.
animated-view.web.tsx
animated-view.tsx
utils.tsx
implementation.tsx
I’m using this with expo. It was working correctly on iOS and Android, this code snippet implements the change for the web build. With the .web switch, this puts them at feature parity.
Would you like for this to be the official way to use RNReanimated and NW? I can make a PR to the NW docs, which would close this issue.
This issue is caused by how
react-native-reanimatedbuilds in3.1.16.NativeWind relies on a
jsxtransform (turning<View> -> jsx(View), where it needs to use thejsxfunction from NativeWind.3.1.16is being published to NPM with thejsxfunction being hardcoded toreact/jsx-runtime. This also means thatreact-native-reanimatedwill not work with libraries like@emotion/nativewhich relies on the jsx transform.I’m not actually sure why this is happeneding, as the
tsconfig.json#jsxis correctly set toreact-native, which should preserve the JSX.A work around is to simply not use
Animated.View. You can just use aViewand add an animation class to it likeanimate-none, and NativeWind will turn yourViewinto anAnimated.View