Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 71 ยท Components and Interaction

Modals, Alerts and Bottom Sheets

Show Modal, Alert.alert, action sheets, bottom sheets and toasts in React Native, handle the Android back button, and model a modal stack with live stand-ins.

Not everything belongs on a screen of its own. Confirming a delete, picking an option, showing a short "Saved" message or asking for a quick input all happen on top of what is already there. React Native offers several layers for this, from a built-in system dialog to a custom sliding sheet. Choosing the right one makes your app feel native instead of improvised.

This lesson goes from the lightest tool to the heaviest: toasts, Alert, action sheets, Modal and bottom sheets.

What runs on this site. System dialogs and modal windows are drawn by iOS and Android, so the real code is read-only here. The runnable examples are stand-ins: an alert() function that mimics the button-array contract and renders a dialog in HTML, and a reducer that manages a stack of modals, including the Android back button rule. The look and animations are the platform's own and cannot be reproduced in a browser.

Alert: the system dialog

Alert.alert shows the platform's own dialog, with no component to render. It is the standard way to confirm something destructive.

JSX
import { Alert } from 'react-native';

function confirmDelete(onDelete) {
  Alert.alert(
    'Delete note?',
    'This cannot be undone.',
    [
      { text: 'Cancel', style: 'cancel' },
      { text: 'Delete', style: 'destructive', onPress: onDelete },
    ],
    { cancelable: true }
  );
}

The arguments are a title, an optional message, an array of buttons and an options object. A button has text, an onPress callback and a style: default, cancel or destructive (red on iOS). Some platform rules matter:

  • iOS places the cancel button in its conventional position and makes destructive red. Android shows buttons as text actions, and supports at most three.
  • With cancelable: true on Android, tapping outside or pressing back dismisses the dialog, and onDismiss runs.
  • Alert.prompt (a dialog with a text field) exists on iOS only. On Android, build your own Modal.
  • Alert.alert is not promise-based. If you need await, wrap it in a Promise that resolves in each button's onPress.

Do not overuse alerts. They interrupt the flow, so keep them for confirmations and errors the person must see.

Alert.prompt in detail (iOS)

The full signature is Alert.prompt(title, message, callbackOrButtons, type, defaultValue, keyboardType):

Argument Meaning
callbackOrButtons either a function called with the entered text when the user presses OK, or an array of buttons whose onPress receives the text
type (the prompt type) "plain-text" (default), "secure-text" (hidden characters, for a password) or "login-password" (two fields: login and password; the callback receives both)
defaultValue the text the field starts with
keyboardType any TextInput keyboard type, such as "numeric"
JavaScript
Alert.prompt(
  'Rename list',
  'Choose a new name',
  (text) => rename(text.trim()),      // the simple form: one callback
  'plain-text',
  currentName,
);

Alert.prompt('Sign in', undefined, [
  { text: 'Cancel', style: 'cancel' },
  { text: 'Sign in', onPress: ({ login, password }) => signIn(login, password) },   // login-password gives an object
], 'login-password');

Because it exists only on iOS, wrap it in a helper that uses a small Modal with a TextInput on Android, so the rest of your code asks for "a text from the user" without checking the platform (see Platform-Specific Code).

Action sheets

When there are several choices, such as "Take photo", "Choose from library" and "Cancel", iOS has a native action sheet that slides up from the bottom.

JSX
import { ActionSheetIOS } from 'react-native';

ActionSheetIOS.showActionSheetWithOptions(
  {
    options: ['Cancel', 'Take photo', 'Choose from library', 'Delete'],
    cancelButtonIndex: 0,
    destructiveButtonIndex: 3,
  },
  (index) => {
    if (index === 1) openCamera();
  }
);

ActionSheetIOS is iOS only. For a cross-platform solution, use a library such as @expo/react-native-action-sheet, which uses the native sheet on iOS and a bottom-sheet look on Android, or build one with a Modal.

Pick the lightest layer

Toast A short message that fades by itself.
Alert Confirm or inform. One decision.
Action sheet A short list of choices.
Modal Any custom content on top.
1 / 2
An Alert.alert contract (stand-in)

For custom content, React Native has Modal. You control it with a boolean in state.

JSX
import { useState } from 'react';
import { Modal, View, Text, Pressable } from 'react-native';

