react-native 虚拟按键

 BackHandler.addEventListener("hardwareBackPress", function () {
      if (!isEmpty(localCart.deliverAddress)) {
        dispatch({
          type: "changSheetState",
          payload: {
            showSheet: false,
            height: 380,
            children: () => null,
            onCloseEnd: () => {},
            sheetTitle: "",
          },
        });
        setShowMap({ mapVisible: false, stopPermission: true });
      }
      if (currentRoute === undefined) {
        return true;
      }
      if (currentRoute.currentPage === "ExploreScreen") {
        RNAlert.alert("Hold on!", "Are you sure you want to exit App?", [
          {
            text: "Cancel",
            onPress: () => null,
            style: "cancel",
          },
          { text: "YES", onPress: () => BackHandler.exitApp() },
        ]);
        return true;
      }
      if (
        currentRoute?.currentPage !== "LoginScreeen" ||
        currentRoute?.currentPage !== "LogOutScreen"
      ) {
        NavigationService.goBack();
        /**
         * When true is returned the event will not be bubbled up
         * & no other back action will execute
         */
        return true;
      }
      return true;
    });
// React.useEffect(
  //   () =>
  //     navigation.addListener("beforeRemove", (e) => {
  //       e.preventDefault();
  //     }),
  //   [navigation]
  // );

你可能感兴趣的:(react-native 虚拟按键)