-
Notifications
You must be signed in to change notification settings - Fork 3k
/
index.web.js
53 lines (46 loc) · 1.88 KB
/
index.web.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
import React, {useState} from 'react';
import {InteractionManager} from 'react-native';
import withWindowDimensions from '../withWindowDimensions';
import BaseModal from './BaseModal';
import {propTypes, defaultProps} from './modalPropTypes';
import * as StyleUtils from '../../styles/StyleUtils';
import themeColors from '../../styles/themes/default';
import StatusBar from '../../libs/StatusBar';
import CONST from '../../CONST';
function Modal(props) {
const [previousStatusBarColor, setPreviousStatusBarColor] = useState();
const setStatusBarColor = (color = themeColors.appBG) => {
if (!props.fullscreen) {
return;
}
InteractionManager.runAfterInteractions(() => StatusBar.setBackgroundColor(color));
};
const hideModal = () => {
setStatusBarColor(previousStatusBarColor);
props.onModalHide();
};
const showModal = () => {
const statusBarColor = StatusBar.getBackgroundColor();
const isFullScreenModal =
props.type === CONST.MODAL.MODAL_TYPE.CENTERED || props.type === CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE || props.type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED;
setPreviousStatusBarColor(statusBarColor);
// If it is a full screen modal then match it with appBG, otherwise we use the backdrop color
setStatusBarColor(isFullScreenModal ? themeColors.appBG : StyleUtils.getThemeBackgroundColor(statusBarColor));
props.onModalShow();
};
return (
<BaseModal
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
onModalHide={hideModal}
onModalShow={showModal}
avoidKeyboard={false}
>
{props.children}
</BaseModal>
);
}
Modal.propTypes = propTypes;
Modal.defaultProps = defaultProps;
Modal.displayName = 'Modal';
export default withWindowDimensions(Modal);