export function InfoDialog() {
  const [visible, setVisible] = useState(false);

  return (
    <>
      <Pressable onPress={() => setVisible(true)}>
        <Text>Open</Text>
      </Pressable>

      <Modal
        visible={visible}
        animationType="slide"
        transparent
        onRequestClose={() => setVisible(false)}
      >
        <View style={{ flex: 1, justifyContent: 'flex-end', backgroundColor: 'rgba(0,0,0,0.4)' }}>
          <View style={{ backgroundColor: 'white', padding: 24, borderTopLeftRadius: 16, borderTopRightRadius: 16 }}>
            <Text>Hello from a modal.</Text>
            <Pressable onPress={() => setVisible(false)}>
              <Text>Close</Text>
            </Pressable>
          </View>
        </View>
      </Modal>
    </>
  );
}

Key props:

  • visible shows or hides it. Keep this in state.
  • animationType: none, slide or fade.
  • transparent: when true, you see the screen behind the modal, which is how you draw a dimmed backdrop and a card.
  • onRequestClose: called when the Android back button is pressed. React Native requires it on Android, so the back button has a defined behavior. Always set visible to false inside it. (onDismiss is a separate, iOS-only callback that runs after the modal has closed.)
  • presentationStyle (iOS): fullScreen, pageSheet, formSheet or overFullScreen, to get the stacked-card look.
  • statusBarTranslucent (Android) draws the modal under the status bar.

A Modal sits in its own native window above everything, including navigation headers and tab bars. This is its strength and its limit: it is excellent for dialogs and pickers, but it does not take part in your navigation history, so the back gesture and deep links ignore it. If a "modal" is really a screen with its own route, use a navigation presentation mode instead (see Stack Navigation with React Navigation).

Opening a second modal while the first is still closing can fail on iOS. If you must chain them, open the next one in the first one's onDismiss, or keep a single modal and swap its contents.

Bottom sheets

A bottom sheet is a panel that slides up from the bottom, often with snap points (a third of the screen, then half, then full) and drag to dismiss. You have three routes:

  1. Build it on Modal: as in the example above, with a Pressable backdrop that closes it on tap. Simple, but with no drag gesture.
  2. A library: @gorhom/bottom-sheet is the common choice; it uses Reanimated and Gesture Handler for smooth drags and snap points (see Reanimated and Gesture Handler).
  3. Navigation: Expo Router and React Navigation can present a screen as a sheet or formSheet, which gets the system's own sheet behavior and a real back stack.

Toasts

A toast is a brief message ("Saved", "Copied") that appears and fades away without blocking. Android has a built-in ToastAndroid.show('Saved', ToastAndroid.SHORT), but iOS has no equivalent, so cross-platform apps use a library such as react-native-toast-message or sonner-native, or a small custom component that animates in and out of a View placed near the root. Keep toasts short, never put the only copy of important information in one, and give them an accessibility announcement for screen readers.

Modeling a modal stack

Because modals are driven by state, you can describe all of them with a reducer. This is useful when dialogs can open from several places and must close in the right order, with the back button closing the topmost one first.

A modal stack with a back button (stand-in)

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which prop makes the Android back button close a Modal?

    onRequestClose is called when the Android back button is pressed. Set visible to false inside it. onDismiss is an iOS callback after the modal has closed.
  2. 2. Which tool is best for a quick yes/no confirmation before deleting something?

    Alert.alert uses the platform's own dialog, supports a cancel button and a red destructive button, and is meant for exactly this kind of one-decision confirmation.
  3. 3. Why does a Modal not appear in your navigation history?

    A Modal is driven by state (visible) and shown above everything, so deep links and the navigation back stack do not know about it. A screen presented as a modal route does.
  4. 4. Which statement about Alert.prompt is correct?

    Alert.prompt, a dialog with a text field, exists only on iOS. On Android you build your own Modal with a TextInput.

Summary

  • Pick the lightest layer that does the job: toast, Alert, action sheet, Modal or a bottom sheet.
  • Alert.alert(title, message, buttons, options) shows the system dialog; use style: 'cancel' and 'destructive'; Android allows three buttons and Alert.prompt is iOS only.
  • ActionSheetIOS is iOS only; use a library for cross-platform action sheets.
  • Modal is controlled by visible; set onRequestClose for the Android back button, transparent for backdrops and animationType for motion.
  • Bottom sheets come from a Modal, a library such as @gorhom/bottom-sheet, or a navigation sheet presentation; toasts need a library on iOS.
  • On this site the real code is read-only; the TryIts imitate the Alert contract and a modal stack in HTML.

Next, reach outside your app with Platform APIs: Linking, Share, Vibration, Appearance.