-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
v3 - nativewind@next #308
Comments
This is a preview release - so don't be surprised if there are some stray bugs. I hope to use your feedback in stabilizing for a stable release. Docs will be available at https://next.nativewind.dev/, but are currently out of date. I will be hiding comments of resolved issues so I can keep track of incoming comments. Known issues
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@marklawlor Thank you for the library. I am trying to use it with vite bundler and everything works except manually toggling dark mode on the web gives this error "color-scheme.js:38 Cannot manually control color scheme. Please set "darkMode: 'class'" in your 'tailwind.config.js'" |
|
Same issue as @esinanturan |
Hey, Having issues with building an expo app with native wind. It causes the builds on EAS to timeout and never complete when using V3. |
Check here (#363) for workaround solution |
@marklawlor Are you need help with maintaining? I want to help you with this lib |
@marklawlor Im working on a lib that took so much learn from your utils but with a different approach, putting tailwindcss compiler in the runtime (real fast) to avoid problems with module transforms, if you want to discuss a collaboration between libs I will be happy to give you some feedback. |
Also putting in a comment for maintenance. I'm the author of https://tw-classed.vercel.app/ . I was initially thinking of creating a If you are in need of maintainers let me know, I'm happy to help! |
Do we have an update? |
It seems like the project is abandoned, so sad. I've moved over to tamagui... |
He's doing major work on expo-router to make it compatible with nativewind. |
@atanaskanchev I do not blame you to think that here is the real reason: |
Hi everyone. As explained in #464, development is now moving to a new project within the Expo organisation. While this project may be put on hold - the vision for Tailwind in React Native is stronger than ever. More updates coming soon. |
How can i make it work as UI package in turborepo, and i've tried, adding app/tailwind.config.js
i've even added nativewind to the UI package,
No matter what i've done, the tailwind isn't picking up any styling from my UI package at all |
Every time when you changing tailwind config you need to do |
it's still not working for some reason, it's only the UI package that isn't working. Do u have an example guide that i can follow? |
A small tip I found digging in source code
P.S. UPDATE: read my comment below to fix issue with variables object and colors in your tailwind config I was able to support multiple themes using this approach, works like a charm for both Web and Native @nareshbhatia you probably had the same issue. |
Even with this setup, I'm still getting the error on native (not web), is there anything else to this? Or do you have a public repo I can check out, that would be very helpful. Spent 2 hours trying to make this work, trying all sorts of combinations 😄 Here is the Tailwind config: Here is the CSS file: |
@yekta Try to JSON.stringify each color in variables object I found it later because I wasn't using the variables property, but it works |
That did it, thanks a lot. |
NativeWind 3.0 is a major update for NativeWind that fixes a large variety of issues. For most users the upgrade will be simple and should only require a small configuration change.
Breaking Changes
Web exclusively uses CSS styles
NativeWind on web now only works with CSS styling. The minimum version of React Native Web is now v0.18.
Project setup
Native apps now require a Metro plugin
Babel now uses a preset instead of a plugin
Tailwind now requires a preset instead of a plugin
Base scaling has changed
NativeWind now supports the
rem
unit. This is a breaking change as it will affect allrem
based styles.Previously, NativeWind 1-1 matched the scaling of TailwindCSS documentation and overrode the
rem
values with theirpx
equivalent. (example scaling)This was undesirable, as components styled with NativeWind were different to the base component. For example, NativeWind's text was slightly larger than the default.
Now that NativeWind supports
rem
, we can use anrem
value of 14 to match the default<Text />
.The result of this is your app may "shrink", as everything scales down from the previous static 16px to the new 14.
You can restore the old behaviour by setting
NativeWindStyleSheet.setVariables({ '--rem': 16 })
Dark mode
darkMode: 'class'
to enable manually controlling the color schemedarkMode: class
This aligns NativeWind's functionality with TailwindCSS handling of Dark Mode
styled() props options
The
classProps
option for styles has been removed. This has been merged intoprops
.The option
baseClassName
has been renamed toclassName
The
props
option still allows you to style non-style
props but is now more flexible. Like before it is an object that accepts the name of component props, and it's value configures how that prop is mapped.If the value is a Boolean, NativeWind will so transform that prop (but not rename it)
If the value is a String, NativeWind will transform and rename that prop. This is useful if you have a prop
innerStyle
but you'd like to expose it asinnerClassName
Lastly, it accepts an object with the option
name
renames the prop, same as simply providing a string.value
extracts the style value from the ste object. This is the same behaviour that NativeWind used to do if you provide a string.class
a Boolean that indicates that this prop should only be transformed on native. On web, it will be pre-pended to theclassName
string. This replaces the oldclassProps
option.Web className merging
Styles on native and web behaves slightly differently. Native styles are merged together with later classNames overriding earlier ones. However on the web classNames are prioritized based upon their CSS specificity and not the supplied order.
Normally this isn't an issue and can be easily overcome with the important modifier, however for larger apps you may want a more permanent solution. NativeWind exposes
NativeWindStyleSheet.setWebClassNameMergeStrategy
which you can use with libraries like tailwind-merge to make web behave more like the predictable native styles.Theme functions
Theme functions like
hairlineWidth
andplatformSelect
are now exported fromnativewind/theme
. You will need to update your imports.group
andparent
group-isolate
has been replaced with nested groups. This feature requires TailwindCSS 3.2The parent variant has been removed and should be replaced with nested groups. The
parent
class still exists, but is only used for new variants likeodd:
/even:
Removed features
aspect
with ratio values has been removed. Has been added to React Native . If you require this feature and cannot upgrade you can define your aspect ratios in your theme.NativeWindStyleSheet.setOutput()
has been removedNew Features
Variant support
styled()
has been updated to include variant support allowing for more complex and flexible components.The function signature for styled is
variants
The
variants
option is an schema for what classNames to apply when a prop matches the value.compoundVariants
defaultProps
Additional usage
Variants are not only limited to
styled()
, you can write the variant logic inlineVariant autocomplete
If you're using the "Tailwind CSS IntelliSense" Visual Studio Code extension, you can enable autocompletion by adding the following to your
settings.json
::root
CSS VariablesOne of the downsides of precompiled styles is static theming and being unable to change values at runtime. NativeWind now allows you to assign a CSS variable as a theme value. These values can be change at runtime using the
NativeWindStyleSheet.setVariables
function.A common pattern is changing CSS variables with the colorScheme, so NativeWind also support
.dark
as a special selector. It assumes that.dark
is being used in a global manner (eg on ). When Dark Mode is active, the:root
and.dark
variables will be merged together.CSS variables support being nested inside CSS functions
rgba(255, 255, 255, var(--opacity, 1))
.Setting via theme
Setting during runtime
Setting via plugins
Setting via CSS
Web SSR
On the web,
NativeWindStyleSheet.setVariables()
will add variables to the root element, which will cause hydration errors. You can use<Html lang="en" style={NativeWindStyleSheet.getSSRStyles()}>
Limitations
NativeWind only implements a subset of the CSS variable specification. The main two differences are
:root
or.dark
--background: white url(...)
useUnsafeVariable()
NativeWind exposes a new
useUnsafeVariable
hook which allows your components to react to variable updates.useUnsafeVariable
is unsafe because it behaves slightly differently between platforms, especially with units. For example10vw
on native will return a number that is the calculated value of10vw
while on web it returns the string"10vw"
.For consistent behaviour across platforms, it is recommend you only use this hook for
string
variables such as colors.useUnsafeVariable
also allows you to set the variable, similar touseState
rem
UnitsMany developers use
rem
units to ensure consistent scaling across their application. NativeWind now mimics this behaviour using the CSS variable--rem
, which defaults to14
. Developers can change their either by adding afont-size
to:root
or by callingNativeWindStyleSheet.setVariable({ --rem: <value > })
Inline theme functions
Theme functions like
platformSelect
previously could only be used with other theme functions. Now they can be used inline with other CSS functionsvar(--error-color, ${platformColor({ ios: "systemRed", default: "red" }))
RTL Support
The
rtl
andltr
variants are now supported. Developers can change this value viaNativeWindStyleSheet.setDirection()
orNativeWindStyleSheet.toggleDirection()
Odd/Even/First/Last
The
odd/even/first/last
variants are now supported for styling children.Bug Fixes & Improvements
Experimental CSS support
You can now optionally include a single
.css
import at your App entrypoint which NativeWind will use as the input for your Tailwind styles. This file needs to contain the TailwindCSS atRules and can also contain additional CSS rules.Custom CSS is a highly experimental feature that allows developers to write custom CSS classes and use features like
@apply
without learning Tailwind's plugin system.The text was updated successfully, but these errors were encountered: