Skip to content

fix(ios): pass taps to the children of a long-press MenuView on Fabric - #1233

Merged
Naturalclar merged 2 commits into
react-native-menu:masterfrom
hugomn:fix/ios-long-press-children
Nov 15, 2026
Merged

Naturalclar merged 2 commits into
react-native-menu:masterfrom
hugomn:fix/ios-long-press-children

Conversation

@hugomn

@hugomn hugomn commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes #1183.

On the new architecture, MenuView.mm sets the menu's UIButton as the component's contentView. React Native adds the contentView with addSubview: and mounts the children with insertSubview:atIndex:, so the button always sits above the children, and nothing overrides the hit test. Every touch lands on the button and React's touch target becomes the MenuView itself. With shouldOpenOnLongPress, a Pressable or a Text with onPress inside never gets its press. It also hides the children from VoiceOver: RCTViewComponentView takes isAccessibilityElement from its contentView, so the whole menu reads as one element.

With this change, when shouldOpenOnLongPress is on, the UIContextMenuInteraction lives on the component view and the button steps out of touches and accessibility. The interaction forwards configurationForMenuAtLocation and willEnd to the button, so the menu, its title and onOpenMenu / onCloseMenu come from the same code as before. A tap reaches the child under the finger and a long press opens the menu. Menus that open on a tap are not touched.

A few details a reviewer will probably ask about:

  • Preview. The preview is the component view as it's drawn, through the iOS 16 delegate methods and the older pair for iOS 14 and 15, since the podspec still allows those. All new API is behind @available / API_AVAILABLE, and the build adds no warnings to MenuView.mm. On the iOS 18.6 simulator the preview shows the content. I think this also covers [iOS 18] Context menu preview is blank when using shouldOpenOnLongPress with React Native Fabric (New Architecture) #1201, but I haven't tried its exact case.
  • themeVariant. The button applied it to its own menu. In long-press mode the menu is presented from the component view, so I apply it there instead. That's what the old architecture already does, where the button is the view that holds the children, and it means the variant also reaches the children in this mode.
  • Old architecture. I don't think it needs this: LegacyMenuViewImplementation is the view itself and the children are mounted inside the button, so the hit test already reaches them. I read it but didn't build or run it.
  • Recycling. The mode is only switched when shouldOpenOnLongPress changes, so it relies on prepareForRecycle keeping _props, as showsMenuAsPrimaryAction already does. There's a comment about it in the code.
  • hitSlop. It lives in the button's point(inside:), and the button no longer takes touches in long-press mode, so hitSlop is not applied there. I can move it to the component view if you want it kept.
  • Android is unchanged.

About #1218: it covers a related case differently, with a new onPress prop for a tap on the anchor, driven by the button's touchUpInside. This PR adds no prop; the children keep their own press handling. The two do overlap on iOS: with this change the button no longer takes touches in long-press mode, so if both land, the tap for #1218 would have to come from the component view rather than the button. Happy to adjust either way.

I also added a small case to the example app: a long-press menu with a Pressable counter and a link-style Text inside.

Test Plan

Example app (React Native 0.81.1, new architecture, pods installed as in CI with RCT_USE_PREBUILT_RNCORE=1 RCT_USE_RN_DEP=1, Release build), on the iOS 26.5 and iOS 18.6 simulators. In the new example case I tapped the counter twice and the link once, then long-pressed the counter and the link:

master this branch
Two taps on the counter, one on the link counter 0, link 0 counter 2, link 1
Long press on the counter or the link Menu opens with the card as preview, counts don't change
Accessibility tree One element for the whole card Link and button exposed on their own
Tap on "Test" (tap-to-open) Opens Opens

Same results on both iOS versions.

Android (API 36 emulator, Debug): nothing changes. Taps already reach the children there. A long press opens the menu and the Pressable also fires on release, as it did before, because the Android MenuView doesn't cancel the JS touch.

yarn typescript, yarn lint and yarn test pass.

Not covered: a real device, listening with VoiceOver (I only checked the accessibility tree), the old architecture, and visionOS (I didn't build it).

I have screenshots of master against this branch on both iOS versions and on Android, and can add them here.

On the new architecture the menu's UIButton is the component's
contentView, which React Native keeps above the children, so it took
every touch: with shouldOpenOnLongPress a Pressable or a Text link inside
never received its press, and VoiceOver read the whole view as one
element because the view takes isAccessibilityElement from its
contentView.

When the menu opens on a long press, the UIContextMenuInteraction now
lives on the component view and the button steps out of touches and
accessibility. The interaction forwards to the button's own delegate
methods, so the menu, its title and the open/close events are unchanged.
The preview is the component view (iOS 16 and earlier delegate methods
both covered), and themeVariant is applied to the component view in
that mode. Tap-to-open menus are untouched.
@hugomn

hugomn commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Quick follow-up: I have now checked this on a real iPhone too, in a release build of our app. A link inside a long-press MenuView opens on tap, and a long press on the same content still opens the menu. Tap-to-open menus elsewhere in the app behave as before.

@Naturalclar Naturalclar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thank you! tested locally on my side as well.

@Naturalclar
Naturalclar merged commit 93cb5d7 into react-native-menu:master Nov 15, 2026
4 of 5 checks passed
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.

Pressable within MenuView is not pressable

2 participants