What's Changed
A patch release with no breaking changes. Theme StyleSheets now pick up breakpoint changes for views that mount later, and inline styles are no longer overridden after a press or below a ScopedTheme. On Android, rt.insets.top is correct in split-screen and windowed mode. Unistyles also exports the AppTheme, AppThemeName and AppBreakpoint types.
✨ New
AppTheme,AppThemeNameandAppBreakpointare now exported fromreact-native-unistyles. Before, you had to derive the theme type yourself, e.g.UnistylesThemes[keyof UnistylesThemes]. The types follow the themes and breakpoints you registered inUnistylesThemesandUnistylesBreakpoints. The configuration and theming guides show how to use them (#1382)
import type { AppTheme, AppThemeName, AppBreakpoint } from 'react-native-unistyles'
// AppTheme - the shape of your theme (union of all registered themes)
// AppThemeName - union of your theme names, e.g. 'light' | 'dark'
// AppBreakpoint - union of your breakpoint names, e.g. 'xs' | 'sm' | 'md'
const getBorder = (theme: AppTheme) => ({
borderWidth: 1,
borderColor: theme.colors.primary
})
const themeNames: Array<AppThemeName> = ['light', 'dark']🎨 Themes and styles
- A StyleSheet created with
StyleSheet.create(theme => ...)now refreshes when a runtime value it uses changes, not only when the theme changes. Before, a view that mounted after a rotation, fold or split-screen resize got the previous breakpoint's values, e.g.paddingLeft: { xs: 10, md: 40 }stayed at10. Views that were already mounted updated correctly, andStyleSheet.create((theme, rt) => ...)wasn't affected (#1383, closes #1378) - Inline styles now keep overriding StyleSheet values after a view is linked again. Before, a
Pressablewhose style depends onpressedgot the StyleSheet's value back on press after a theme change, e.g.paddingHorizontal: 20over an inline12. Below aScopedThemethis happened on the first render (#1377, closes #1376)
<Pressable
style={({ pressed }) => [
styles.button(pressed),
// ✅ 3.8.2: stays 12 after a theme change and a press
{ paddingHorizontal: 12 }
]}
/>🤖 Android
rt.insets.topno longer reports the window's position on screen when the window doesn't start at the top of the display, e.g. the bottom pane of split-screen, Samsung pop-up view or desktop windowing. In a bottom split-screen pane it returned about 460dp instead of 0, so a header withpaddingTop: rt.insets.toppushed the content off-screen. The top inset now comes from the root window insets, the same sourcereact-native-safe-area-contextuses (#1375, closes #1374)
🧪 Internal
react-native-nitro-modulesandnitrogenupdated to 0.37.2. The generated specs only changed in comments and inHybridNativePlatformSpec_cxx.swift, with the same behavior (#1372)- New e2e scenarios cover inline styles after a theme change and inside a
ScopedTheme, and a screen that mounts after the device rotates (#1377, #1383)
❤️ Contributors
Thanks to those whose reports shaped the fixes:
- @BasixKOR (#1374, #1378), who found and traced both the Android split-screen inset and the theme StyleSheet refresh issues
- @O-Q (#1376), who traced the lost inline styles to
link()and proposed the fix
Full Changelog: v3.8.1...v3.8.2