From 6c2b6f2c67f18d5082c05993d1202b88a36740bf Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 11:16:53 +0900 Subject: [PATCH 1/4] feat(native): press styles through Pressable on React Native `_active` and its React Native name `_pressed` make the element a `Pressable` whose `style` is a function of whether it is pressed: `({ pressed }) => [styles.a, pressed && styles.b]`. A `Box`, `Flex`, `Center` or `VStack` with a press style becomes a `Pressable`; a `Button` already is one. Press styles combine with responsive values, themes, platforms, orientations and conditions, and need no runtime, so they work with `runtime: false` too. On a `Text`, an `Image` or an `Input`, and with `as`, they are build errors. Co-Authored-By: Claude Opus 5.5 --- .../changepack_log_react_native_pressed.json | 8 ++ .github/workflows/publish.yml | 1 + apps/expo/check-bundle.mjs | 10 +- apps/expo/src/App.tsx | 2 + libs/extractor/src/native/element.rs | 127 +++++++++++++----- libs/extractor/src/native/errors.rs | 26 ++-- libs/extractor/src/native/mod.rs | 5 +- ...actor__native__tests__platform_shapes.snap | 1 - .../extractor__native__tests__pressed.snap | 6 - ...ractor__native__tests__pressed_errors.snap | 9 ++ ...ative__tests__pressed_name_collisions.snap | 10 ++ ...r__native__tests__pressed_runtime_off.snap | 17 +++ ...ractor__native__tests__pressed_styles.snap | 47 +++++++ ...tractor__native__tests__runtime_false.snap | 1 - ...xtractor__native__tests__runtime_true.snap | 1 - libs/extractor/src/native/style.rs | 19 +++ libs/extractor/src/native/tests.rs | 57 +++++--- packages/metro-plugin/README.md | 22 ++- 18 files changed, 285 insertions(+), 84 deletions(-) create mode 100644 .changepacks/changepack_log_react_native_pressed.json delete mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__pressed.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__pressed_errors.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__pressed_name_collisions.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__pressed_runtime_off.snap create mode 100644 libs/extractor/src/native/snapshots/extractor__native__tests__pressed_styles.snap diff --git a/.changepacks/changepack_log_react_native_pressed.json b/.changepacks/changepack_log_react_native_pressed.json new file mode 100644 index 000000000..9ed03be7e --- /dev/null +++ b/.changepacks/changepack_log_react_native_pressed.json @@ -0,0 +1,8 @@ +{ + "changes": { + "bindings/devup-ui-binding/package.json": "Patch", + "bindings/devup-ui-wasm/package.json": "Patch" + }, + "note": "`codeExtractNative` compiles press styles for React Native (part of #411): `_active` and its React Native name `_pressed` make the element a `Pressable` (a `Box`, `Flex`, `Center` or `VStack` becomes one, a `Button` already is) whose `style` is a function of whether it is pressed, `({ pressed }) => [styles.a, pressed && styles.b]`. Press styles combine with responsive values, themes, platforms, orientations and conditions, and work with `runtime: false` as they need no runtime. They are build errors on a `Text`, an `Image` or an `Input`, and with `as`. Web output is unchanged.", + "date": "2026-11-21T00:00:00.000Z" +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1696a4342..2bf0a8564 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,6 +10,7 @@ on: - feat/napi-binding - feat/react-native-metro - feat/react-native-themes + - feat/react-native-responsive # Pull requests and every job below run read-only. Only the `release` and # `deploy-pages` jobs get write permissions, and they run on pushes to main diff --git a/apps/expo/check-bundle.mjs b/apps/expo/check-bundle.mjs index 445677c7b..a7168e173 100644 --- a/apps/expo/check-bundle.mjs +++ b/apps/expo/check-bundle.mjs @@ -5,7 +5,8 @@ // must be there as React Native style objects. src/App.tsx reads the theme, // the breakpoint and the orientation, so it calls each of those hooks of the // runtime; src/Badge.tsx is styled the same in every theme and at every -// width, so it must not use the runtime. +// width, so it must not use the runtime. Its buttons take press styles, which +// React Native's `Pressable` applies through a function for `style`. import { readdirSync, readFileSync } from 'node:fs' import { join } from 'node:path' @@ -117,7 +118,12 @@ for (const platform of ['ios', 'android']) { if (code.includes(PLACEHOLDER)) { failures.push(`${platform}/${file}: holds "${PLACEHOLDER}"`) } - for (const style of ['backgroundColor:"#5a44ff"', 'StyleSheet']) { + for (const style of [ + 'backgroundColor:"#5a44ff"', + 'backgroundColor:"#4330d9"', + 'StyleSheet', + 'style:({pressed:', + ]) { if (!code.replaceAll(' ', '').includes(style)) { failures.push(`${platform}/${file}: lacks ${style}`) } diff --git a/apps/expo/src/App.tsx b/apps/expo/src/App.tsx index 02be3958e..624128e25 100644 --- a/apps/expo/src/App.tsx +++ b/apps/expo/src/App.tsx @@ -67,6 +67,7 @@ export function App() { gap={3} > + <__Pressable onPress={go} style={({ pressed: __p }) => [__p && __s.g, __b < 1 ? __s.h : __s.a]} /> + <__Pressable onPress={go} style={({ pressed: __p }) => [ + __s.i, + __p && (on ? __s.h : __s.a), + extra + ]}> + + + <__Pressable style={({ pressed: __p }) => __t === 1 && __p && __s.j} /> + + + + + + + - <__Pressable onPress={go} style={({ pressed: __p }) => [__p && __s.g, __b < 1 ? __s.h : __s.a]} /> + <__Pressable onPress={go} style={({ pressed: __p }) => [__b < 1 ? __s.g : __s.a, __p && __s.h]} /> <__Pressable onPress={go} style={({ pressed: __p }) => [ __s.i, - __p && (on ? __s.h : __s.a), + __p && (on ? __s.g : __s.a), extra ]}> diff --git a/libs/extractor/src/native/snapshots/extractor__native__tests__theme_two.snap b/libs/extractor/src/native/snapshots/extractor__native__tests__theme_two.snap index 78a879126..621f269f2 100644 --- a/libs/extractor/src/native/snapshots/extractor__native__tests__theme_two.snap +++ b/libs/extractor/src/native/snapshots/extractor__native__tests__theme_two.snap @@ -83,7 +83,7 @@ export function Card({ on, color }) { ]} /> - + ; } diff --git a/libs/extractor/src/native/tests.rs b/libs/extractor/src/native/tests.rs index 026082155..7cb5c546d 100644 --- a/libs/extractor/src/native/tests.rs +++ b/libs/extractor/src/native/tests.rs @@ -1169,3 +1169,17 @@ export const outside = "#; fn compiles_pressed(#[case] name: &str, #[case] runtime: bool, #[case] code: &str) { assert_snapshot!(name, compile_themed(two_themes(), runtime, code)); } + +#[rstest] +#[case::theme("block_order_theme", "")] +#[case::orientation("block_order_orientation", "")] +#[case::pressed("block_order_pressed", "")] +#[case::nested( + "block_order_nested", + "" +)] +#[case::platform("block_order_platform", "")] +fn blocks_apply_after_the_other_styles(#[case] name: &str, #[case] code: &str) { + let code = format!("export function A() {{ return {code} }}"); + assert_snapshot!(name, compile_themed(two_themes(), true, &code)); +} From 3ba5930b1fd09a3bfea33aa3129c8bd9e973bc89 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 12:04:13 +0900 Subject: [PATCH 3/4] test(native): cover a static style checked against one kept in order Co-Authored-By: Claude Opus 5.5 --- libs/extractor/src/native/tests.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libs/extractor/src/native/tests.rs b/libs/extractor/src/native/tests.rs index 7cb5c546d..d65cf36d7 100644 --- a/libs/extractor/src/native/tests.rs +++ b/libs/extractor/src/native/tests.rs @@ -1183,3 +1183,24 @@ fn blocks_apply_after_the_other_styles(#[case] name: &str, #[case] code: &str) { let code = format!("export function A() {{ return {code} }}"); assert_snapshot!(name, compile_themed(two_themes(), true, &code)); } + +#[test] +fn a_static_style_after_one_kept_in_order_checks_it() { + let mut sheet = Sheet::new("s".to_string()); + let code = style_code( + vec![ + Choice::Dynamic(vec![("margin".to_string(), "m".to_string())]), + Choice::Static(declarations(&[("margin", 2.0)])), + Choice::Dynamic(vec![("width".to_string(), "w".to_string())]), + Choice::Static(declarations(&[("padding", 1.0)])), + ], + vec![], + &mut sheet, + &VARS, + ) + .map(|style| style.code); + assert_eq!( + code.as_deref(), + Some("[s.a, { margin: m }, s.b, { width: w }]") + ); +} From 7d52b64bbe893bae1d5bbfbbd494473c619e27b5 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 12:30:43 +0900 Subject: [PATCH 4/4] test(native): cover a static style checked against a state block Co-Authored-By: Claude Opus 5.5 --- libs/extractor/src/native/tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/extractor/src/native/tests.rs b/libs/extractor/src/native/tests.rs index d65cf36d7..57ae043ab 100644 --- a/libs/extractor/src/native/tests.rs +++ b/libs/extractor/src/native/tests.rs @@ -1193,6 +1193,11 @@ fn a_static_style_after_one_kept_in_order_checks_it() { Choice::Static(declarations(&[("margin", 2.0)])), Choice::Dynamic(vec![("width".to_string(), "w".to_string())]), Choice::Static(declarations(&[("padding", 1.0)])), + when( + State::Pressed, + Choice::Static(declarations(&[("height", 1.0)])), + ), + Choice::Static(declarations(&[("top", 1.0)])), ], vec![], &mut sheet, @@ -1201,6 +1206,6 @@ fn a_static_style_after_one_kept_in_order_checks_it() { .map(|style| style.code); assert_eq!( code.as_deref(), - Some("[s.a, { margin: m }, s.b, { width: w }]") + Some("[s.a, { margin: m }, s.b, { width: w }, p && s.c]") ); }