Skip to content

Commit c42c98a

Browse files
authored
Merge pull request #61372 from software-mansion-labs/fix/modal-status-bar
Fix color of top status bar when opening modals
2 parents 6869b04 + 382bd6a commit c42c98a

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/components/Modal/BaseModal.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function BaseModal(
5353
innerContainerStyle = {},
5454
outerStyle,
5555
onModalShow = () => {},
56+
onModalWillShow,
57+
onModalWillHide,
5658
propagateSwipe,
5759
fullscreen = true,
5860
animationIn,
@@ -276,7 +278,11 @@ function BaseModal(
276278
onModalShow={handleShowModal}
277279
propagateSwipe={propagateSwipe}
278280
onModalHide={hideModal}
279-
onModalWillShow={saveFocusState}
281+
onModalWillShow={() => {
282+
saveFocusState();
283+
onModalWillShow?.();
284+
}}
285+
onModalWillHide={onModalWillHide}
280286
onDismiss={handleDismissModal}
281287
onSwipeComplete={() => onClose?.()}
282288
swipeDirection={swipeDirection}

src/components/Modal/BottomDockedModal/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function BottomDockedModal({
101101

102102
useEffect(
103103
() => () => {
104-
onModalWillHide();
105104
if (handleRef.current) {
106105
InteractionManager.clearInteractionHandle(handleRef.current);
107106
}

src/components/Modal/index.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = (
2121
};
2222

2323
const hideModal = () => {
24-
setStatusBarColor(previousStatusBarColor);
2524
onModalHide();
2625
if ((window.history.state as WindowState)?.shouldGoBack) {
2726
window.history.back();
@@ -33,6 +32,21 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = (
3332
});
3433

3534
const showModal = () => {
35+
if (shouldHandleNavigationBack) {
36+
window.history.pushState({shouldGoBack: true}, '', null);
37+
window.addEventListener('popstate', handlePopStateRef.current);
38+
}
39+
onModalShow?.();
40+
};
41+
42+
useEffect(
43+
() => () => {
44+
window.removeEventListener('popstate', handlePopStateRef.current);
45+
},
46+
[],
47+
);
48+
49+
const onModalWillShow = () => {
3650
const statusBarColor = StatusBar.getBackgroundColor() ?? theme.appBG;
3751

3852
const isFullScreenModal =
@@ -46,27 +60,22 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = (
4660
// If it is a full screen modal then match it with appBG, otherwise we use the backdrop color
4761
setStatusBarColor(isFullScreenModal ? theme.appBG : StyleUtils.getThemeBackgroundColor(statusBarColor));
4862
}
49-
50-
if (shouldHandleNavigationBack) {
51-
window.history.pushState({shouldGoBack: true}, '', null);
52-
window.addEventListener('popstate', handlePopStateRef.current);
53-
}
54-
onModalShow?.();
63+
rest.onModalWillShow?.();
5564
};
5665

57-
useEffect(
58-
() => () => {
59-
window.removeEventListener('popstate', handlePopStateRef.current);
60-
},
61-
[],
62-
);
66+
const onModalWillHide = () => {
67+
setStatusBarColor(previousStatusBarColor);
68+
rest.onModalWillHide?.();
69+
};
6370

6471
return (
6572
<BaseModal
6673
// eslint-disable-next-line react/jsx-props-no-spreading
6774
{...rest}
6875
onModalHide={hideModal}
6976
onModalShow={showModal}
77+
onModalWillShow={onModalWillShow}
78+
onModalWillHide={onModalWillHide}
7079
avoidKeyboard={false}
7180
fullscreen={fullscreen}
7281
useNativeDriver={false}

0 commit comments

Comments
 (0)