Skip to content

feat: add onPress to tap the anchor while long-press opens the menu#1218

Open
zcmgyu wants to merge 1 commit into
react-native-menu:masterfrom
zcmgyu:feat/anchor-onpress-with-longpress-menu
Open

feat: add onPress to tap the anchor while long-press opens the menu#1218
zcmgyu wants to merge 1 commit into
react-native-menu:masterfrom
zcmgyu:feat/anchor-onpress-with-longpress-menu

Conversation

@zcmgyu

@zcmgyu zcmgyu commented Jul 24, 2026

Copy link
Copy Markdown

The problem

Right now, if you set shouldOpenOnLongPress, the menu opens on long-press, but a normal tap on the anchor does nothing. There's no way to handle it.

That makes a very common mobile pattern impossible:

▎ Tap a row to open it, long-press it for a context menu (rename, delete, …).

On iOS the anchor is a native UIButton, so it quietly swallows the tap and never tells JS about it.

The fix

A new onPress prop. When shouldOpenOnLongPress is on:

  • Tap → fires onPress
  • Long-press → opens the menu (unchanged)

So the anchor is now both tappable and long-pressable.

<MenuView
  shouldOpenOnLongPress
  onPress={() => openItem(item)}        // 👈 tap
  onPressAction={({ nativeEvent }) => {  // long-press → menu item chosen
    if (nativeEvent.event === 'delete') deleteItem(item)
  }}
  actions={[{ id: 'delete', title: 'Delete', attributes: { destructive: true } }]}
>
  <Row item={item} />
</MenuView>

How it works

The native side reports the anchor tap through the existing onPressAction channel using a reserved id ("rnmenu:onPress"), and index.tsx turns that into the public onPress callback:

  • iOS: UIButton's touchUpInside (only when the menu isn't the primary tap action), plus the iOS <14 action-sheet tap path
  • Android: onSingleTapUp while in long-press mode

No breaking changes

onPress only fires in long-press mode. Regular tap-to-open menus (shouldOpenOnLongPress={false}) behave exactly as before.

Changes

  • New onPress prop (types + JS)
  • iOS: MenuViewImplementation.swift, ActionSheetView.swift
  • Android: MenuView.kt
  • Docs: README

@zcmgyu
zcmgyu requested a review from Naturalclar as a code owner July 24, 2026 07:18
With shouldOpenOnLongPress the menu opens on long press, but the
anchor's normal tap was swallowed by the native UIButton (iOS) with no
way to handle it. Add an `onPress` prop so a tap of the anchor invokes
onPress while long-press still opens the menu — the anchor becomes both
tappable and long-pressable.

Native forwards the anchor tap through the existing onPressAction channel
with a sentinel id ("rnmenu:onPress"): iOS via UIButton touchUpInside
(guarded to non-primary-action mode) plus the iOS<14 action-sheet tap,
Android via onSingleTapUp in long-press mode. index.tsx translates the
sentinel into the onPress callback. Tap-to-open menus
(shouldOpenOnLongPress=false) are unaffected.
@zcmgyu
zcmgyu force-pushed the feat/anchor-onpress-with-longpress-menu branch from 15cd5c9 to a402bbf Compare July 24, 2026 07:20
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