diff --git a/native/navigation/nav-selectors.js b/native/navigation/nav-selectors.js --- a/native/navigation/nav-selectors.js +++ b/native/navigation/nav-selectors.js @@ -317,6 +317,46 @@ }, ); +const getChatNavState: ( + navigationState: ?PossiblyStaleNavigationState, +) => ?PossiblyStaleNavigationState = ( + navigationState: ?PossiblyStaleNavigationState, +) => { + if (!navigationState) { + return null; + } + const [firstAppSubroute] = navigationState.routes; + if (firstAppSubroute.name !== CommunityDrawerNavigatorRouteName) { + return null; + } + + const communityDrawerState = getStateFromNavigatorRoute(firstAppSubroute); + const [firstCommunityDrawerSubroute] = communityDrawerState.routes; + if (firstCommunityDrawerSubroute.name !== TabNavigatorRouteName) { + return null; + } + + const tabState = getStateFromNavigatorRoute(firstCommunityDrawerSubroute); + if (!tabState) { + return null; + } + let chatRoute; + for (const route of tabState.routes) { + if (route.name === ChatRouteName) { + chatRoute = route; + break; + } + } + if (!chatRoute || !chatRoute.state) { + return null; + } + const chatRouteState = getStateFromNavigatorRoute(chatRoute); + if (chatRouteState.type !== 'stack') { + return null; + } + return chatRouteState; +}; + const getRemoveEditMode: ( chatRouteState: ?PossiblyStaleNavigationState, ) => ?RemoveEditMode = (chatRouteState: ?PossiblyStaleNavigationState) => { @@ -362,4 +402,5 @@ drawerSwipeEnabledSelector, useCurrentLeafRouteName, getRemoveEditMode, + getChatNavState, }; diff --git a/native/navigation/overlay-router.js b/native/navigation/overlay-router.js --- a/native/navigation/overlay-router.js +++ b/native/navigation/overlay-router.js @@ -15,6 +15,7 @@ clearOverlayModalsActionType, setRouteParamsActionType, } from './action-types.js'; +import { getRemoveEditMode, getChatNavState } from './nav-selectors.js'; import { removeScreensFromStack } from './navigation-utils.js'; type ClearOverlayModalsAction = { @@ -56,6 +57,8 @@ action: OverlayRouterNavigationAction, options: RouterConfigOptions, ) => { + const chatNavState = getChatNavState(lastState); + const removeEditMode = getRemoveEditMode(chatNavState); if (action.type === clearOverlayModalsActionType) { const { keys } = action.payload; if (!lastState) { @@ -81,6 +84,9 @@ ...lastState, routes: newRoutes, }; + } else if (removeEditMode) { + removeEditMode(action); + return lastState; } else { return baseGetStateForAction(lastState, action, options); }