forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModal.js
84 lines (75 loc) · 2.74 KB
/
Modal.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import PropTypes from 'prop-types';
import {View, useWindowDimensions} from 'react-native';
import ReactNativeModal from 'react-native-modal';
import {SafeAreaInsetsContext} from 'react-native-safe-area-context';
import CustomStatusBar from './CustomStatusBar';
import styles, {getSafeAreaPadding} from '../styles/styles';
import themeColors from '../styles/themes/default';
import getModalStyles from '../styles/getModalStyles';
import CONST from '../CONST';
const propTypes = {
// Callback method fired when the user requests to close the modal
onClose: PropTypes.func.isRequired,
// State that determines whether to display the modal or not
isVisible: PropTypes.bool.isRequired,
// Modal contents
children: PropTypes.node.isRequired,
// Style of modal to display
type: PropTypes.oneOf([
CONST.MODAL.MODAL_TYPE.CENTERED,
]),
};
const defaultProps = {
type: '',
};
const Modal = (props) => {
const {
modalStyle,
modalContainerStyle,
swipeDirection,
animationIn,
animationOut,
needsSafeAreaPadding
} = getModalStyles(props.type, useWindowDimensions());
return (
<ReactNativeModal
onBackdropPress={props.onClose}
onBackButtonPress={props.onClose}
onSwipeComplete={props.onClose}
swipeDirection={swipeDirection}
isVisible={props.isVisible}
backdropColor={themeColors.modalBackdrop}
backdropOpacity={0.5}
backdropTransitionOutTiming={0}
style={modalStyle}
animationIn={animationIn}
animationOut={animationOut}
>
<CustomStatusBar />
<SafeAreaInsetsContext.Consumer>
{(insets) => {
const {paddingTop, paddingBottom} = getSafeAreaPadding(insets);
return (
<View
style={{
...styles.defaultModalContainer,
paddingBottom,
...modalContainerStyle,
// This padding is based on the insets and could not neatly be
// returned by getModalStyles to avoid passing this inline.
paddingTop: needsSafeAreaPadding ? paddingTop : 20,
}}
>
{props.children}
</View>
);
}}
</SafeAreaInsetsContext.Consumer>
</ReactNativeModal>
);
};
Modal.propTypes = propTypes;
Modal.defaultProps = defaultProps;
Modal.displayName = 'Modal';
export default Modal;