React Native theorytheory 0/50 · 0%
Components · medium

25. Modal and overlay patterns

Confirmation dialogs and bottom sheets.

`Modal` renders content above the rest of the app, ideal for a transaction confirmation dialog that must be explicitly dismissed before continuing.

import { Modal, View, Text, Pressable } from "react-native";

function ConfirmModal({ visible, onConfirm, onCancel }: { visible: boolean; onConfirm: () => void; onCancel: () => void }) {
  return (
    <Modal visible={visible} transparent animationType="slide">
      <View>
        <Text>Confirm sending 0.5 ETH?</Text>
        <Pressable onPress={onConfirm}><Text>Confirm</Text></Pressable>
        <Pressable onPress={onCancel}><Text>Cancel</Text></Pressable>
      </View>
    </Modal>
  );
}

For richer, swipeable bottom sheets, community libraries like `@gorhom/bottom-sheet` provide better gesture handling than the basic `Modal`.

Check your understanding

  1. 1. What prop controls whether a Modal is shown?

  2. 2. Why use a confirmation modal before sending a transaction?

  3. 3. What library is popular for swipeable bottom sheets?