Skip to content

fix(focus): enable imperative view refs on macOS - #3171

Open
Jason Morse (JasonVMo) wants to merge 1 commit into
mainfrom
user/jasonvmo/cpp-imperative-focus
Open

Jason Morse (JasonVMo) wants to merge 1 commit into
mainfrom
user/jasonvmo/cpp-imperative-focus

Conversation

@JasonVMo

Copy link
Copy Markdown

Summary:

  • Fabric non-TextInput ref.focus() and ref.blur() currently do nothing on macOS with the default feature flags. The generator configuration changed enableImperativeFocus to true in c32f3fc, but its generated JavaScript, C++, and Kotlin defaults remain false. The generator's unchanged check consequently also fails.
  • Enable these JavaScript view commands explicitly for macOS, where RCTViewComponentView already implements AppKit focus/blur and emits focus events without this flag. Restore the configuration's common default to false so all generated files stay unchanged. Simply regenerating with true would also enable new behavior on iOS and Android; their existing flag gates and defaults are preserved instead.
  • Keep registered TextInputs on their existing TextInputState path. This does not change native first-responder handling or the TextInput host/key-view-loop fixes from fix(macos): Fabric accessibility roles and state, and TextInput read-only and Tab-stop fixes #3136.
  • Add focused coverage for focus and blur on macOS with the flag disabled, both flag states on iOS/Android, and TextInput command routing on all three platforms.

This belongs in the fork: it restores macOS-specific behavior without changing upstream's platform rollout. Verified against main at 0b569f1; no matching open PR was found for enableImperativeFocus or ReactNativeElement. No Changeset is needed for main.

Test Plan:

All commands ran from the worktree root using Yarn 4.12.0 and Node 24.18.0.

Command Result
yarn install --immutable Passed with existing peer-dependency/build-script warnings; needed after the first generator invocation reported that this isolated worktree was not installed. No tracked dependency files changed.
yarn jest packages/react-native/src/private/webapis/dom/nodes/__tests__/ReactNativeElement-test.js --runInBand --watchman=false --cacheDirectory .yarn/jest-cache Before the production fix: 2 failed, 14 passed. Only the macOS focus/blur cases with the flag disabled failed.
yarn jest packages/react-native/src/private/webapis/dom/nodes/__tests__/ReactNativeElement-test.js packages/react-native/src/private/featureflags/__tests__/ReactNativeFeatureFlags-test.js --runInBand --watchman=false --cacheDirectory .yarn/jest-cache Final result: passed, 2 suites / 27 tests.
yarn featureflags --verify-unchanged Failed on unchanged main after installation, identifying the three inconsistent generated defaults. Passed after this fix; no generated files changed.
yarn flow focus-check packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js packages/react-native/src/private/webapis/dom/nodes/__tests__/ReactNativeElement-test.js --max-workers 2 --temp-dir .yarn/flow-cache Final result: passed, 0 errors; checked the 3 focused files, 756 dependents, and 334 dependencies. Earlier draft test-helper typing/mocking issues were corrected before this final pass.
yarn eslint --max-warnings 0 packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js packages/react-native/src/private/webapis/dom/nodes/__tests__/ReactNativeElement-test.js Passed, exit 0.
yarn exec prettier --check packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js packages/react-native/src/private/webapis/dom/nodes/__tests__/ReactNativeElement-test.js Passed; all matched files use Prettier code style.
git --no-pager diff --check Passed, exit 0.
git --no-pager diff --cached --check Passed, exit 0.

Not run: repository-wide yarn flow-check, yarn lint, yarn format-check, the full Jest/Fantom suites, native macOS/iOS/Android builds, Pods, Metro, RNTester focus/blur interaction, or accessibility event probes/screenshots. Validation is scoped to the changed JavaScript and feature-flag generation; native AppKit behavior was inspected but not exercised in a running app. No native sources or generated files changed.

Keep macOS Fabric view focus and blur commands available without enabling the common feature flag on iOS or Android. Restore generator consistency and preserve TextInput command routing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96
@JasonVMo

Copy link
Copy Markdown
Author

Additional validation: the six independent main fixes (#3170–#3175) were combined at e9667492e9 in an isolated worktree. After regenerating Pods from packages/rn-tester, RNTester-macOS and RNTester for arm64/x86_64 iOS simulators both built successfully. Exact commands, corrected codegen invocation, and limitations are recorded in #3175 (integration validation comment). This is build evidence, not live UI or sanitizer qualification; no PR was merged.

This branch has not been deployed

No deployments
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