Skip to main content

useCanDismiss

useCanDismiss is a hook that checks whether an overlay can close, such as a custom panel beneath a second dialog.

Import

import { useCanDismiss } from '@vortexlabs/vortex-native';
import { Button, useCanDismiss } from "@vortexlabs/vortex-native";
import { Modal, Text } from "react-native";

type Props = {
  open: boolean;
  onClose: () => void;
};

export const OrderPanel = (props: Props) => {
  const { open, onClose } = props;
  const canDismiss = useCanDismiss({ active: open });
  const requestClose = () => {
    if (canDismiss()) onClose();
  };

  return (
    <Modal visible={open} onRequestClose={requestClose} animationType="none">
      <Text>Order details</Text>
      <Button onPress={requestClose}>Close details</Button>
    </Modal>
  );
};

Features

  • Checks dismissal order across native overlays.
  • Allows a non-modal layer to participate without blocking layers underneath.

Exit Animations

Keep active true until the exit animation finishes so a second press cannot close the layer underneath. Call the returned function in the dismissal handler.

Nonmodal Overlays

Pass modal: false to let overlays below this layer handle their own dismissal.