Expo

Documentation

AlertIOS

AlertIOS provides functionality to create an iOS alert dialog with a message or create a prompt for user input.
Creating an iOS alert:
AlertIOS.alert('Sync Complete', 'All your data are belong to us.');
Creating an iOS prompt:
AlertIOS.prompt('Enter a value', null, (text) =>
  console.log('You entered ' + text),
);
We recommend using the Alert.alert method for cross-platform support if you don't need to create iOS-only prompts.


Reference

static alert(title: string, [message]: string, [callbackOrButtons]: ?(() => void), ButtonsArray, [type]: AlertType): [object Object]
Create and display a popup alert.
Parameters:
NameTypeRequiredDescription
titlestringYesThe dialog's title. Passing null or '' will hide the title.
messagestringNoAn optional message that appears below the dialog's title.
callbackOrButtons?(() => void),ButtonsArrayNoThis optional argument should be either a single-argument function or an array of buttons. If passed a function, it will be called when the user taps 'OK'. If passed an array of button configurations, each button should include a text key, as well as optional onPress and style keys. style should be one of 'default', 'cancel' or 'destructive'.
typeAlertTypeNoDeprecated, do not use.
Example with custom buttons:
AlertIOS.alert(
  'Update available',
  'Keep your app up to date to enjoy the latest features',
  [
    {
      text: 'Cancel',
      onPress: () => console.log('Cancel Pressed'),
      style: 'cancel',
    },
    {
      text: 'Install',
      onPress: () => console.log('Install Pressed'),
    },
  ],
);

static prompt(title: string, [message]: string, [callbackOrButtons]: ?((text: string) => void), ButtonsArray, [type]: AlertType, [defaultValue]: string, [keyboardType]: string): [object Object]
Create and display a prompt to enter some text.
Parameters:
NameTypeRequiredDescription
titlestringYesThe dialog's title.
messagestringNoAn optional message that appears above the text input.
callbackOrButtons?((text: string) => void),ButtonsArrayNoThis optional argument should be either a single-argument function or an array of buttons. If passed a function, it will be called with the prompt's value when the user taps 'OK'. If passed an array of button configurations, each button should include a text key, as well as optional onPress and style keys (see example). style should be one of 'default', 'cancel' or 'destructive'.
typeAlertTypeNoThis configures the text input. One of 'plain-text', 'secure-text' or 'login-password'.
defaultValuestringNoThe default text in text input.
keyboardTypestringNoThe keyboard type of first text field(if exists). One of 'default', 'email-address', 'numeric', 'phone-pad', 'ascii-capable', 'numbers-and-punctuation', 'url', 'number-pad', 'name-phone-pad', 'decimal-pad', 'twitter' or 'web-search'.
Example with custom buttons:
AlertIOS.prompt(
  'Enter password',
  'Enter your password to claim your $1.5B in lottery winnings',
  [
    {
      text: 'Cancel',
      onPress: () => console.log('Cancel Pressed'),
      style: 'cancel',
    },
    {
      text: 'OK',
      onPress: (password) => console.log('OK Pressed, password: ' + password),
    },
  ],
  'secure-text',
);
,
Example with the default button and a custom callback:
AlertIOS.prompt(
  'Update username',
  null,
  (text) => console.log('Your username is ' + text),
  null,
  'default',
);

An Alert button type
Type
\$Enum
Constants:
ValueDescription
defaultDefault alert with no inputs
plain-textPlain text input alert
secure-textSecure text input alert
login-passwordLogin and password alert

An Alert button style
Type
\$Enum
Constants:
ValueDescription
defaultDefault button style
cancelCancel button style
destructiveDestructive button style

Array or buttons
Type
Array
Properties:
NameTypeDescription
[text]stringButton label
[onPress]functionCallback function when button pressed
[style]AlertButtonStyleButton style
Constants:
ValueDescription
textButton label
onPressCallback function when button pressed
styleButton style