Skip to content

feat(native): css() and className on React Native - #1046

Open
owjs3901 wants to merge 8 commits into
feat/react-native-pressedfrom
feat/react-native-css
Open

owjs3901 wants to merge 8 commits into
feat/react-native-pressedfrom
feat/react-native-css

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Part of #411, depends on #1045 (base: feat/react-native-pressed). PR 6 of the React Native plan: css() and className (D3).

What it does

On React Native, css() compiles to the style it describes, which is the value React Native's style takes. className on a Devup UI element passes that style on:

const button = css({ borderRadius: '8px', px: 5 })

export function Save({ saving }) {
  const label = css({ color: '$text', fontSize: [14, null, 18] })
  return (
    <Button className={button} bg="$primary">
      <Text className={css(label, saving && { opacity: 0.5 })}>Save</Text>
    </Button>
  )
}
const button = __s.a;
export function Save({ saving }) {
  const __t = __useThemeIndex();
  const __b = __useBreakpoint();
  const label = [[__s.b, __s.c][__t], __b < 2 ? __s.d : __s.e];
  return <Button style={[button, __s.f]}>
      <Text style={[label, saving && __s.g]}>Save</Text>
    </Button>;
}
  • What css() takes, as on the web:
    • objects of style props, with responsive values, theme tokens and theme/platform/orientation blocks;
    • conditions choosing between objects (on ? {…} : null, on && {…});
    • what another css() gives, or any style value, passed on whole and in order;
    • falsy parts, which are skipped;
    • CSS text, such as css`padding: 8px 16px; background-color: $primary; border-radius: ${r};`. Property names are converted to React Native's camelCase, !important and comments are dropped, and each interpolation must be a whole value.
  • Order: the element's className comes first, then its style props, then its style prop.
  • Where it can be called: 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. The hooks are inserted there, as for elements. A css() that does not differ can be called anywhere, such as at the top of the file. It compiles to a StyleSheet entry and needs no runtime, including with runtime: false.
  • Imports: the css import is removed. A file importing only css from @devup-ui/react no longer imports the package at all.
  • style with compiled code: a style prop holding a css() call or Devup UI elements now has them compiled. Before, they could overlap the rewritten style.

Build errors

  • class names: className="p-4", className={`…`}, css('p-4'). React Native has no classes; Tailwind is out of scope (D7).
  • a press style (_active/_pressed) inside css(): only the element knows it is pressed. Fix: give _active to the element.
  • selectors, nesting and at-rules in CSS text, a declaration without a value, an interpolation inside a value (${x}px), and a property React Native has no style for.
  • css used other than as a call, and css(...parts).

styled(), globalCss(), keyframes() and Grid are still build errors and come in later PRs.

Expo example and CI

  • apps/expo declares the shape both buttons share with const button = css({...}) at the top of the file and passes it through className. Locally, expo export passes check-bundle.mjs.
  • CI: feat/react-native-pressed is added to the pull_request branches of the workflow. It will be removed when this PR is retargeted.

Tests

  • Rust (insta + rstest) covers:
    • css() at the top of a file and in a component;
    • responsive and theme values;
    • composition with other css() results, arrays, sequences and falsy parts;
    • conditions;
    • className with style;
    • style={css()} on a React Native component;
    • CSS text, including comments, !important, interpolations and empty text;
    • a file importing only css;
    • runtime: false;
    • every error above;
    • unit tests for class ordering.
  • 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의 일부이며 #1045에 의존합니다 (base: feat/react-native-pressed). React Native 계획의 6번째 PR인 css()와 className(D3)입니다.

변경 내용

React Native에서 css()는 자신이 설명하는 스타일로 컴파일됩니다. 이 스타일은 React Native의 style이 받는 값입니다. Devup UI 요소의 className은 그 스타일을 그대로 넘깁니다(위 예시 참고).

  • css()가 받는 것 (웹과 같음):
    • style prop 객체(반응형 값, 테마 토큰, 테마·플랫폼·방향 블록 포함);
    • 객체 중 하나를 고르는 조건식(on ? {…} : null, on && {…});
    • 다른 css()가 준 값이나 임의의 스타일 값(통째로, 순서대로 전달);
    • falsy 값(건너뜀);
    • CSS 텍스트(css`padding: 8px 16px; background-color: $primary; border-radius: ${r};`). 속성 이름은 React Native의 camelCase로 바꾸고, !important와 주석은 버립니다. 보간은 값 전체여야 합니다.
  • 순서: 요소의 className이 먼저 오고, 그다음 style prop, 마지막으로 style prop이 옵니다.
  • 호출할 수 있는 곳: 테마·breakpoint·방향에 따라 달라지는 css()는 런타임을 읽으므로 함수 컴포넌트나 hook 안에서 호출해야 합니다. hook은 요소와 마찬가지로 그곳에 삽입됩니다. 달라지지 않는 css()는 파일 최상단 등 어디서든 호출할 수 있습니다. 이때는 StyleSheet 항목으로 컴파일되므로 런타임이 필요 없고, runtime: false에서도 동작합니다.
  • import: css import는 제거됩니다. @devup-ui/react에서 css만 import하던 파일은 이제 그 패키지를 전혀 import하지 않습니다.
  • 컴파일되는 코드가 든 style: style prop 안의 css() 호출이나 Devup UI 요소도 이제 컴파일됩니다. 이전에는 다시 쓰는 style과 위치가 겹칠 수 있었습니다.

빌드 에러

  • 클래스 이름: className="p-4", className={`…`}, css('p-4'). React Native에는 클래스가 없고, Tailwind는 범위 밖입니다(D7).
  • css() 안의 press 스타일(_active/_pressed): 눌림 여부는 요소만 압니다. 해결: 요소에 _active를 주세요.
  • CSS 텍스트 안의 selector·중첩·at-rule, 값이 없는 선언, 값 일부만인 보간(${x}px), React Native에 없는 속성
  • 호출이 아닌 css 사용, css(...parts)

styled(), globalCss(), keyframes(), Grid는 여전히 빌드 에러이며 다음 PR에서 다룹니다.

Expo 예제와 CI

  • apps/expo는 두 버튼이 공유하는 모양을 파일 최상단의 const button = css({...})로 선언하고 className으로 넘깁니다. 로컬에서 expo export가 check-bundle.mjs를 통과했습니다.
  • CI: workflow의 pull_request branches에 feat/react-native-pressed를 추가했습니다. 이 PR의 base를 바꿀 때 제거합니다.

테스트

  • Rust (insta + rstest)가 다루는 것:
    • 파일 최상단과 컴포넌트 안의 css();
    • 반응형·테마 값;
    • 다른 css() 결과, 배열, sequence, falsy 값과의 조합;
    • 조건식;
    • style과 함께 쓰는 className;
    • React Native 컴포넌트의 style={css()};
    • CSS 텍스트(주석, !important, 보간, 빈 텍스트 포함);
    • css만 import하는 파일;
    • runtime: false;
    • 위의 모든 에러;
    • 클래스 순서 단위 테스트.
  • cargo test --workspace가 통과합니다. 웹 snapshot 변경은 없습니다.
  • clippy -D warnings와 cargo fmt는 깨끗합니다.
  • 로컬 cargo llvm-cov에서 새로 추가한 줄은 모두 커버됩니다.

🤖 Generated with Claude Code

owjs3901 and others added 8 commits November 21, 2026 11:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
@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/errors.rs 100.00% <100.00%> (ø)
libs/extractor/src/native/imports.rs 100.00% <100.00%> (ø)
libs/extractor/src/native/style.rs 100.00% <100.00%> (ø)
🚀 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.

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