diff --git a/src/components/Modal/BaseModal.tsx b/src/components/Modal/BaseModal.tsx index b650408642722..5ca6eda9de5eb 100644 --- a/src/components/Modal/BaseModal.tsx +++ b/src/components/Modal/BaseModal.tsx @@ -54,6 +54,8 @@ function BaseModal( innerContainerStyle = {}, outerStyle, onModalShow = () => {}, + onModalWillShow, + onModalWillHide, propagateSwipe, fullscreen = true, animationIn, @@ -278,7 +280,11 @@ function BaseModal( onModalShow={handleShowModal} propagateSwipe={propagateSwipe} onModalHide={hideModal} - onModalWillShow={saveFocusState} + onModalWillShow={() => { + saveFocusState(); + onModalWillShow?.(); + }} + onModalWillHide={onModalWillHide} onDismiss={handleDismissModal} onSwipeComplete={() => onClose?.()} swipeDirection={swipeDirection} diff --git a/src/components/Modal/BottomDockedModal/index.tsx b/src/components/Modal/BottomDockedModal/index.tsx index 953eabae10b8c..801fbe23cdf43 100644 --- a/src/components/Modal/BottomDockedModal/index.tsx +++ b/src/components/Modal/BottomDockedModal/index.tsx @@ -101,7 +101,6 @@ function BottomDockedModal({ useEffect( () => () => { - onModalWillHide(); if (handleRef.current) { InteractionManager.clearInteractionHandle(handleRef.current); } diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx index 16907a590852a..deca4d0901f1e 100644 --- a/src/components/Modal/index.tsx +++ b/src/components/Modal/index.tsx @@ -21,7 +21,6 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = ( }; const hideModal = () => { - setStatusBarColor(previousStatusBarColor); onModalHide(); if ((window.history.state as WindowState)?.shouldGoBack) { window.history.back(); @@ -33,6 +32,21 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = ( }); const showModal = () => { + if (shouldHandleNavigationBack) { + window.history.pushState({shouldGoBack: true}, '', null); + window.addEventListener('popstate', handlePopStateRef.current); + } + onModalShow?.(); + }; + + useEffect( + () => () => { + window.removeEventListener('popstate', handlePopStateRef.current); + }, + [], + ); + + const onModalWillShow = () => { const statusBarColor = StatusBar.getBackgroundColor() ?? theme.appBG; const isFullScreenModal = @@ -46,20 +60,13 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = ( // If it is a full screen modal then match it with appBG, otherwise we use the backdrop color setStatusBarColor(isFullScreenModal ? theme.appBG : StyleUtils.getThemeBackgroundColor(statusBarColor)); } - - if (shouldHandleNavigationBack) { - window.history.pushState({shouldGoBack: true}, '', null); - window.addEventListener('popstate', handlePopStateRef.current); - } - onModalShow?.(); + rest.onModalWillShow?.(); }; - useEffect( - () => () => { - window.removeEventListener('popstate', handlePopStateRef.current); - }, - [], - ); + const onModalWillHide = () => { + setStatusBarColor(previousStatusBarColor); + rest.onModalWillHide?.(); + }; return ( {}, type, onModalShow = ( {...rest} onModalHide={hideModal} onModalShow={showModal} + onModalWillShow={onModalWillShow} + onModalWillHide={onModalWillHide} avoidKeyboard={false} fullscreen={fullscreen} useNativeDriver={false}