Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking on background to Close triggers the press event of the pressed area #853

Open
mabdurrafey-afl opened this issue Jul 10, 2024 · 3 comments

Comments

@mabdurrafey-afl
Copy link

No description provided.

@zollipaul
Copy link

+1 here. workaround for me is to track, if menu is open somehow and then disable all other elements or put an absolute view over the rest to block the touch event. not a good solution though. Someone has other ideas? Is this a bug report or feature request?

@mabdurrafey-afl
Copy link
Author

@zollipaul this is a big issue, leading to thoughts to replace this package :-(

@fbeccaceci
Copy link

I wrapped the component this way

import { useState } from "react";
import { Pressable, ViewStyle, View, Dimensions } from "react-native";
import { MenuView, MenuComponentProps } from "@react-native-menu/menu";
import { Portal } from "@gorhom/portal";

export type MenuProps = MenuComponentProps;

export default function Menu({ children, ...props }: MenuProps) {
  const [isOpen, setIsOpen] = useState(false);

  const onPressAction: MenuComponentProps["onPressAction"] = ({ nativeEvent }) => {
    setIsOpen(false);
    props.onPressAction?.({ nativeEvent });
  };

  return (
    <MenuView {...props} onPressAction={onPressAction}>
      <Pressable onPress={() => setIsOpen(true)}>{children}</Pressable>
      <Portal>
        {isOpen && <Pressable style={absoluteViewStyle} onPress={() => setIsOpen(false)} />}
      </Portal>
    </MenuView>
  );
}

const screenSize = Dimensions.get("screen");

const absoluteViewStyle: ViewStyle = {
  position: "absolute",
  top: 0,
  left: 0,
  width: screenSize.width,
  height: screenSize.height,

  zIndex: 999,
};

And it makes it work more as you would expect, at least on ios, haven't tried it on android

hyoban added a commit to hyoban/follow-app that referenced this issue Aug 17, 2024
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

No branches or pull requests

3 participants