Skip to content

presentAlert ​

Opens an alert dialog with a title, an optional message and action buttons. Tapping any button closes the alert, then runs that button's onPress.

variant: 'alert'
tsx
import {presentAlert, useNativeSheet} from 'react-native-universal-sheet';

function DeleteButton({onDelete}: {onDelete: () => void}) {
  const sheet = useNativeSheet();

  return (
    <Button
      title="Delete"
      onPress={() =>
        presentAlert(sheet, {
          id: 'confirm-delete',
          title: 'Delete this photo?',
          message: 'It will be removed from all your devices.',
          actions: [
            {label: 'Cancel', style: 'cancel'},
            {label: 'Delete', style: 'destructive', onPress: onDelete},
          ],
        })
      }
    />
  );
}

Signature ​

ts
presentAlert(manager: SheetManager, options: AlertOptions): SheetResult

Options ​

OptionTypeDefaultDescription
idstringrequiredSheet id
titlestringrequiredAlso used as the accessibility label
messagestring—Body text
actionsSheetAction[]one OK buttonButtons, top to bottom
appearanceSheetAppearance—Surface colour, radius, width…
stylesSheetStyles—contentStyle, titleStyle, messageStyle, buttonStyle, buttonTextStyle

SheetAction ​

FieldTypeDescription
labelstringButton text. Must be unique within the alert
style'default' | 'destructive' | 'cancel'destructive renders red
onPress() => voidRuns after the alert starts closing

Styled alert ​

tsx
presentAlert(sheet, {
  id: 'logout',
  title: 'Log out?',
  message: 'You will need to sign in again.',
  actions: [{label: 'Stay'}, {label: 'Log out', style: 'destructive', onPress: logout}],
  appearance: {backgroundColor: '#FFFFFF', cornerRadius: 20, width: 300},
  styles: {
    titleStyle: {fontSize: 20, textAlign: 'center'},
    messageStyle: {textAlign: 'center'},
    buttonTextStyle: {fontWeight: '600'},
  },
});

Default look ​

PartDefault
Bodypadding: 20, gap: 12
Title18 pt, weight 600, #111
Message15 pt, #444
Button text16 pt, #0a62d6; destructive #d62c2c

Every value can be overridden with styles.

Alert defaults ​

The alert variant has a backdrop, no drag, no keyboard handling and no nested scrolling. The Android back button closes it.

Released under the MIT License.