-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (34 loc) · 1.44 KB
/
index.js
File metadata and controls
40 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { NativeModules, Platform } from 'react-native';
const { ActionSheet } = NativeModules;
const processColor = require('react-native/Libraries/StyleSheet/processColor');
const invariant = require('invariant');
export default {
showActionSheetWithOptions: (options, callback) => {
invariant(
typeof options === 'object' && options !== null,
'Options must be a valid object',
);
invariant(typeof callback === 'function', 'Must provide a valid callback');
invariant(ActionSheet, "ActionSheetManager does't exist");
const { tintColor, destructiveButtonIndex, ...remainingOptions } = options;
let destructiveButtonIndices = null;
if (Array.isArray(destructiveButtonIndex)) {
destructiveButtonIndices = destructiveButtonIndex;
} else if (typeof destructiveButtonIndex === 'number') {
destructiveButtonIndices = [destructiveButtonIndex];
}
const processedTintColor = processColor(tintColor);
invariant(
processedTintColor == null || typeof processedTintColor === 'number',
'Unexpected color given for ActionSheetIOS.showActionSheetWithOptions tintColor',
);
ActionSheet.showActionSheetWithOptions(
{
...remainingOptions,
tintColor: processedTintColor,
destructiveButtonIndices,
},
callback,
);
}
};