Skip to content

Commit 7ad735a

Browse files
fix(mobile): long-pressing a thread row no longer navigates into the thread
On iOS the long-press context menu rows are a plain Pressable wrapped in the patched MenuView: the native button is touch-transparent so the row keeps handling taps, and the UIContextMenuInteraction lives on the host component view. RN's Fabric touch handler refuses to be prevented by recognizers inside the RN view tree (RCTSurfaceTouchHandler canBePreventedByGestureRecognizer), so the touch is never cancelled when the menu opens - on finger-up Pressability fired onPress and navigated with the menu already showing. Releasing just under the ~500ms menu threshold navigated too, since a Pressable without onLongPress fires onPress after any hold duration. Mirror the Android branch in ControlPillMenu: in long-press mode, clone the child with a no-op onLongPress and delayLongPress of 350ms. Once onLongPress dispatches, Pressability swallows the release, so holds past 350ms can only open the menu, never tap through. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent bd18d8d commit 7ad735a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎apps/mobile/src/components/ControlPill.tsx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,25 @@ export function ControlPillMenu(
133133
}
134134

135135
const { className: _className, ...menuProps } = props;
136+
let children = menuProps.children;
137+
// In long-press mode the wrapped pressable still receives the touch (the
138+
// patched MenuView button is touch-transparent) and RN's Fabric touch
139+
// handler is never cancelled by the in-tree UIContextMenuInteraction, so a
140+
// bare onPress would fire on finger-up even after the menu opened — and
141+
// also on a long press released just under the menu threshold. A dispatched
142+
// onLongPress makes Pressability swallow the release, so holds past 350ms
143+
// (below the ~500ms context-menu threshold) can only open the menu, never
144+
// tap through.
145+
if (props.shouldOpenOnLongPress && isValidElement(children)) {
146+
const child = children as ReactElement<{ onLongPress?: () => void; delayLongPress?: number }>;
147+
children = cloneElement(child, {
148+
onLongPress: child.props.onLongPress ?? (() => undefined),
149+
delayLongPress: child.props.delayLongPress ?? 350,
150+
});
151+
}
136152
return (
137153
<MenuView {...menuProps} themeVariant={isDarkMode ? "dark" : "light"}>
138-
{menuProps.children}
154+
{children}
139155
</MenuView>
140156
);
141157
}

0 commit comments

Comments
 (0)