Skip to content

feat(native): press styles through Pressable on React Native - #1045

Open
owjs3901 wants to merge 4 commits into
feat/react-native-responsivefrom
feat/react-native-pressed
Open

owjs3901 wants to merge 4 commits into
feat/react-native-responsivefrom
feat/react-native-pressed

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #411, depends on #1044 (base: feat/react-native-responsive). PR 5 of the React Native plan: press styles (R3).

What it does

_active, the web's name, and _pressed, React Native's name, apply their styles while the element is pressed. React Native tells only a Pressable whether it is pressed, through a function for its style. So, as the owner decided, the element becomes a Pressable only when it uses a press style:

export function Buttons({ go }) {
  return (
    <Box onPress={go} bg="$primary" p={[1, 2]} _active={{ opacity: 0.5, bg: '$text' }} />
  )
}
import { Pressable as __Pressable } from "react-native";
export function Buttons({ go }) {
  const __t = __useThemeIndex();
  const __b = __useBreakpoint();
  return <__Pressable onPress={go} style={({ pressed: __p }) => [
    [__s.a, __s.b][__t],
    __b < 1 ? __s.c : __s.d,
    __p && [__s.e, __s.f][__t],
    __p && __s.g
  ]} />;
}
  • A Box, Flex, Center or VStack with a press style renders React Native's Pressable and keeps its other props, such as onPress. Without a press style, it is still a View. An empty _active={{}} does not change the element.
  • A Button is already a Pressable, so only its style becomes a function.
  • Press styles combine with everything before them: responsive values, themes (_themeDark={{ _pressed: {...} }}), platform and orientation blocks, conditions and runtime values. The style prop the element is given is still merged last.
  • An element outside a component that also reads the theme still renders through Themed: $s={(__t) => ({ pressed: __p }) => ...}.
  • No runtime is needed. Pressable gives pressed itself, so press styles also compile with runtime: false, and the runtime does not grow.

Fix: blocks apply after the other styles

On the web, _themeDark, _landscape and _active win over the element's other styles whatever the order of the props, because their selectors and media queries do. On React Native they followed the order of the props. So <Box _active={{ bg: 'red' }} bg="blue" />, which is the order ESLint sorts props in, never turned red, and a later bg dropped a _themeDark one (#1042, #1044). The styles of these blocks now come after the element's other styles at every level of nesting, which changes three earlier snapshots. Platform blocks (_ios/_android/_web) keep the order of the props.

Build errors

  • On a Text, an Image or an Input, which are not Pressable: "a press style needs React Native's Pressable, and the element renders React Native's Text. Fix: wrap it in a Box or a Button with _pressed".
  • With as, whose component cannot also be a Pressable.
  • A value other than an object, as with the other blocks.

_hover, _focus and the other interaction states are still build errors.

