Alert API launches an alert dialog with a specified title and message. It works on both iOS and Android, allowing you to show static alerts or prompt users for input (iOS only).
Import
Methods
alert()
Displays a native alert dialog with optional buttons.The dialog’s title. Pass
null or empty string for no title.An optional message that appears below the title.
An optional array of buttons. If not provided, a default “OK” button is shown.
- iOS: Supports any number of buttons
- Android: Maximum of 3 buttons (neutral, negative, positive)
Optional configuration object.Properties:
cancelable(boolean, Android only): Whether the alert can be dismissed by tapping outsideonDismiss(function, Android only): Callback when alert is dismisseduserInterfaceStyle(string): Can be ‘light’, ‘dark’, or ‘unspecified’
AlertButton Type
prompt() (iOS only)
Displays a native prompt dialog with a text input field.The dialog’s title.
An optional message that appears below the title.
Either a callback function that receives the input text, or an array of buttons.
The type of input field. Options:
'default': Standard text input'plain-text': Plain text input'secure-text': Secure text entry (password)'login-password': Username and password fields
'plain-text'The default text in the input field.
The keyboard type for the input field (e.g., ‘numeric’, ‘email-address’).
Same options as
alert() method.Examples
Basic Alert
Alert with Buttons
iOS Prompt
Prompt with Login Fields
Android Cancelable Alert
Platform Differences
Button Handling
iOS:- Supports unlimited number of buttons
- Buttons can have
styleproperty:'default','cancel', or'destructive' - The
isPreferredproperty highlights a specific button
- Maximum of 3 buttons
- Button order matters: [neutral, negative, positive]
- The last button in the array is displayed as the positive action
Button Positioning
Best Practices
On Android, alerts are dismissed when the app goes to the background. Consider this when implementing critical user flows.