@@ -3,9 +3,19 @@ import {useEffect} from 'react';
33import usePrevious from '@hooks/usePrevious' ;
44import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
55import useSidePanel from '@hooks/useSidePanel' ;
6+ import Navigation from '@libs/Navigation/Navigation' ;
67import navigationRef from '@libs/Navigation/navigationRef' ;
78import CONST from '@src/CONST' ;
89
10+ function toggleSidePanelWithHistory ( isVisible : boolean ) {
11+ Navigation . isNavigationReady ( ) . then ( ( ) => {
12+ navigationRef . dispatch ( {
13+ type : CONST . NAVIGATION . ACTION_TYPE . TOGGLE_SIDE_PANEL_WITH_HISTORY ,
14+ payload : { isVisible} ,
15+ } ) ;
16+ } ) ;
17+ }
18+
919export default function useSyncSidePanelWithHistory ( ) {
1020 const { closeSidePanel, openSidePanel, shouldHideSidePanel} = useSidePanel ( ) ;
1121 const { isExtraLargeScreenWidth} = useResponsiveLayout ( ) ;
@@ -16,18 +26,12 @@ export default function useSyncSidePanelWithHistory() {
1626 // If the window width has been expanded and the modal is displayed, remove its history entry.
1727 // The side panel is only synced with the history when it's displayed as RHP.
1828 if ( ! shouldHideSidePanel && isExtraLargeScreenWidth ) {
19- navigationRef . dispatch ( {
20- type : CONST . NAVIGATION . ACTION_TYPE . TOGGLE_SIDE_PANEL_WITH_HISTORY ,
21- payload : { isVisible : false } ,
22- } ) ;
29+ toggleSidePanelWithHistory ( false ) ;
2330 return ;
2431 }
2532
2633 // When shouldHideSidePanel changes, synchronize the side panel with the browser history.
27- navigationRef . dispatch ( {
28- type : CONST . NAVIGATION . ACTION_TYPE . TOGGLE_SIDE_PANEL_WITH_HISTORY ,
29- payload : { isVisible : ! shouldHideSidePanel } ,
30- } ) ;
34+ toggleSidePanelWithHistory ( ! shouldHideSidePanel ) ;
3135 } , [ shouldHideSidePanel , isExtraLargeScreenWidth ] ) ;
3236
3337 useEffect ( ( ) => {
0 commit comments