Repository navigation
fix(focus): enable imperative view refs on macOS - #3171
Jason Morse (JasonVMo) wants to merge 1 commit into
Conversation
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
|
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. |
| // [macOS] | ||
|
|
||
| import TextInputState from '../../../../../../Libraries/Components/TextInput/TextInputState'; | ||
| import {Commands as ViewCommands} from '../../../../../../Libraries/Components/View/ViewNativeComponent'; | ||
| import Platform from '../../../../../../Libraries/Utilities/Platform'; | ||
| import * as ReactNativeFeatureFlags from '../../../../featureflags/ReactNativeFeatureFlags'; | ||
| import ReactNativeElement from '../ReactNativeElement'; | ||
|
|
||
| jest.mock( | ||
| '../../../../../../Libraries/Components/View/ViewNativeComponent', | ||
| () => ({ | ||
| Commands: { | ||
| blur: jest.fn(), | ||
| focus: jest.fn(), | ||
| }, | ||
| }), | ||
| ); | ||
| jest.mock('../specs/NativeDOM', () => ({})); |
There was a problem hiding this comment.
I don't think we the macOS fork should be responsible for adding these tests. Especially ones that seem to test nothing macOS specific.
https://deepwiki.com/mattpocock/skills/4.2-test-driven-development
| } else if ( | ||
| Platform.OS === 'macos' || // [macOS] | ||
| ReactNativeFeatureFlags.enableImperativeFocus() | ||
| ) { | ||
| ViewCommands.blur(this); |
There was a problem hiding this comment.
This very much feels like th wrong place to set this. Can we not just override the default in the feature flags, even if we have to touch a bunch of files?
| }, | ||
| enableImperativeFocus: { | ||
| defaultValue: true, // [macOS] | ||
| defaultValue: false, |
There was a problem hiding this comment.
I'd rather we come up with a way to override these in our fork more easily
Summary:
ref.focus()andref.blur()currently do nothing on macOS with the default feature flags. The generator configuration changedenableImperativeFocustotruein c32f3fc, but its generated JavaScript, C++, and Kotlin defaults remainfalse. The generator's unchanged check consequently also fails.RCTViewComponentViewalready implements AppKit focus/blur and emits focus events without this flag. Restore the configuration's common default tofalseso all generated files stay unchanged. Simply regenerating withtruewould also enable new behavior on iOS and Android; their existing flag gates and defaults are preserved instead.TextInputStatepath. 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.This belongs in the fork: it restores macOS-specific behavior without changing upstream's platform rollout. Verified against
mainat 0b569f1; no matching open PR was found forenableImperativeFocusorReactNativeElement. No Changeset is needed formain.Test Plan:
All commands ran from the worktree root using Yarn 4.12.0 and Node 24.18.0.
yarn install --immutableyarn jest packages/react-native/src/private/webapis/dom/nodes/__tests__/ReactNativeElement-test.js --runInBand --watchman=false --cacheDirectory .yarn/jest-cacheyarn 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-cacheyarn featureflags --verify-unchangedmainafter 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-cacheyarn 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.jsyarn 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.jsgit --no-pager diff --checkgit --no-pager diff --cached --checkNot 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.