Skip to content

feat(native): styled() on React Native - #1047

Merged
owjs3901 merged 37 commits into
mainfrom
feat/react-native-styled
Nov 29, 2026
Merged

owjs3901 merged 37 commits into
mainfrom
feat/react-native-styled

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Part of #411, depends on #1046 (base: feat/react-native-css). PR 7 of the React Native plan: styled().

What it does

styled() compiles to a function component. The component renders its target with the styles it describes, followed by the style it is given. As the design planned, the static part is hoisted into the StyleSheet, and functions of the props become values and parts chosen at render:

export const Card = styled(Box)({ bg: '$surface', p: [2, null, 4], borderRadius: '8px' })
export const Title = styled(Text)`
  color: ${(props) => props.color};
  font-size: 18px;
`
export const Item = styled(View)({ m: 1 }, (props) => props.active && css({ opacity: 0.5 }))
export const Card = (__props) => {
  const __t = __useThemeIndex();
  const __b = __useBreakpoint();
  return <Box {...__props} style={[__s.a, [__s.b, __s.c][__t], __b < 2 ? __s.d : __s.e, __props.style]} />;
};
export const Title = (__props) => {
  return <Text {...__props} style={[__s.g, { color: ((props) => props.color)(__props) }, __props.style]} />;
};
export const Item = (__props) => {
  return <View {...__props} style={[__s.i, ((props) => props.active && __s.h)(__props), __props.style]} />;
};
  • Forms: styled(Target)(...parts), styled(Target)`css text` and styled(Target, styles).
  • Parts: the same as css() in feat(native): css() and className on React Native #1046:
    • objects with responsive values, tokens and theme/platform/orientation/press blocks;
    • conditions;
    • other css() results;
    • CSS text.
  • Functions of the props, which give variants:
    • a value: w: (p) => p.width, or an interpolation in CSS text, converted like a runtime value;
    • a part giving what css() gives: (p) => p.primary && css({...}).
  • Targets:
    • A Devup UI component renders its React Native component and keeps the styles it declares first (Flex keeps its row).
    • Any React Native or other component, such as View or Animated.View, is rendered as it is.
  • Press styles: a press style on a styled Box makes it a Pressable (feat(native): press styles through Pressable on React Native #1045). A styled Button gets a style function.
  • Hooks: the hooks the styles read, including those of css() calls inside functions, are called at the top of the generated component. styled() can therefore be called at the top of the file even when its styles differ by theme or breakpoint.
  • Imports: the styled import is removed.

Build errors

  • a tag (styled('div')), or a target that is not a component name
  • styled(Target) that is not called with styles, styled(...parts), styled used other than as a call, and styled(Target, styles, extra)
  • a function of the props that gives style props ((p) => ({ bg: p.color }), or a condition choosing such objects). React Native cannot read style props at runtime. Fix: return what css() gives, or write each value as a function.
  • a press style on a target the build cannot make a Pressable

Known difference from the web, documented in the README: <Card p={1} /> passes p on to the target instead of compiling it, because the component is not a Devup UI element. Give style or className instead.

Expo example and CI

  • apps/expo/src/Badge.tsx is now styled(Text)({...}). It still uses no runtime: check-bundle.mjs passes locally.
  • CI: feat/react-native-css is added to the pull_request branches of the workflow. It will be removed when this PR is retargeted.

Tests

  • Rust (insta + rstest) covers every form and target, including:
    • theme and breakpoint hooks in the generated component;
    • CSS text with an interpolated function;
    • function values and function parts;
    • press styles on Box and Button;
    • every error.
  • cargo test --workspace passes. There are no web snapshot changes.
  • clippy -D warnings and cargo fmt are clean.
  • Local cargo llvm-cov shows every new line covered.

#411의 일부이며 #1046에 의존합니다 (base: feat/react-native-css). React Native 계획의 7번째 PR인 styled()입니다.

변경 내용

styled()는 함수 컴포넌트로 컴파일됩니다. 이 컴포넌트는 target을 렌더링하면서 styled()가 설명하는 스타일을 적용하고, 그 뒤에 자신이 받은 style을 붙입니다. 설계대로 정적인 부분은 StyleSheet로 끌어올리고, props의 함수는 렌더링할 때 고르는 값과 부분이 됩니다(위 예시 참고).

  • 형태: styled(Target)(...parts), styled(Target)`css text`, styled(Target, styles)
  • parts: #1046의 css()와 같습니다.
    • 반응형 값, 토큰, 테마·플랫폼·방향·press 블록이 든 객체;
    • 조건식;
    • 다른 css() 결과;
    • CSS 텍스트.
  • props의 함수(variant):
    • 값: w: (p) => p.width 또는 CSS 텍스트의 보간. 런타임 값처럼 변환합니다.
    • css() 결과를 돌려주는 부분: (p) => p.primary && css({...})
  • target:
    • Devup UI 컴포넌트는 해당 React Native 컴포넌트로 렌더링하고, 먼저 선언하는 스타일을 유지합니다(Flex의 row).
    • View, Animated.View 등 그 밖의 컴포넌트는 그대로 렌더링합니다.
  • press 스타일: press 스타일이 있는 styled Box는 Pressable이 되고(feat(native): press styles through Pressable on React Native #1045), styled Button은 style 함수를 받습니다.
  • hook: 스타일이 읽는 hook은 생성된 컴포넌트 맨 위에서 호출합니다. 함수 안의 css()가 읽는 hook도 포함됩니다. 그래서 테마나 breakpoint에 따라 스타일이 달라지더라도 styled()를 파일 최상단에서 호출할 수 있습니다.
  • import: styled import는 제거됩니다.

빌드 에러

  • 태그(styled('div')) 또는 컴포넌트 이름이 아닌 target
  • 스타일과 함께 호출하지 않은 styled(Target), styled(...parts), 호출이 아닌 styled 사용, styled(Target, styles, extra)
  • style prop을 돌려주는 props 함수((p) => ({ bg: p.color }) 또는 그런 객체를 고르는 조건식). React Native는 런타임에 style prop을 읽을 수 없습니다. 해결: css() 결과를 돌려주거나, 값마다 함수로 쓰세요.
  • Pressable로 만들 수 없는 target의 press 스타일

웹과 다른 점(README에 문서화): <Card p={1} />는 p를 컴파일하지 않고 target에 그대로 넘깁니다. 이 컴포넌트는 Devup UI 요소가 아니기 때문입니다. 대신 style이나 className을 주세요.

Expo 예제와 CI

  • apps/expo/src/Badge.tsx는 이제 styled(Text)({...})입니다. 여전히 런타임을 쓰지 않으며, 로컬에서 check-bundle.mjs를 통과했습니다.
  • CI: workflow의 pull_request branches에 feat/react-native-css를 추가했습니다. 이 PR의 base를 바꿀 때 제거합니다.

테스트

  • Rust (insta + rstest)가 모든 형태와 target을 다룹니다. 여기에 포함되는 것:
    • 생성된 컴포넌트의 테마·breakpoint hook;
    • 함수를 보간한 CSS 텍스트;
    • 함수 값과 함수 부분;
    • Box와 Button의 press 스타일;
    • 모든 에러.
  • cargo test --workspace가 통과합니다. 웹 snapshot 변경은 없습니다.
  • clippy -D warnings와 cargo fmt는 깨끗합니다.
  • 로컬 cargo llvm-cov에서 새로 추가한 줄은 모두 커버됩니다.

🤖 Generated with Claude Code

owjs3901 and others added 25 commits November 19, 2026 22:55
Add a Native target to ExtractOption that turns Devup UI elements into
React Native components with their styles hoisted into one
StyleSheet.create per file, and expose it as codeExtractNative in the
WASM and NAPI bindings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tive into the ABI checks

Snapshot every supported prop shape, platform and build error of the
native target, list codeExtractNative in the binding ABI guards and the
cross-engine corpus, document it and add its changepack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as literals are

A dynamic length such as p={x} reached React Native unscaled, so x = 2
gave padding 2 where the web build gives 8px for the constant. Wrap
values read at runtime in a file-local function that converts them as
the build converts a literal: numbers and numeric strings take the
property's scale (four pixels a unit for lengths), px lengths become
numbers and rem/em lengths become pixels. Colors, keywords and other
text pass through as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… conversion in the changepack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add @devup-ui/metro-plugin (experimental, private 0.x): withDevupUI()
points babelTransformerPath at a transformer that runs codeExtractNative
on files importing Devup UI and chains to the upstream transformer
(the config's, else Expo's, else React Native's). Build errors carry
loc and a code frame so Metro reports file:line:col, the upstream AST
locations are moved back to the source through the engine's map, and
the cache key covers the upstream key, devup.json, the engine version
and the options.

Add apps/expo (Expo SDK 58, RN 0.88) and a path-filtered CI job that
exports iOS and Android bundles and checks no @devup-ui/react module
or runtime placeholder is left.

Part of #411.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve `$` tokens and typography of devup.json at build time for React
Native. With one theme every value is a literal and no runtime is imported;
with more, each theme's styles are precomputed and picked by the index
`useThemeIndex()` of the new `@devup-ui/react/native` runtime gives, which
follows the OS appearance and `setTheme`. `_theme*` and the theme API
compile, and `runtime: false` keeps them build errors. The Metro plugin
registers devup.json's theme, and the Expo example gains a theme toggle and
a bundle check that static files do not use the runtime.

Part of #411.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
verify-dist loads every declared entry, and `@devup-ui/react/native`
imports react-native, which is Flow source Bun cannot parse. A virtual
module stands in for it so the entry still loads and exports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover a typography whose token one theme does not define, a static style
merged into a themed one, and a later style checked against a choice that
applies in one theme. A merge that leaves every theme declaring the same
styles now collapses to one static style instead of picking between equal
objects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… React Native

Responsive arrays, length/shadow/typography tokens with a value at each
breakpoint, responsive values in platform, theme and orientation blocks and
conditions compile to one style object for each run of breakpoints that
share their styles (by breakpoint and theme where both differ). The runtime
store of @devup-ui/react/native also tells the breakpoint of devup.json the
window is at and its orientation through one Dimensions listener that
notifies only when a breakpoint is crossed or the window turns.
_portrait/_landscape apply by orientation. With runtime: false these stay
build errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The React Native runtime now reads the window size through Dimensions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`_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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r styles

On the web, `_themeDark`, `_landscape` and `_active` win over the element's
other styles whatever the order of the props, as their selectors and media
queries do. On React Native they followed the order of the props, so
`<Box _active={{ bg: 'red' }} bg="blue" />` (the order ESLint sorts props
in) never turned red, and a later `bg` dropped a `_themeDark` one. The
styles of these blocks now come after the element's other styles, at every
level of nesting. Platform blocks keep the order of the props.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	libs/extractor/src/native/element.rs
#	libs/extractor/src/native/tests.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`styled(Target)(...parts)`, `` styled(Target)`css text` `` and
`styled(Target, styles)` compile to a function component rendering its
target with the styles they describe, before the `style` it is given. The
parts are those of `css()`; a function in them is called with the props, as
a value or as a part giving what `css()` gives. A Devup UI target keeps the
styles it declares first, a styled `Box` with a press style becomes a
`Pressable`, and the hooks the styles read are called in the component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/extractor/src/native/element.rs 100.00% <100.00%> (ø)
libs/extractor/src/native/element/css_call.rs 100.00% <100.00%> (ø)
libs/extractor/src/native/element/styled.rs 100.00% <100.00%> (ø)
libs/extractor/src/native/imports.rs 100.00% <ø> (ø)
libs/extractor/src/native/style.rs 100.00% <100.00%> (ø)
packages/react/src/native/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* wip(native): css() and className on React Native

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* wip(native): drop a probe test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(native): css() as CSS text, README and changepack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(native): pass classes to style_code in the merged test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(native): cover css() parts around state blocks and empty objects

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from feat/react-native-css to feat/react-native-pressed November 25, 2026 15:26
owjs3901 and others added 9 commits November 26, 2026 00:27
… React Native (#1044)

* feat(native): responsive values, responsive tokens and orientation on React Native

Responsive arrays, length/shadow/typography tokens with a value at each
breakpoint, responsive values in platform, theme and orientation blocks and
conditions compile to one style object for each run of breakpoints that
share their styles (by breakpoint and theme where both differ). The runtime
store of @devup-ui/react/native also tells the breakpoint of devup.json the
window is at and its orientation through one Dimensions listener that
notifies only when a breakpoint is crossed or the window turns.
_portrait/_landscape apply by orientation. With runtime: false these stay
build errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(verify-dist): give the react-native stand-in Dimensions

The React Native runtime now reads the window size through Dimensions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflicts left by squash-merging #1041 against the branch's
own un-squashed metro commits, keeping #1040's shared runtime units
import (`@devup-ui/react/scale`) alongside the native runtime entry, and
drop the merged feat/react-native-metro, -responsive and -css branches
from the pull_request triggers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflicts left by squash-merging #1044 against the branch's
own un-squashed responsive commits, take main's shared runtime units
import for values read at runtime, and drop the merged
feat/react-native-responsive branch from the pull_request triggers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflicts left by squash-merging #1046 against the branch's
own un-squashed css commits, take main's shared runtime units import for
values read at runtime, and drop the merged feat/react-native-css branch
from the pull_request triggers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main now holds #1042 squashed, whose tree matches this branch's merged
feat/react-native-themes, so the merge keeps this branch's tree and only
drops the merged feat/react-native-themes branch from the pull_request
triggers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in #1043, #1055 and #1056 from main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in main (#1042 squashed, #1043, #1055, #1056) and the stack's
squash-merge resolutions, and drop the merged branches from the
pull_request triggers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in #1057, #1058, #1061 and #1062 from main, and take #1063's
pull_request trigger, which runs the checks whatever branch a pull
request targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in main's #1057, #1058, #1061 and #1062, and take #1063's
pull_request trigger, which runs the checks whatever branch a pull
request targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from feat/react-native-pressed to main November 28, 2026 17:40
owjs3901 and others added 2 commits November 29, 2026 02:40
`_hover` and `_focus` read the `hovered` and `focused` that `Pressable`
gives its style function, and make a `Box` a `Pressable` as `_active` does.
An `Input` with `_focus` renders through the runtime's new `Focused`, which
follows its focus events. `_disabled` applies while the element's
`disabled` prop is true, or a `styled()` component's. In `css()` these are
build errors.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Merged against the pre-squash tip 34caf28 so content that was
squash-merged does not conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit 1c3de01 into main Nov 29, 2026
39 checks passed
@owjs3901
owjs3901 deleted the feat/react-native-styled branch November 29, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant