fix(macos): show React menu on right-click of Fabric root views#2757
Draft
Saadnajmi wants to merge 1 commit intomicrosoft:trunkfrom
Draft
fix(macos): show React menu on right-click of Fabric root views#2757Saadnajmi wants to merge 1 commit intomicrosoft:trunkfrom
Saadnajmi wants to merge 1 commit intomicrosoft:trunkfrom
Conversation
The Fabric root view (`RCTSurfaceHostingProxyRootView`) does not override `menuForEvent:` like the old-architecture `RCTRootView` does, so secondary clicks on the React content do nothing on the new architecture. Add a `HostingViewController` whose `rightMouseDown` shows the React menu, and use it for the React content view in multi-app mode. Also ungate the existing `ViewController` handlers so single-app mode picks them up via the responder chain. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On the new architecture, right-clicking inside the React content of the macOS test app shows nothing. On the old architecture,
RCTRootView.menuForEvent:returns the dev menu, but the Fabric root view (RCTSurfaceHostingProxyRootView) does not overridemenuForEvent:, so the menu never appears.This adds a small
HostingViewControllerthat overridesmouseDown/rightMouseDownto pop up the React menu, and:AppDelegate.present()(multi-app mode, after a component is presented).ViewControllerso they also fire inENABLE_SINGLE_APP_MODE, where the storyboard-instantiatedViewControlleris in the responder chain above the React root view.The
popUpReactMenuhelper is moved out of the#if !ENABLE_SINGLE_APP_MODEguard so it is available in single-app mode too.Relationship to microsoft/rnx-kit#4114
This is the self-contained workaround of a pair. The underlying root cause — that consumers of
host.viewWithModuleName:bypassRCTRootViewFactoryand so the upstreamdevMenuwiring onRCTSurfaceHostingView(react-native-macos 0.81+) never runs — is fixed properly in microsoft/rnx-kit#4114. That PR makes@rnx-kit/react-native-hostsetdevMenuon 0.81+ and installs a fallback gesture recognizer on older versions, so the upstream React Native dev menu (Reload, Open Debugger, …) shows on secondary-click without the test app needing to do anything.The two PRs differ in what menu they show:
Once microsoft/rnx-kit#4114 lands, is published, and the test app bumps
@rnx-kit/react-native-host, this workaround can be removed in favor of the upstream behavior — or kept if we prefer the test app's richer React menu over the bare RN dev menu. They will conflict if both are active, since the rnx-kit gesture recognizer fires before the responder chain reachesHostingViewController, so this should be removed at the same commit that picks up the new rnx-kit version.Test plan
🤖 Generated with Claude Code