Example #1
0
 static alert(
   title: ?string,
   message?: ?string,
   buttons?: Array<{
     text: ?string;
     onPress: ?Function;
   }>
 ): void {
   var callbacks = [];
   var buttonsSpec = [];
   title = title || '';
   message = message || '';
   buttons = buttons || [DEFAULT_BUTTON];
   buttons.forEach((btn, index) => {
     callbacks[index] = btn.onPress;
     var btnDef = {};
     btnDef[index] = btn.text || DEFAULT_BUTTON_TEXT;
     buttonsSpec.push(btnDef);
   });
   RCTAlertManager.alertWithArgs({
     title,
     message,
     buttons: buttonsSpec,
   }, (id) => {
     var cb = callbacks[id];
     cb && cb();
   });
 }
 GLOBAL.alert = function(text) {
   var alertOpts = {
     title: 'Alert',
     message: '' + text,
     buttons: [{'cancel': 'OK'}],
   };
   RCTAlertManager.alertWithArgs(alertOpts, function () {});
 };
Example #3
0
 static alert(
   title: ?string,
   message?: ?string,
   buttons?: Array<{
     text?: string;
     onPress?: ?Function;
     style?: AlertButtonStyle;
   }>,
   type?: ?AlertType
 ): void {
   var callbacks = [];
   var buttonsSpec = [];
   var cancelButtonKey;
   var destructiveButtonKey;
   buttons && buttons.forEach((btn, index) => {
     callbacks[index] = btn.onPress;
     if (btn.style == 'cancel') {
       cancelButtonKey = String(index);
     } else if (btn.style == 'destructive') {
       destructiveButtonKey = String(index);
     }
     if (btn.text || index < (buttons || []).length - 1) {
       var btnDef = {};
       btnDef[index] = btn.text || '';
       buttonsSpec.push(btnDef);
     }
   });
   RCTAlertManager.alertWithArgs({
     title: title || undefined,
     message: message || undefined,
     buttons: buttonsSpec,
     type: type || undefined,
     cancelButtonKey,
     destructiveButtonKey,
   }, (id, value) => {
     var cb = callbacks[id];
     cb && cb(value);
   });
 }
Example #4
0
  /**
   * Create and display a prompt to enter some text.
   *
   * See http://facebook.github.io/react-native/docs/alertios.html#prompt
   */
  static prompt(
    title: ?string,
    message?: ?string,
    callbackOrButtons?: ?(((text: string) => void) | ButtonsArray),
    type?: ?AlertType = 'plain-text',
    defaultValue?: string,
    keyboardType?: string,
  ): void {
    if (typeof type === 'function') {
      console.warn(
        'You passed a callback function as the "type" argument to AlertIOS.prompt(). React Native is ' +
          'assuming  you want to use the deprecated AlertIOS.prompt(title, defaultValue, buttons, callback) ' +
          'signature. The current signature is AlertIOS.prompt(title, message, callbackOrButtons, type, defaultValue, ' +
          'keyboardType) and the old syntax will be removed in a future version.',
      );

      const callback = type;
      RCTAlertManager.alertWithArgs(
        {
          title: title || '',
          type: 'plain-text',
          defaultValue: message,
        },
        (id, value) => {
          callback(value);
        },
      );
      return;
    }

    let callbacks = [];
    const buttons = [];
    let cancelButtonKey;
    let destructiveButtonKey;
    if (typeof callbackOrButtons === 'function') {
      callbacks = [callbackOrButtons];
    } else if (callbackOrButtons instanceof Array) {
      callbackOrButtons.forEach((btn, index) => {
        callbacks[index] = btn.onPress;
        if (btn.style === 'cancel') {
          cancelButtonKey = String(index);
        } else if (btn.style === 'destructive') {
          destructiveButtonKey = String(index);
        }
        if (btn.text || index < (callbackOrButtons || []).length - 1) {
          const btnDef = {};
          btnDef[index] = btn.text || '';
          buttons.push(btnDef);
        }
      });
    }

    RCTAlertManager.alertWithArgs(
      {
        title: title || '',
        message: message || undefined,
        buttons,
        type: type || undefined,
        defaultValue,
        cancelButtonKey,
        destructiveButtonKey,
        keyboardType,
      },
      (id, value) => {
        const cb = callbacks[id];
        cb && cb(value);
      },
    );
  }
}},{key:'prompt',value:function prompt(











































title,
message,
callbackOrButtons)


{var type=arguments.length>3&&arguments[3]!==undefined?arguments[3]:'plain-text';var defaultValue=arguments[4];
if(typeof type==='function'){
console.warn(
'You passed a callback function as the "type" argument to AlertIOS.prompt(). React Native is '+
'assuming  you want to use the deprecated AlertIOS.prompt(title, defaultValue, buttons, callback) '+
'signature. The current signature is AlertIOS.prompt(title, message, callbackOrButtons, type, defaultValue) '+
'and the old syntax will be removed in a future version.');

var callback=type;
var defaultValue=message;
RCTAlertManager.alertWithArgs({
title:title||undefined,
type:'plain-text',
defaultValue:defaultValue},
function(id,value){
callback(value);
});
return;
}

var callbacks=[];
var buttons=[];
var cancelButtonKey;
var destructiveButtonKey;
if(typeof callbackOrButtons==='function'){
callbacks=[callbackOrButtons];
}else
if(callbackOrButtons instanceof Array){
callbackOrButtons.forEach(function(btn,index){
callbacks[index]=btn.onPress;
if(btn.style==='cancel'){
cancelButtonKey=String(index);
}else if(btn.style==='destructive'){
destructiveButtonKey=String(index);
}
if(btn.text||index<(callbackOrButtons||[]).length-1){
var btnDef={};
btnDef[index]=btn.text||'';
buttons.push(btnDef);
}
});
}

RCTAlertManager.alertWithArgs({
title:title||undefined,
message:message||undefined,
buttons:buttons,
type:type||undefined,
defaultValue:defaultValue,
cancelButtonKey:cancelButtonKey,
destructiveButtonKey:destructiveButtonKey},
function(id,value){
var cb=callbacks[id];
cb&&cb(value);
});
}}]);return AlertIOS;}();