-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
55 lines (50 loc) · 1.25 KB
/
Copy pathutils.ts
File metadata and controls
55 lines (50 loc) · 1.25 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Alert } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
export function clamp(val: number, min: number, max: number)
{
if (val < min)
return min;
else if (val > max)
return max;
else
return val;
}
interface ConfirmAlertOptions
{
acceptText?: string;
acceptStyle?: 'default' | 'destructive' | 'cancel';
cancelText?: string;
cancelStyle?: 'default' | 'destructive' | 'cancel';
}
export function confirmAlert(message: string, title?: string, options?: ConfirmAlertOptions): Promise<boolean>
{
return new Promise((resolve, reject) => {
console.log('wat');
Alert.alert(title ?? 'Confirm', message, [
{
text: options?.cancelText ?? 'No',
style: options?.cancelStyle ?? 'default',
isPreferred: true,
onPress: () => resolve(false),
},
{
text: options?.acceptText ?? 'Yes',
style: options?.acceptStyle ?? 'destructive',
onPress: () => resolve(true),
}
])
});
}
/**
* Returns style props that can be passed to a scroll views content container to respect the safe area
*/
export function useSafeAreaStyle()
{
const insets = useSafeAreaInsets();
return {
paddingLeft: insets.left,
paddingRight: insets.right,
paddingTop: insets.top,
paddingBottom: insets.bottom
}
}