Skip to content

Latest commit

 

History

History
130 lines (110 loc) · 6.91 KB

no-nativewind.mdx

File metadata and controls

130 lines (110 loc) · 6.91 KB
title Bloom without NativeWind
description The decision and plan that take NativeWind, react-native-css and Tailwind out of Bloom, with the look unchanged.

Bloom without NativeWind

Status: shipped in Bloom 23.0.0.

Decision

Bloom styles through one mechanism: React Native styles. Bloom has no className, no NativeWind, no react-native-css and no Tailwind, in its source, its dependencies, its peers or its docs. Nothing it draws changes.

Why: the Bloom language draws Bloom's real components, so a language app pays for whatever those components need. react-native-css wraps every View and Text an app bundles; on the Pixel that wrapper costs about 890 ms of cold start. Apps drop NativeWind through the className codemod (bloom-language-classnames.mdx); Bloom has to drop it first.

What it was

  • About 585 className attributes in 57 families, on Styled* primitives (styled() from react-native-css) and on Bloom components, plus 169 className-style props (className, contentClassName, labelClassName, …) that forward a consumer's classes.
  • The theme's native variable plumbing: VariableContextProvider from the optional nativewind peer in BloomThemeProvider, BloomColorScope, BloomSeedScope, ThemeScopeBridge and ConcentricProvider; react-native-css's rootVariables (native-root-vars); vars() (useColorScopeStyle); useNativeVariable (concentric class markers); the css-interop dark-mode flag (init-css-interop).
  • Tailwind configuration: design-tokens/theme.css (generated by theme-css.ts, with the concentric @utility publishers), the ./tailwind-preset and ./design-tokens/theme.css exports, the --color-* aliases every scope writes, Storybook's Tailwind pipeline.
  • Package entries: nativewind and react-native-css peers, nativewind, react-native-css, tailwindcss, @tailwindcss/vite dev dependencies, the lightningcss pins, the bloom-language react-native-css peer and its styled() hover-group hosts.

The mechanism

A component's styles are StyleSheet.create objects of numbers from Bloom's tokens. Colour comes from useColorTokens() (theme/color-tokens.ts):

  • Native: the nearest scope's token record (the provider's, a colour scope's, a seed scope's, or the one a portal bridge carries), so a colour is exactly the value the class read. In mode="adaptive" the record holds the platform's dynamic colours, as useTheme().colors does: the provider builds both from one palette (Theme, Which reader).
  • Web: the token's CSS variable (var(--primary)), which the theme writes on the document and a colour scope on its element, as the classes read it. A theme switch re-renders nothing on the web; the server's first paint is the same.

createTokenStyles((t) => ({ … })) builds a component's styles once per palette (once on the web) as a StyleSheet, so a style keeps its identity while the theme does: a theme switch re-renders the leaves that read the tokens, nothing else. tokenAlpha(t.primary, 0.5) is a /50 opacity modifier.

The rest, by what the class did:

  • Responsive variants (sm:, max-sm:, md:) read useWindowBreakpoint().
  • dark: reads the theme's mode; rtl: reads useIsRtl().
  • active: is a pressable's pressed state; hover:, focus-visible: and group-hover: are the web's: the existing dataSet hook and adopted stylesheet (styles/interactive-web-css.ts), or SubtleHover.
  • web: utilities and web-only properties (cursor, userSelect, transition*, outline*) are a web style entry.
  • A raw DOM element's own className (bloom-meter-fill, a .web.tsx fork's <button>) is not NativeWind and stays.

Values are taken from what renders today, not from reading Tailwind: the class resolver runs a class string through Tailwind v4 over Bloom's tokens and react-native-css's native runtime, and gives the Android style, the colour token each colour is, and the web CSS. A Bloom component under a class can override what the class set (a Text's own size wins), so the parity harness is the authority.

Proof

  • Native: scripts/no-nativewind/run.sh <baseline> <out> [family,…] renders each family's cases (scripts/no-nativewind/cases/<family>.cases.tsx) on Android under Bloom's provider, light, dark and adaptive (over the mocked dynamic palette __mocks__/dynamic-palette.ts), in a baseline checkout styled by react-native-css's real runtime over the Tailwind an app compiles, and in this branch, and requires identical committed host trees.
  • Web: scripts/no-nativewind/verify-web.mjs compares every story of a family in Chrome between the baseline Storybook (Tailwind, as an app ships it, preflight aside) and this branch's (no Tailwind): every element's computed style and size, light and dark, at rest, hovered and pressed.
  • Each family's Jest suite stays green; suites that asserted className plumbing are deleted with it.

Public changes

  • Removed props: every className and *ClassName prop. A consumer passes style (or the language's modifiers); the codemod rewrites app call sites.
  • Removed exports: useColorScopeStyle, initCssInteropDarkMode.
  • Kept, for apps still using className (removed once the fleet has migrated): ./tailwind-preset and ./design-tokens/theme.css, generated from the same token scales and roles Bloom's styles read, and the scoped --color-* aliases a colour scope writes on the web. They are token outputs for an app's own Tailwind; Bloom has no NativeWind or Tailwind dependency. The concentric rounded-concentric utilities are gone: Bloom's concentric geometry comes from radius and style.
  • Added exports (@oxy.so/bloom/theme): useColorTokens, createTokenStyles, tokenAlpha, ColorToken, ColorTokens, ColorScopeLayerContext, ColorScopeLayer.
  • Peers removed: nativewind, react-native-css.
  • Apps no longer need NativeWind, react-native-css, Tailwind or @oxy.so/app-preset/base.css for Bloom. An app keeps them only for its own className, until the codemod moves it; theme.css and the preset keep its classes on Bloom's tokens meanwhile. On native, Bloom no longer publishes its tokens to react-native-css, so an app with classes left wraps its tree in app-preset's BloomNativeWindTheme once, inside BloomProvider: it publishes the theme's tokens and, through Bloom's generic ColorScopeLayerContext, each colour scope's tokens to NativeWind, so classes inside a scope follow it.

App side

@oxy.so/app-preset (oxy) makes NativeWind optional: an app without nativewind installed gets a Metro config with no NativeWind wrapper and no react-native-css redirects. The base-font substitution (Inter for a text that names no family) no longer rides on NativeWind's Text: it redirects react-native's own Text and TextInput to a host that puts the base face first, so only raw React Native text needs it; Bloom's and the language's text already name their family.