Expo example and CI

  • The two buttons of apps/expo now take _active styles.
  • check-bundle.mjs requires the bundle to hold the pressed color and a style:({pressed: function.
  • CI: feat/react-native-responsive is added to the pull_request branches of the workflow. It will be removed when this PR is retargeted.

Tests

  • Rust (insta + rstest) covers:
    • press styles on a Button and on Box/Flex, with themes, breakpoints, conditions and a given style;
    • nested and empty press styles;
    • a press style inside _themeDark;
    • an element outside a component;
    • name collisions (__p, __Pressable);
    • runtime: false;
    • errors;
    • block order: theme, orientation, press, nested and platform blocks.
  • cargo test --workspace passes. There are no web snapshot changes.
  • clippy -D warnings and cargo fmt are clean.
  • Locally, expo export for iOS and Android passes check-bundle.mjs.

#411의 일부이며 #1044에 의존합니다 (base: feat/react-native-responsive). React Native 계획의 5번째 PR인 press 스타일(R3)입니다.

변경 내용

_active(웹 이름)와 _pressed(React Native 이름)는 요소가 눌려 있는 동안 스타일을 적용합니다. React Native에서 눌림 여부를 아는 것은 Pressable뿐이고, Pressable은 style 함수로 그 값을 넘깁니다. 그래서 owner 결정대로 press 스타일을 쓸 때만 요소가 Pressable이 됩니다(위 예시 참고).

  • press 스타일이 있는 Box, Flex, Center, VStack은 React Native의 Pressable로 렌더링되고, onPress 같은 다른 prop은 그대로 유지합니다. press 스타일이 없으면 그대로 View입니다. 빈 _active={{}}는 요소를 바꾸지 않습니다.
  • Button은 이미 Pressable이므로 style만 함수가 됩니다.
  • 반응형 값, 테마(_themeDark={{ _pressed: {...} }}), 플랫폼·방향 블록, 조건식, 런타임 값과 모두 함께 동작합니다. 요소에 준 style prop은 여전히 마지막에 병합됩니다.
  • 컴포넌트 밖에 있으면서 테마도 읽는 요소는 계속 Themed로 렌더링합니다.
  • 런타임이 필요 없습니다. pressed는 Pressable이 직접 주므로 runtime: false에서도 컴파일되고, 런타임 크기도 늘지 않습니다.

수정: 블록은 다른 스타일보다 나중에 적용

웹에서 _themeDark, _landscape, _active는 selector와 media query 덕분에 prop 순서와 관계없이 요소의 다른 스타일을 이깁니다. React Native에서는 prop 순서를 따랐습니다. 그래서 ESLint가 정렬하는 순서인 <Box _active={{ bg: 'red' }} bg="blue" />는 눌러도 빨간색이 되지 않았고, 뒤에 오는 bg가 _themeDark의 값을 지웠습니다(#1042, #1044). 이제 이 블록의 스타일은 모든 중첩 단계에서 요소의 다른 스타일 뒤에 오며, 그래서 이전 snapshot 세 개가 바뀌었습니다. 플랫폼 블록(_ios/_android/_web)은 prop 순서를 유지합니다.

빌드 에러

  • Pressable이 아닌 Text, Image, Input에 쓴 경우 ("Box나 Button으로 감싸세요" 안내)
  • as와 함께 쓴 경우. as가 주는 컴포넌트는 Pressable이 될 수 없습니다.
  • 다른 블록처럼, 객체가 아닌 값

_hover, _focus 등 나머지 상호작용 상태는 여전히 빌드 에러입니다.

Expo 예제와 CI

  • apps/expo의 버튼 두 개에 _active 스타일을 추가했습니다.
  • check-bundle.mjs는 번들에 눌린 상태의 색과 style:({pressed: 함수가 있는지 확인합니다.
  • CI: workflow의 pull_request branches에 feat/react-native-responsive를 추가했습니다. 이 PR의 base를 바꿀 때 제거합니다.

테스트

  • Rust (insta + rstest)가 다루는 것:
    • Button과 Box/Flex의 press 스타일(테마, breakpoint, 조건식, 요소에 준 style 포함);
    • 중첩된 press 스타일과 빈 press 스타일;
    • _themeDark 안의 press 스타일;
    • 컴포넌트 밖의 요소;
    • 이름 충돌(__p, __Pressable);
    • runtime: false;
    • 에러;
    • 블록 순서: 테마, 방향, press, 중첩, 플랫폼 블록.
  • cargo test --workspace가 통과합니다. 웹 snapshot 변경은 없습니다.
  • clippy -D warnings와 cargo fmt는 깨끗합니다.
  • 로컬에서 iOS·Android expo export가 check-bundle.mjs를 통과했습니다.

🤖 Generated with Claude Code

`_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>
@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/errors.rs 100.00% <100.00%> (ø)
libs/extractor/src/native/mod.rs 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.

owjs3901 and others added 3 commits November 21, 2026 11:40
…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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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