Skip to content

feat(native): hover, focus and disabled styles on React Native - #1048

Open
owjs3901 wants to merge 1 commit into
feat/react-native-styledfrom
feat/react-native-states
Open

owjs3901 wants to merge 1 commit into
feat/react-native-styledfrom
feat/react-native-states

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Part of #411, depends on #1047 (base: feat/react-native-styled). PR 8 of the React Native plan: the remaining interaction states (_hover, _focus, _disabled) from the design's selector table.

What it does

<Button disabled={busy} onPress={go} bg="$primary"
  _hover={{ opacity: 0.9 }} _focus={{ borderColor: 'blue' }} _active={{ opacity: 0.7 }} _disabled={{ opacity: 0.4 }} />
<Input _focus={{ borderColor: '$primary' }} value={value} onFocus={track} />
<Button disabled={busy} onPress={go} style={({ pressed: __p, hovered: __h, focused: __f }) => [
  [__s.a, __s.b][__t], __h && __s.c, __f && __s.d, busy && __s.e, __p && __s.f
]} />
<__Focused value={value} onFocus={track} $c={Input} $s={(__f) => __f && [__s.h, __s.i][__t]} />
  • _hover and _focus on Pressable: they read the hovered and focused that Pressable gives its style function. The function destructures only the keys the element reads. Like _active, they make a Box/Flex/Center/VStack a Pressable. React Native reports them where the platform has a pointer or keyboard focus, such as the web through react-native-web (D5). On a phone's touch screen they never apply. This is documented.
  • _focus on an Input: a TextInput tells its focus only through events. The element therefore renders through a new runtime component, Focused. Focused keeps the focus state, still calls the element's own onFocus/onBlur, and gives the style function (focused, theme, breakpoint, landscape). Inside a component, the theme hooks stay in the component. Outside one, Focused reads them as Themed does.
  • _disabled: applies while the element's disabled prop is true. It compiles to busy && __s.e, or to the style alone for a bare disabled. On an element without disabled it never applies, so it is dropped. In a styled() component it reads the component's disabled prop: __props.disabled && ….
  • Styled components: _hover, _focus and _disabled also work in styled() (feat(native): styled() on React Native #1047).

Runtime: @devup-ui/react/native

Focused (internal) is added. Size, measured with bun build --minify (react and react-native external) and then gzip -9:

Minified Minified + gzip
Before this PR 1,115 B 630 B
After this PR 1,302 B 702 B
Change +187 B +72 B

Build errors

  • _hover/_focus/_active on a Text or an Image, _hover on an Input, and any of them with as
  • in css(): _hover, _focus and _active (fix: give them to the element). _disabled is also an error there, because only the element knows its disabled.
  • other selectors (_focusVisible, _checked, _before, …), as before

Expo example and CI

  • The name input of apps/expo takes _focus={{ borderColor: '#5a44ff' }}.
  • check-bundle.mjs requires src/App.tsx to use Focused. Locally, expo export passes the check.
  • CI: feat/react-native-styled 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 state on Button, Box and Input;
    • an element with and without disabled, and a bare disabled;
    • Focused inside and outside a component, with theme and breakpoint values;
    • styled() with states;
    • errors in css(), on Text/Input and with as.
  • 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.
  • Runtime bun test for Focused:
    • focus and blur change the style;
    • the element's handlers are still called;
    • it works without handlers.
    • The runtime keeps 100% coverage.

#411의 일부이며 #1047에 의존합니다 (base: feat/react-native-styled). React Native 계획의 8번째 PR로, 설계의 selector 표에 남아 있던 상호작용 상태(_hover, _focus, _disabled)를 다룹니다.

변경 내용

  • Pressable의 _hover와 _focus: Pressable이 style 함수에 주는 hovered와 focused를 읽습니다. 함수는 요소가 읽는 키만 구조 분해합니다. _active처럼 Box/Flex/Center/VStack을 Pressable로 만듭니다. React Native는 포인터나 키보드 포커스가 있는 플랫폼에서만 이 값을 알려 줍니다. react-native-web을 쓰는 웹(D5)이 그 예이고, 휴대폰 터치 화면에서는 적용되지 않습니다. 이 내용은 README에 문서화했습니다.
  • Input의 _focus: TextInput은 포커스를 이벤트로만 알려 줍니다. 그래서 이 요소는 새 런타임 컴포넌트 Focused로 렌더링합니다. Focused는 포커스 상태를 관리하고, 요소의 onFocus/onBlur도 그대로 호출하며, style 함수에 (focused, theme, breakpoint, landscape)를 넘깁니다. 컴포넌트 안에서는 테마 hook이 컴포넌트에 그대로 남습니다. 컴포넌트 밖에서는 Themed처럼 Focused가 직접 읽습니다.
  • _disabled: 요소의 disabled prop이 참일 때 적용되며, busy && __s.e로 컴파일됩니다. disabled만 쓰면 스타일만 남습니다. disabled가 없는 요소에서는 적용될 일이 없으므로 제거합니다. styled() 컴포넌트에서는 컴포넌트의 disabled prop을 읽습니다(__props.disabled && …).
  • styled 컴포넌트: _hover, _focus, _disabled는 styled()(feat(native): styled() on React Native #1047)에서도 동작합니다.

런타임 @devup-ui/react/native

내부용 Focused를 추가했습니다. 크기는 bun build --minify(react와 react-native는 external)로 번들한 뒤 gzip -9로 측정했습니다.

minified min+gz
이 PR 이전 1,115 B 630 B
이 PR 이후 1,302 B 702 B
증가량 +187 B +72 B

빌드 에러

  • Text·Image의 _hover/_focus/_active, Input의 _hover, as와 함께 쓴 경우
  • css() 안의 _hover, _focus, _active(요소에 주세요). disabled는 요소만 알기 때문에 _disabled도 에러입니다.
  • 그 밖의 selector(_focusVisible, _checked, _before, …)는 이전과 같습니다.

Expo 예제와 CI

  • apps/expo의 이름 입력란에 _focus={{ borderColor: '#5a44ff' }}를 추가했습니다.
  • check-bundle.mjs는 src/App.tsx가 Focused를 쓰는지 확인합니다. 로컬에서 expo export가 검사를 통과했습니다.
  • CI: workflow의 pull_request branches에 feat/react-native-styled를 추가했습니다. 이 PR의 base를 바꿀 때 제거합니다.

테스트

  • Rust (insta + rstest)가 다루는 것:
    • Button·Box·Input의 모든 상태;
    • disabled가 있는 요소와 없는 요소, 값 없이 쓴 disabled;
    • 컴포넌트 안팎의 Focused(테마·breakpoint 값 포함);
    • 상태를 쓰는 styled();
    • css(), Text/Input, as의 에러.
  • cargo test --workspace가 통과합니다. 웹 snapshot 변경은 없습니다.
  • clippy -D warnings와 cargo fmt는 깨끗합니다.
  • 로컬 cargo llvm-cov에서 새로 추가한 줄은 모두 커버됩니다.
  • Focused 런타임 bun 테스트:
    • focus/blur에 따라 스타일이 바뀝니다;
    • 요소의 핸들러도 호출됩니다;
    • 핸들러가 없어도 동작합니다.
    • 런타임 coverage는 100%를 유지합니다.

🤖 Generated with Claude Code

`_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>
@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% <ø> (ø)
libs/extractor/src/native/style.rs 100.00% <100.00%> (ø)
packages/react/src/native/index.ts 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