-
Notifications
You must be signed in to change notification settings - Fork 28
/
modal.react.js
67 lines (61 loc) · 1.84 KB
/
modal.react.js
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
56
57
58
59
60
61
62
63
64
65
66
67
// @flow
import { useNavigation } from '@react-navigation/native';
import * as React from 'react';
import { View, TouchableWithoutFeedback, StyleSheet } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import KeyboardAvoidingView from './keyboard-avoiding-view.react.js';
import { useStyles } from '../themes/colors.js';
import type { ViewStyle } from '../types/styles.js';
type Props = $ReadOnly<{
+children: React.Node,
+containerStyle?: ViewStyle,
+modalStyle?: ViewStyle,
+safeAreaEdges?: $ReadOnlyArray<'top' | 'right' | 'bottom' | 'left'>,
+disableClosing?: boolean,
}>;
function Modal(props: Props): React.Node {
const navigation = useNavigation();
const close = React.useCallback(() => {
if (props.disableClosing) {
return;
}
if (navigation.isFocused()) {
navigation.goBack();
}
}, [navigation, props.disableClosing]);
const styles = useStyles(unboundStyles);
const { containerStyle, modalStyle, children, safeAreaEdges } = props;
return (
<SafeAreaView style={styles.container} edges={safeAreaEdges}>
<KeyboardAvoidingView
behavior="padding"
style={[styles.container, containerStyle]}
>
<TouchableWithoutFeedback onPress={close}>
<View style={StyleSheet.absoluteFill} />
</TouchableWithoutFeedback>
<View style={[styles.modal, modalStyle]}>{children}</View>
</KeyboardAvoidingView>
</SafeAreaView>
);
}
const unboundStyles = {
container: {
flex: 1,
justifyContent: 'center',
overflow: 'visible',
},
modal: {
backgroundColor: 'modalBackground',
borderColor: 'modalForegroundBorder',
borderWidth: 2,
borderRadius: 5,
flex: 1,
justifyContent: 'center',
marginBottom: 30,
marginHorizontal: 15,
marginTop: 100,
padding: 12,
},
};
export default Modal;