react-native-context-menu-view icon indicating copy to clipboard operation
react-native-context-menu-view copied to clipboard

On press is called when context menu being released too quickly

Open youngDevelopman opened this issue 3 years ago • 8 comments

I have the following code structure for the flat list items:

<ContextMenu
    previewBackgroundColor={"black"}
    actions={[{ title: "Open article" }, { title: "Remove from favourites", destructive: true, systemIcon: 'trash' }]}
    onPress={(e) => {....}
    }}
>
    <TouchableOpacity onPress={() => onPress(item.id)}>
          ...
    </TouchableOpacity>
</ContextMenu>

When I tap on an item and hold it then everything is okay, but when I release it too quickly then the onPress method is called that, in my case, leads to redirecting to another page.

Is there a way to track whether the menu is currently opened, so I can block the redirecting to another screen until it's closed?

Here is the video showcasing the bug:

https://user-images.githubusercontent.com/31933374/179400146-5d819a23-66ef-4481-8274-fbc264a0e224.MP4

youngDevelopman avatar Jul 17 '22 13:07 youngDevelopman

I am not having this problem in iOS, but the problem is still there in android.

florianrohrauer avatar Aug 10 '22 11:08 florianrohrauer

Hi, can u add timeout for your action?

fukemy avatar Aug 24 '22 15:08 fukemy

I'm experiencing the same problem on Android, it's working well on iOS. Does anyone have a workaround?

Edit: Found a workaround, on your TouchableOpacity element, pass an empty function to onLongPress and that will fix it.

focux avatar Mar 03 '23 17:03 focux

Thanks @focux . His solution works, you might be able to intercept the event to stop propagation of the pressabke if it's grabbed by the long press but I have not tried

mpiannucci avatar Mar 05 '23 15:03 mpiannucci

I am using this library with Expo Router. Somehow my screen isn't navigating to any screen anymore with router.push() on iOS when I opened and closed the ContextMenu before. But this only happens on a physical device. On the simulator its working... Does somebody have the same problem?

SalihColak avatar Jan 17 '24 12:01 SalihColak

Hi! Who still having this having issue and passing empty function to your onLongPress property didn't help you. Try add delayLongPress property to your TouchableOpacity or Pressable element and set it to 250 (default 500)

DimanVorosh avatar Feb 26 '24 16:02 DimanVorosh

@focux @DimanVorosh solution seems to work but I hope to see a fix for this in the near future. thanks for the great package also adding delayLongPress={250} seems to do the trick

shanoysinc avatar Jun 30 '24 17:06 shanoysinc