AlertIOS.prompt()

static prompt(title, message?, callbackOrButtons?, type?, defaultValue?)

Prompt the user to enter some text.

  • title: string -- The dialog's title.
  • message: string -- An optional message that appears above the text input.
  • callbackOrButtons -- This 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'.

  • type: string -- This configures the text input. One of 'plain-text', 'secure-text' or 'login-password'.
  • defaultValue: string -- the default value for the text field.

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'
)
doc_React_Native
2016-06-23 04:23:24
Comments
Leave a Comment

Please login to continue.