Skip to content

feat: compile Devup UI elements to React Native styles (core, static subset) - #1039

Open
owjs3901 wants to merge 4 commits into
mainfrom
feat/react-native-core
Open

owjs3901 wants to merge 4 commits into
mainfrom
feat/react-native-core

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of #411 — PR 1 of the React Native plan: core native target, static subset.

What

  • ExtractOption gains target: ExtractTarget::{Web, Native(NativeTarget { platform, runtime })}. Web is the default and its path is untouched: no existing snapshot changed, and the full extractor suite (13,351 tests) passes as is.
  • New libs/extractor/src/native/ emitter. Users keep importing from @devup-ui/react (no new package). The import is rewritten to react-native under the same local names, style props become style objects hoisted into one StyleSheet.create per file, and they are passed through style.
  • Element mapping: Box→View, Text→Text, Image→Image (src→source), Input→TextInput, Button→Pressable, and Flex/VStack/Center→View with their flex defaults.
  • Values:
    • Shorthands and the web's number scale (p={1} → padding: 4).
    • px/rem/em become numbers; % and auto stay strings.
    • m="1px 2px" → marginVertical/marginHorizontal; border → width/style/color; gap → rowGap/columnGap; bg → backgroundColor/backgroundImage.
    • Dynamic values convert at runtime as literals do at build time, through a small function the file declares (const __u = (v, s) => …, no runtime import). It is emitted only when used:
      • lengths: p={x} → { padding: __u(x, 4) }, so x = 2 gives 8 (same as web's const x = 2 → 8px); "3px" → 3, "1rem" → 16, "2" → 8, while %/auto and anything else stay as they are
      • plain numbers (opacity, flex, zIndex, aspectRatio): __u(x, 1), so numeric strings become numbers
      • colors, keywords, shadows and fontWeight: passed through
      • Known gaps: a dynamic unitless lineHeight number is a font-size multiple on the web but pixels on React Native ("24px" works). Units the build cannot resolve without the window (vw/vh) reach React Native as they are. For reference, a truly dynamic value on the web goes raw into a CSS variable, so a number is not scaled there either; this PR doesn't change the web.
    • Conditionals (a ? x : y, a && x) are supported.
    • A later prop wins, as on the web.
  • _ios / _android / _web resolve at build time from platform.
  • Every prop React Native has no style for is a build error (file:line:col) with a reason and a fix. That includes responsive arrays, theme tokens and variants, and _pressed/_active. In this PR these need the runtime from later PRs, and runtime: false names itself in the message.
  • codeExtractNative(filename, code, packageName, platform, runtime) is exposed in the WASM and NAPI bindings, returning the existing Output with no css. The ABI guards, the validation oracle and the cross-engine corpus include it.
  • No Metro plugin and no runtime yet.

Example

import { Flex, Text } from '@devup-ui/react'
export const A = () => (
  <Flex bg="red" p={4} _ios={{ boxShadow: '0 1px 2px #0003' }}>
    <Text color={on ? 'blue' : 'gray'}>Hi</Text>
  </Flex>
)

compiles for ios to

import { View as Flex, Text } from "react-native";
import { StyleSheet } from "react-native";
const __s = StyleSheet.create({
	a: {
		flexDirection: "row",
		backgroundColor: "red",
		padding: 16,
		boxShadow: "0 1px 2px #0003"
	},
	b: { color: "blue" },
	c: { color: "gray" }
});
export const A = () => <Flex style={__s.a}>
    <Text style={on ? __s.b : __s.c}>Hi</Text>
  </Flex>;

Tests

  • 101 insta/rstest cases (including a Boa test running the conversion function) in native/tests.rs: every supported shape, each platform, and every build error message.
  • Binding-core tests and a WASM unit test.
  • A react-native-target corpus scenario run on both engines.
  • cargo clippy -D warnings, cargo fmt and ESLint are clean.

#411의 일부입니다. React Native 계획의 PR 1(코어 native 타깃, 정적 부분집합)입니다.

내용

  • ExtractOption에 target: ExtractTarget::{Web, Native(NativeTarget { platform, runtime })}를 추가했습니다. 기본값은 Web이고 웹 경로는 그대로입니다. 기존 스냅샷은 하나도 바뀌지 않았고, extractor 전체 테스트(13,351개)도 수정 없이 통과합니다.
  • libs/extractor/src/native/ 이미터를 새로 추가했습니다. 사용자는 계속 @devup-ui/react에서 import합니다(새 패키지 없음). import는 같은 로컬 이름으로 react-native로 바뀌고, 스타일 prop은 파일마다 하나의 StyleSheet.create로 끌어올린 뒤 style로 전달합니다.
  • 요소 매핑:
    • Box→View, Text→Text, Image→Image(src→source)
    • Input→TextInput, Button→Pressable
    • Flex/VStack/Center→flex 기본값을 가진 View
  • 값 변환:
    • 단축 prop과 웹의 숫자 배율(p={1} → padding: 4)을 그대로 따릅니다.
    • px/rem/em은 숫자가 되고, %와 auto는 문자열로 남습니다.
    • m="1px 2px" → marginVertical/marginHorizontal, border → width/style/color, gap → rowGap/columnGap, bg → backgroundColor/backgroundImage로 바뀝니다.
    • 동적 값은 파일에 선언하는 작은 함수(const __u = (v, s) => …, 런타임 import 없음)로 빌드 시점의 리터럴과 똑같이 런타임에 변환합니다. 이 함수는 쓰일 때만 넣습니다.
      • 길이: p={x} → { padding: __u(x, 4) }이므로 x = 2이면 8입니다(웹에서 const x = 2 → 8px과 같음). "3px" → 3, "1rem" → 16, "2" → 8이 되고, %/auto와 그 밖의 값은 그대로 남습니다.
      • 일반 숫자(opacity, flex, zIndex, aspectRatio): __u(x, 1)이므로 숫자 문자열이 숫자가 됩니다.
      • 색, 키워드, 그림자, fontWeight: 그대로 전달합니다.
      • 남은 차이: 동적 단위 없는 lineHeight 숫자는 웹에서 글꼴 크기의 배수지만 React Native에서는 픽셀입니다("24px"는 정상 동작). 창 크기 없이는 풀 수 없는 단위(vw/vh)는 그대로 전달됩니다. 참고로 웹은 진짜 동적 값을 CSS 변수에 그대로 넣기 때문에 웹에서도 숫자는 배율이 적용되지 않습니다. 이 PR은 웹을 바꾸지 않습니다.
    • 조건식(a ? x : y, a && x)을 지원합니다.
    • 웹과 같이 뒤에 쓴 prop이 이깁니다.
  • _ios / _android / _web은 빌드 시점에 platform으로 결정됩니다.
  • React Native에 해당 스타일이 없는 prop은 모두 이유와 해결 방법을 담은 빌드 에러(file:line:col)가 됩니다. 반응형 배열, 테마 토큰과 변형, _pressed/_active도 여기에 포함됩니다. 이들은 이후 PR의 런타임이 필요하며, runtime: false이면 메시지에 그 사실이 표시됩니다.
  • WASM과 NAPI 바인딩에 codeExtractNative(filename, code, packageName, platform, runtime)를 노출했습니다. 기존 Output을 css 없이 반환합니다. ABI 가드, 검증 오라클, 두 엔진 비교 코퍼스에도 포함했습니다.
  • Metro 플러그인과 런타임은 아직 없습니다.

테스트

  • native/tests.rs에 insta/rstest 101개 케이스(변환 함수를 Boa로 실행하는 테스트 포함)가 있습니다. 지원하는 모든 형태, 각 플랫폼, 모든 빌드 에러 메시지를 다룹니다.
  • 바인딩 코어 테스트와 WASM 단위 테스트를 추가했습니다.
  • 두 엔진에서 실행되는 react-native-target 코퍼스 시나리오를 추가했습니다.
  • cargo clippy -D warnings, cargo fmt, ESLint 모두 통과합니다.

🤖 Generated with Claude Code

owjs3901 and others added 2 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>
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bindings/devup-ui-binding/index.mjs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/host.rs 100.00% <ø> (ø)
bindings/devup-ui-binding/src/lib.rs 100.00% <ø> (ø)
bindings/devup-ui-wasm/src/lib.rs 100.00% <ø> (ø)
libs/binding/src/lib.rs 100.00% <ø> (ø)
libs/binding/src/output.rs 100.00% <ø> (ø)
libs/extractor/benches/alloc_benchmark.rs 100.00% <ø> (ø)
libs/extractor/benches/extract_benchmark.rs 100.00% <100.00%> (ø)
libs/extractor/benches/semantic_pass_benchmark.rs 100.00% <100.00%> (ø)
libs/extractor/src/lib.rs 100.00% <ø> (ø)
... and 10 more

... 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.

owjs3901 and others added 2 commits November 20, 2026 00:09
…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>
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