-
-
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
[3.16.1] NativeWind classes not being applied on Animated.View #6665
Comments
I have no investigated this yet. But incase this is a reanimated issue, NativeWind on web works by passing a StyleQ precompiled styled object to the
|
Hey y'all, after checking 3.12, 3.14, and 3.15.5, I found that the change appeared in |
This issue is caused by how NativeWind relies on a
I'm not actually sure why this is happeneding, as the A work around is to simply not use |
@marklawlor Thank you for checking this out and sharing that alternative. That is useful in many situations, but there's some situations where we needed lower level control to do something more precisely. These are instances where tailwind isn't driving the animation, we're just adding additional tailwind classes and the javascript calculations are driving the animation (e.g. moving a box around in absolute space, relying on screen measurements, but also needs some tailwind classes, like flex, typography, or a background color, applied to an element; classes unrelated to that animation). What we're trying for now in those places is we're implementing the first workaround where you're using the object to set style (with a ts-ignore). In this situation the class is applied correctly to the animated view, instead of using the more convenient classname property. In situations where it looks like the animation view can be swapped for a view and transpiled to a view, we're doing that too. Thanks again for your OSS work, both of y'all, and all your help. |
Another workaround is to use
|
Thanks! That works great. Here's my full cross-platform component in typescript. animated-view.web.tsx import Animated from 'react-native-reanimated';
import type { ViewProps } from 'react-native';
import type { AnimatedProps } from 'react-native-reanimated';
import { cssInterop } from 'nativewind';
import { cn } from '~/lib/utils';
const InteropAnimatedView = cssInterop(Animated.View, { className: 'style' });
export const AnimatedView = ({ className, ...animatedViewProps }: AnimatedProps<ViewProps>) => {
return <InteropAnimatedView {...animatedViewProps} className={cn(className)} />;
}; animated-view.tsx import Animated from 'react-native-reanimated';
export const AnimatedView = Animated.View; utils.tsx import type { ClassValue } from 'clsx';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
} implementation.tsx import Animated, { useAnimatedStyle } from 'react-native-reanimated';
import { AnimatedView } from '~/components/ui/animated-view';
const viewStyle = useAnimatedStyle(() => {
/// interpolate here
})
<AnimatedView style={viewStyle} className="flex items-center justify-center">
<View/>
</AnimatedView> 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. |
cssInterop returns a new component. Calling it during render will always cause a remount of that component (as your rendering something different everytime) |
I wanted to provide a quick update here, firstly import Animated from 'react-native-reanimated';
import type { ViewProps } from 'react-native';
import type { AnimatedProps } from 'react-native-reanimated';
import { cssInterop } from 'nativewind';
import { cn } from '~/lib/utils';
//move to here
const InteropAnimatedView = cssInterop(Animated.View, { className: 'style' });
export const AnimatedView = ({ className, ...animatedViewProps }: AnimatedProps<ViewProps>) => {
//const InteropAnimatedView = cssInterop(Animated.View, { className: 'style' });
return <InteropAnimatedView {...animatedViewProps} className={cn(className)} />;
}; 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 import Animated from 'react-native-reanimated';
export const AnimatedView = Animated.View; 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. |
This issue is an upstream bug with I've the issue isn't addressed soon then I'll probably adjust the |
I'm having the same problem, I was using Moti (which uses Reanimated under the hood) and classNames were working fine. For now I've been using just plain I don't fully understand from the conversation if we'll be able to just use classNames on the animated View directly or if creating a custom cssInterop wrapper is the way to go moving forward? |
@marklawlor @amandaharlin Thanks for troubleshooting this! |
Is there a workaround that we can apply meanwhile? I have a big codebase with many animated views and would be a pain to change all those views to use a style object until this is fixed. @marklawlor would patching the |
@marklawlor I submitted a pull request in |
<!-- Please provide enough information so that others can review your pull request. --> <!-- Keep pull requests small and focused on a single change. --> ### Summary In 0595213 the JSX runtime was changed to `automatic` without the option for the user to opt back in for `classic`. The `classic` runtime is needed for NativeWind library, which is dependent on Reanimated. Fixes - software-mansion/react-native-reanimated#6665 - #678 ### Test plan 🚀 --------- Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
@tjzel I believe you have misunderstood this issue NativeWind prefers the JSX runtime to be set to automatic. When the runtime is automatic additional JSX configuration options are available. The TypeScript
You can see here during the NativeWind installation that we require the Looking at your PR, the actual fix needs to
Interestingly, this PR will fix people's problems as NativeWind does also support |
@marklawlor You are right, I got confused when you were talking about TypeScript's I don't think disabling |
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Fixes #6665 Applying the change I made to `react-native-builder-bob`: - callstack/react-native-builder-bob#695 It restores `classic` runtime for the `@babel/react-native` preset used for generating ESModule code. The behavior was changed when we bumped builder-bob: - #6485 ## Test plan I ran the `diff` for the version of `lib` without `jsxRuntime: classic` and with it - the differences are only in regards to `_jsx` usage. You can read more here: - #6665
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> Fixes #6665 Applying the change I made to `react-native-builder-bob`: - callstack/react-native-builder-bob#695 It restores `classic` runtime for the `@babel/react-native` preset used for generating ESModule code. The behavior was changed when we bumped builder-bob: - #6485 I ran the `diff` for the version of `lib` without `jsxRuntime: classic` and with it - the differences are only in regards to `_jsx` usage. You can read more here: - #6665
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> Fixes #6665 Applying the change I made to `react-native-builder-bob`: - callstack/react-native-builder-bob#695 It restores `classic` runtime for the `@babel/react-native` preset used for generating ESModule code. The behavior was changed when we bumped builder-bob: - #6485 I ran the `diff` for the version of `lib` without `jsxRuntime: classic` and with it - the differences are only in regards to `_jsx` usage. You can read more here: - #6665
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Fixes #6665 Applying the change I made to `react-native-builder-bob`: - callstack/react-native-builder-bob#695 It restores `classic` runtime for the `@babel/react-native` preset used for generating ESModule code. The behavior was changed when we bumped builder-bob: - #6485 ## Test plan I ran the `diff` for the version of `lib` without `jsxRuntime: classic` and with it - the differences are only in regards to `_jsx` usage. You can read more here: - #6665
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Fixes #6665 Applying the change I made to `react-native-builder-bob`: - callstack/react-native-builder-bob#695 It restores `classic` runtime for the `@babel/react-native` preset used for generating ESModule code. The behavior was changed when we bumped builder-bob: - #6485 ## Test plan I ran the `diff` for the version of `lib` without `jsxRuntime: classic` and with it - the differences are only in regards to `_jsx` usage. You can read more here: - #6665
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Fixes #6665 Applying the change I made to `react-native-builder-bob`: - callstack/react-native-builder-bob#695 It restores `classic` runtime for the `@babel/react-native` preset used for generating ESModule code. The behavior was changed when we bumped builder-bob: - #6485 ## Test plan I ran the `diff` for the version of `lib` without `jsxRuntime: classic` and with it - the differences are only in regards to `_jsx` usage. You can read more here: - #6665
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.
52.0.0-preview.18
52.0.0-preview.18
3.10.1
3.16.1
4.1.21
4.1.21
Steps to reproduce
npx create-expo-stack@latest --nativewind
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
The text was updated successfully, but these errors were encountered: