From 0fd0de629365a12356393ebe09c84558a289c13d Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 11:35:01 +0900 Subject: [PATCH 1/5] wip(native): css() and className on React Native Co-Authored-By: Claude Opus 5.5 --- apps/expo/src/App.tsx | 12 +- libs/extractor/src/native/element.rs | 80 ++++-- libs/extractor/src/native/element/css_call.rs | 234 ++++++++++++++++++ libs/extractor/src/native/errors.rs | 18 +- libs/extractor/src/native/imports.rs | 18 +- .../extractor__native__tests__apis.snap | 3 +- .../extractor__native__tests__css_alone.snap | 8 + .../extractor__native__tests__css_calls.snap | 47 ++++ .../extractor__native__tests__css_errors.snap | 15 ++ .../extractor__native__tests__css_only.snap | 12 + ...actor__native__tests__css_runtime_off.snap | 5 + ...ractor__native__tests__web_only_props.snap | 2 +- libs/extractor/src/native/style.rs | 39 ++- libs/extractor/src/native/tests.rs | 91 ++++++- 14 files changed, 537 insertions(+), 47 deletions(-) create mode 100644 libs/extractor/src/native/element/css_call.rs create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__css_alone.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__css_calls.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__css_errors.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__css_only.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__css_runtime_off.snap diff --git a/apps/expo/src/App.tsx b/apps/expo/src/App.tsx index 624128e25..6d8174a5f 100644 --- a/apps/expo/src/App.tsx +++ b/apps/expo/src/App.tsx @@ -1,6 +1,7 @@ import { Box, Button, + css, Flex, Image, Input, @@ -12,6 +13,9 @@ import { useState } from 'react' import { Badge } from './Badge' +/** The shape both buttons share */ +const button = css({ borderRadius: '8px', px: 5, py: 3 }) + export function App() { const [name, setName] = useState('') const [count, setCount] = useState(0) @@ -69,10 +73,8 @@ export function App() { + ) +} +``` + +`css()` takes what it does on the web: objects of style props (with +responsive values, theme tokens and the theme, platform and orientation +blocks), conditions choosing between them, what another `css()` gives, and +CSS text (`` css`padding: 8px; background-color: $primary;` ``, each +interpolation a whole value). The element's style props apply after its +`className`, and its `style` prop last. + +A `css()` whose styles differ by theme, breakpoint or orientation reads the +runtime, so it must be called in a function component or a hook. One that does +not can be called anywhere, such as at the top of the file. These are build +errors: + +- a class name (`className="p-4"`, `css('p-4')`) +- a press style in `css()`: give `_active` to the element itself +- selectors, nesting and at-rules in CSS text + +`css()` gives a style rather than a class on React Native, so pass it to +`className`, not to the `style` of a React Native component, which TypeScript +types as a string. + ## Limits of this version Only styles the build can decide are supported: literals, values read at runtime, theme tokens, responsive values, conditions between them and the -platform, theme and orientation blocks. These are build errors, reported by -Metro at the file, line and column: +platform, theme, orientation and press blocks, and `css()`. These are build +errors, reported by Metro at the file, line and column: - interaction states other than `_active`/`_pressed` (`_hover`, `_focus`, ...) -- `css()`, `styled()`, `globalCss()`, `keyframes()` and `Grid` +- `styled()`, `globalCss()`, `keyframes()` and `Grid` - any prop React Native has no style for - with `runtime: false`, a value that differs by theme or breakpoint, `_theme*` with more than one theme, `_portrait`, `_landscape`, and From 4f8a95ad4edc7b9a191591e931e91509c64e5fd2 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 12:05:15 +0900 Subject: [PATCH 4/5] test(native): pass classes to style_code in the merged test Co-Authored-By: Claude Opus 5.5 --- libs/extractor/src/native/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/extractor/src/native/tests.rs b/libs/extractor/src/native/tests.rs index 1427470bd..766f40f9f 100644 --- a/libs/extractor/src/native/tests.rs +++ b/libs/extractor/src/native/tests.rs @@ -1270,7 +1270,7 @@ fn a_static_style_after_one_kept_in_order_checks_it() { Choice::Dynamic(vec![("width".to_string(), "w".to_string())]), Choice::Static(declarations(&[("padding", 1.0)])), ], - vec![], + (vec![], vec![]), &mut sheet, &VARS, ) From fb7882a62e9dff0a8ac6fa3db59b9dd8e04a09ab Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 12:22:26 +0900 Subject: [PATCH 5/5] test(native): cover css() parts around state blocks and empty objects Co-Authored-By: Claude Opus 5.5 --- libs/extractor/src/native/element/css_call.rs | 12 ++---------- .../extractor__native__tests__css_only.snap | 19 ++++++++++++++++++- libs/extractor/src/native/tests.rs | 3 ++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/libs/extractor/src/native/element/css_call.rs b/libs/extractor/src/native/element/css_call.rs index 7de6e8afb..b0ff3cdbd 100644 --- a/libs/extractor/src/native/element/css_call.rs +++ b/libs/extractor/src/native/element/css_call.rs @@ -244,16 +244,8 @@ impl<'a> Elements<'_> { let mark = self.replacements.len(); self.visit_expression(expression); let (start, end) = (span.start as usize, span.end as usize); - let mut inner = Vec::new(); - let mut index = mark; - while index < self.replacements.len() { - let (from, to, _) = self.replacements[index]; - if start <= from && to <= end { - inner.push(self.replacements.remove(index)); - } else { - index += 1; - } - } + // What visiting the expression changes lies in it + let mut inner = self.replacements.split_off(mark); inner.sort_by_key(|(from, to, _)| (*from, *to)); let mut code = String::new(); let mut at = start; diff --git a/libs/extractor/src/native/snapshots/extractor__native__tests__css_only.snap b/libs/extractor/src/native/snapshots/extractor__native__tests__css_only.snap index 0aea6f564..99100733a 100644 --- a/libs/extractor/src/native/snapshots/extractor__native__tests__css_only.snap +++ b/libs/extractor/src/native/snapshots/extractor__native__tests__css_only.snap @@ -3,12 +3,14 @@ source: libs/extractor/src/native/tests.rs expression: "compile_themed(two_themes(), runtime, code)" --- import { View as Box, Pressable as Button, View as Center, View as Flex, Image, TextInput as Input, Text, View as VStack } from "react-native"; +import { useLandscape as __useLandscape } from "@devup-ui/react/native"; import { StyleSheet } from "react-native"; const __s = StyleSheet.create({ a: { margin: 8 }, b: { padding: 4 }, c: { padding: 8 }, - d: { margin: 4 } + d: { margin: 4 }, + e: { padding: 12 } }); export const s = [__s.a, cond ? __s.b : __s.c]; export const t = [ @@ -17,3 +19,18 @@ export const t = [ on && __s.d, other.css({ p: 1 }) ]; +export const useU = () => { + const __l = __useLandscape(); + return [ + t, + __s.b, + __l && __s.d, + __s.a, + on ? null : [__s.c, __l && __s.e], + other`x` + ]; +}; +export const useV = () => { + const __l = __useLandscape(); + return [__s.c, __l && __s.d]; +}; diff --git a/libs/extractor/src/native/tests.rs b/libs/extractor/src/native/tests.rs index 766f40f9f..2e90e2681 100644 --- a/libs/extractor/src/native/tests.rs +++ b/libs/extractor/src/native/tests.rs @@ -1202,7 +1202,8 @@ export function Card({ on, extra, children }) { #[case::css_only( "css_only", true, - "import { css } from '@devup-ui/react'\nexport const s = css({ m: 2 }, cond ? { p: 1 } : { p: 2 })\nexport const t = css(true, on ? undefined : { p: 1 }, on ? { m: 1 } : false, (other.css({ p: 1 })))" + "import { css } from '@devup-ui/react'\nexport const s = css({ m: 2 }, cond ? { p: 1 } : { p: 2 })\nexport const t = css(true, on ? undefined : { p: 1 }, on ? { m: 1 } : false, (other.css({ p: 1 })))\nexport const useU = () => css(t, { p: 1 }, { _landscape: { m: 1 } }, { m: 2 }, on ? {} : { p: 2, _landscape: { p: 3 } }, other`x`) +export const useV = () => css({ _landscape: { m: 1 } }, { p: 2 })" )] #[case::text( "css_text",