當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript react-native.ActionSheetIOS類代碼示例

本文整理匯總了TypeScript中react-native.ActionSheetIOS的典型用法代碼示例。如果您正苦於以下問題:TypeScript ActionSheetIOS類的具體用法?TypeScript ActionSheetIOS怎麽用?TypeScript ActionSheetIOS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ActionSheetIOS類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _actions

 _actions(event: any) {
   var todoMVC: TodoMVC = this.navigator.activeComponent;
   ActionSheetIOS.showActionSheetWithOptions({
       title: 'Actions',
       options: ['Reset list', 'Empty list', 'Fill list with 100 items', 'Save', 'Load', 'Cancel'],
       cancelButtonIndex: 5},
     (actionIndex) => {
       if (actionIndex == 0 && todoMVC) {
         todoMVC.reset();
       } else if (actionIndex == 1 && todoMVC) {
         todoMVC.empty();
       } else if (actionIndex == 2 && todoMVC) {
         todoMVC.full();
       } else if (actionIndex == 3 && todoMVC) {
         todoMVC.save();
       } else if (actionIndex == 4 && todoMVC) {
         todoMVC.load();
       }
     }
   );
 }
開發者ID:darocha,項目名稱:react-native-renderer,代碼行數:21,代碼來源:kitchensink.ts

示例2: openActionSheet

export function openActionSheet(config: IOpenActionSheetConfig) {

  if (Platform.OS === 'ios') {
    const opts = {} as ActionSheetIOSOptions;

    // Map values
    opts.options = config.options.map(getOptionValue);

    if (config.cancel === true) {
      opts.cancelButtonIndex = opts.options.length;
      opts.options.push('Cancel');
    }

    opts.title = config.title;
    opts.message = config.message;
    opts.tintColor = config.tintColor;
    opts.destructiveButtonIndex = config.destructiveButtonIndex;

    ActionSheetIOS.showActionSheetWithOptions(
      opts,
      (index: number) => {
        if (config.options.length === index) {
          if (typeof config.onCancel === 'function') {
            config.onCancel();
          }
          return;
        }
        if (typeof config.onSelect === 'function' && config.options.length > index) {
          return config.onSelect(config.options[index], index);
        }
      },
    );
  }

  if (Platform.OS === 'android') {

    // Convert options to { id, label }
    const items = config.options.map((option: any, index) => ({
      id: getOptionKey(option, index),
      label: getOptionValue(option),
    }));

    let type = DialogAndroid.listPlain;
    if (config.type === 'radio') {
      type = DialogAndroid.listRadio;
    }
    if (config.type === 'checkbox') {
      type = DialogAndroid.listCheckbox;
    }

    DialogAndroid.showPicker(config.title, config.message, {
      type,
      items,
      neutralIsClear: config.clear ? true : false,
      neutralText: config.clear ? 'Clear' : undefined,
      negativeText: config.cancel ? 'Cancel' : undefined,
      selectedId: config.selectedId,
      selectedIds: config.selectedIds,
    })
    .then(({ selectedItem, selectedItems }: any) => {
      if (selectedItem) {
        const index = items.findIndex(option => option.id === selectedItem.id);
        if (typeof config.onSelect === 'function') {
          return config.onSelect(config.options[index], index);
        }
      } else if (selectedItems) {
        if (typeof config.onMultiSelect === 'function') {
          return config.onMultiSelect(selectedItems);
        }
      } else if (typeof config.onCancel === 'function') {
        return config.onCancel();
      }
    });
  }
}
開發者ID:birkir,項目名稱:kvikmyndr-app,代碼行數:75,代碼來源:openActionSheet.ts


注:本文中的react-native.ActionSheetIOS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。