What's Changed
A minor release with no breaking changes. The Babel plugin is now deprecated and will be removed in Unistyles 4.0. Re.Pack, Rspack and Rsbuild get UnistylesPlugin, an experimental integration that works without the Babel plugin, like withUnistylesConfig does for Metro. Fixes cover views that keep the previous theme after a freeze, a concurrent render, or a React Compiler memo, Reanimated fades that end at the wrong opacity, and props a theme sets to undefined. On Android, rt.insets.top is correct with a hidden status bar below Android 11 and in desktop windows. Unistyles also builds against React Native nightlies again.
๐ฃ Deprecation: Babel plugin
- The Babel plugin (
react-native-unistyles/plugin) is deprecated and will be removed in Unistyles 4.0. It works the same as before in 3.x, so you don't have to change anything to upgrade to 3.9.0. Where your bundler has a replacement, you can switch now:
| Bundler | Replacement | Guide |
|---|---|---|
| Metro (Expo, bare RN) | withUnistylesConfig in metro.config.js
| Metro |
| Re.Pack, Rspack, Rsbuild | UnistylesPlugin in your Rspack config (new, see below)
| Re.Pack |
| Vite, Next.js and others | none yet, keep the Babel plugin in 3.x | Babel plugin |
- Both integrations replace the Babel plugin, they don't run next to it. Remove
react-native-unistyles/pluginfrombabel.config.js, Unistyles throws an error if both are set up styles.useVariants()no longer changesstyles, use the styles it returns. The codemod converts your components:
npx jscodeshift --parser=tsx --extensions=tsx,ts,jsx,js -t node_modules/react-native-unistyles/codemods/use-variants.js src- Jest needs no changes
RepackUnistylePluginandBASE_REPACK_EXCLUDE_PATHSfromreact-native-unistyles/repack-pluginare deprecated too and will be removed in 4.0.RepackUnistylePluginstill works and prints a warning. Replace it withUnistylesPlugin, or addreact-native-unistyles/pluginto yourbabel.config.js(see Usage with Re.Pack) (#1371)
โจ New
- Experimental Re.Pack, Rspack and Rsbuild integration.
UnistylesPluginruns the resolver of the Metro integration inside Rspack, so it swaps the same imports and StyleSheets record their dependencies while they run, without the Babel plugin. It takes no options (noroot,autoProcessImportsorautoProcessPaths) and requires@rspack/core1.7.5 or newer (#1371 by @whydidoo, docs)
// rspack.config.mjs
import * as Repack from '@callstack/repack'
import { UnistylesPlugin } from 'react-native-unistyles/repack-plugin'
export default {
// other config
plugins: [
new Repack.RepackPlugin(),
new UnistylesPlugin()
]
}- On the web, add it to
tools.rspackin Rsbuild, or topluginsof yourrspack.config.mjs, and resolvereact-nativeto React Native Web. The guide has full configs for both - The swap runs before Module Federation decides what is shared, so the host and every remote use one copy of the swapped components. Share
react-native,react-native-unistylesandreact-native-unistyles/in every container - Libraries in
node_modulesget the swap too. A second copy of Unistyles (e.g. nested in a library'snode_modules) prints a warning, because its styles won't update - Tested with Re.Pack's Rspack setup, not its webpack setup. Restart Re.Pack with
--reset-cacheafter switching
๐จ Themes and styles
- Views in a frozen subtree (react-freeze, React Navigation's
freezeOnBlur) now show the new theme when they come back, also when they don't re-render (React.memo, bailed-out list cells). Before, a theme change made while they were frozen was lost. Views whose styles didn't change are still restored without a commit (#1389, closes #1379) <ScopedTheme>no longer leaks its theme to views outside the scope when a concurrent render (startTransition, Suspense) yields inside it. Unistyles now reads each view's theme from its scope instead of a global value set during render (#1392, closes #1381)- A view faded with Reanimated no longer ends at a mid-animation opacity (e.g.
0.5) after a theme change and an unrelated React commit. After its own commits, Unistyles gave React's node the props Reanimated had applied during the animation. React's node now keeps its own props plus the Unistyles values (#1393, closes #1380) - A view that first mounts after a theme change from an element kept by the React Compiler (or a
useMemo) now shows the new theme. Before, it kept the style object made under the old theme. Each style now records the revision it was made at, and Unistyles commits the current values when a view mounts with an older one (#1394, closes #1386) - Props that a theme sets to
undefinedare now reset after a theme change. Before, the view kept the previous theme's value, e.g.backgroundColor: isLight ? 'red' : undefinedstayed red in the dark theme. Unistyles now sendsnull, like React does. Props the new style leaves out entirely aren't reset yet (#1395)
๐ค Android
- Below Android 11,
rt.insets.topis now0when the status bar is hidden throughWindowInsetsControllerCompat, e.g. React Native'sStatusBarwith edge-to-edge,SystemBarsfrom react-native-edge-to-edge or react-native-keyboard-controller. Before, it kept the status bar height (#1390, closes #1384) - In Android 15 desktop windowing,
rt.insets.topnow includes the caption bar the system draws over the top of the app. Before, it was0, so content was drawn under the caption bar. The top inset now takes the larger of the status bar and the caption bar (#1391, closes #1385)
๐ Web
- CSS rules are no longer deleted while elements that aren't attached to the document yet still use them, e.g. content in a portal whose container a map appends to its pane later. Before, the rule came back only on a later render of the style (#1398 by @erickreutz, closes #1397)
๐๏ธ React Native nightlies
- Unistyles builds against React Native nightlies again on iOS and Android. React Native changed
ShadowNodeFamily::nativeProps_DEPRECATEDto a struct (react/react-native#59624). Unistyles detects the type at compile time, so it builds against both released versions and nightlies (#1388 by @Abbondanzo)
๐งช Internal
- New e2e scenarios:
status-bar,safe-area(comparesrt.insetswith react-native-safe-area-context),undefined-reset, a Reanimated fade after a theme change, and elements kept across a theme change (#1390, #1391, #1393, #1394, #1395) - The e2e host runs on an Android API 29 emulator too, can launch a run in a desktop window (
--window desktop) and skip scenarios (--skip) (#1390, #1391)
โค๏ธ Contributors
Thanks to everyone who sent a PR for this release:
And to those whose reports shaped the fixes:
- @BasixKOR (#1379, #1380, #1381), who found and traced the frozen subtree, Reanimated opacity and
ScopedThemeissues - @YunPC (#1384, #1385), who reported both Android top inset issues
- @RaiN3772 (#1386), who reported the React Compiler issue and proposed a fix in #1387
- @erickreutz (#1397), who traced the deleted web rules and sent the fix
Full Changelog: v3.8.2...v3.9.0