本文整理汇总了TypeScript中react-native.ActionSheetIOS.showActionSheetWithOptions方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ActionSheetIOS.showActionSheetWithOptions方法的具体用法?TypeScript ActionSheetIOS.showActionSheetWithOptions怎么用?TypeScript ActionSheetIOS.showActionSheetWithOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类react-native.ActionSheetIOS
的用法示例。
在下文中一共展示了ActionSheetIOS.showActionSheetWithOptions方法的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();
}
}
);
}
示例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();
}
});
}
}