2024-03-09 04:59:47 +01:00
|
|
|
// ActionSheet.ts
|
|
|
|
import { Alert, InteractionManager } from 'react-native';
|
|
|
|
import { ActionSheetOptions, CompletionCallback } from './ActionSheet.common';
|
|
|
|
|
|
|
|
export default class ActionSheet {
|
|
|
|
static showActionSheetWithOptions(options: ActionSheetOptions, completion: CompletionCallback): void {
|
|
|
|
InteractionManager.runAfterInteractions(() => {
|
|
|
|
const alertOptions = options.options.map((option, index) => {
|
2024-03-09 05:08:07 +01:00
|
|
|
let style: 'default' | 'cancel' | 'destructive' = 'default';
|
2024-03-09 04:59:47 +01:00
|
|
|
if (index === options.destructiveButtonIndex) {
|
|
|
|
style = 'destructive';
|
|
|
|
} else if (index === options.cancelButtonIndex) {
|
|
|
|
style = 'cancel';
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
text: option,
|
|
|
|
onPress: () => completion(index),
|
|
|
|
style,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
Alert.alert(options.title || '', options.message || '', alertOptions, { cancelable: !!options.cancelButtonIndex });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|