-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathModal.js
64 lines (57 loc) · 1.53 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
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';
let closeModal;
let onModalClose;
/**
* Allows other parts of the app to call modal close function
*
* @param {Function} [onClose]
*/
function setCloseModal(onClose) {
closeModal = onClose;
}
/**
* Close modal in other parts of the app
*
* @param {Function} [onModalCloseCallback]
* @param {Boolean} isNavigating
*/
function close(onModalCloseCallback, isNavigating = true) {
if (!closeModal) {
// If modal is already closed, no need to wait for modal close. So immediately call callback.
if (onModalCloseCallback) { onModalCloseCallback(); }
onModalClose = null;
return;
}
onModalClose = onModalCloseCallback;
closeModal(isNavigating);
}
function onModalDidClose() {
if (!onModalClose) { return; }
onModalClose();
onModalClose = null;
}
/**
* Allows other parts of the app to know when a modal has been opened or closed
*
* @param {Boolean} isVisible
*/
function setModalVisibility(isVisible) {
Onyx.merge(ONYXKEYS.MODAL, {isVisible});
}
/**
* Allows other parts of app to know that an alert modal is about to open.
* This will trigger as soon as a modal is opened but not yet visible while animation is running.
*
* @param {Boolean} isVisible
*/
function willAlertModalBecomeVisible(isVisible) {
Onyx.merge(ONYXKEYS.MODAL, {willAlertModalBecomeVisible: isVisible});
}
export {
setCloseModal,
close,
onModalDidClose,
setModalVisibility,
willAlertModalBecomeVisible,
};