github jpudysz/react-native-unistyles v3.8.2
Release v3.8.2

one hour ago

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, AppThemeName and AppBreakpoint are now exported from react-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 in UnistylesThemes and UnistylesBreakpoints. 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 at 10. Views that were already mounted updated correctly, and StyleSheet.create((theme, rt) => ...) wasn't affected (#1383, closes #1378)
  • Inline styles now keep overriding StyleSheet values after a view is linked again. Before, a Pressable whose style depends on pressed got the StyleSheet's value back on press after a theme change, e.g. paddingHorizontal: 20 over an inline 12. Below a ScopedTheme this 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.top no 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 with paddingTop: rt.insets.top pushed the content off-screen. The top inset now comes from the root window insets, the same source react-native-safe-area-context uses (#1375, closes #1374)

🧪 Internal

  • react-native-nitro-modules and nitrogen updated to 0.37.2. The generated specs only changed in comments and in HybridNativePlatformSpec_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

Don't miss a new react-native-unistyles release

NewReleases is sending notifications on new releases.