Skip to content

[SOLVED] Pressable Event duplicates longPress with navigation #108

@DMaxence

Description

@DMaxence

I recently updated react-native-ios-context-menu and noticed the behavior is not the same as before.

I have a list of cards and when you click it it navigate to the associated profile page.
Before that, the longpress was correctly handled, but now if I release my finger as soon as I feel the vibration of the longPress, the shortPress fires too.
But if I press long enough, the shortPress is not fired and everything works fine.

Expected behavior

RPReplay_Final1725883798.MP4

Not too long press behavior

RPReplay_Final1725883785.MP4

It was working very well on 1.X

My package.json:

"expo": "^51.0.24",
"@react-navigation/native": "^6.1.6",
"react-native-elements": "^3.4.3",
"react-native-ios-context-menu": "^2.5.1",
"react-native-ios-utilities": "^4.4.5",
"react": "18.2.0",
"react-native": "0.74.3"

The code I use for this :

import { ListItem } from "react-native-elements";
import { ContextMenuView } from "react-native-ios-context-menu";
import { useNavigation } from "@react-navigation/native";

const Card = () => {
  const navigation = useNavigation();

  return (
    <ContextMenuView
      menuConfig={{
        menuTitle: "",
        menuItems: [
          {
            actionKey: "key-00",
            actionTitle: "Edit",
          },
          {
            actionKey: "key-01",
            actionTitle: "Delete",
            menuAttributes: ["destructive"],
          },
        ],
      }}
      onPressMenuItem={({ nativeEvent }) => {
        switch (nativeEvent.actionKey) {
          case "key-00":
            navigation.navigate("EditPartner", { partnerId: partner._id });
            break;
          case "key-01":
            Alert.alert(
              "Are you sure you want to remove this partner?",
              "This action is irreversible and cannot be undone.",
              [
                {
                  text: "Cancel",
                  style: "cancel",
                },
                {
                  text: "Delete",
                  onPress: () => deletePartner(partner._id),
                  style: "destructive",
                },
              ]
            );
            break;
        }
      }}
    >
      <ListItem
        onPress={() =>
          navigation.navigate("Partner", {
            partnerId: partner._id,
          })
        }
      >
        <ListItem.Content>
          <ListItem.Title>
            <Text>Title</Text>
          </ListItem.Title>
        </ListItem.Content>
      </ListItem>
    </ContextMenuView>
  );
};

I can't find anywhere in the doc a navigation inside the ContextMenuView.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions