diff --git a/native/chat/chat-router.js b/native/chat/chat-router.js --- a/native/chat/chat-router.js +++ b/native/chat/chat-router.js @@ -28,6 +28,7 @@ ChatThreadListRouteName, ComposeSubchannelRouteName, } from '../navigation/route-names.js'; +import { exitEditAlert } from '../utils/edit-messages-utils.js'; type ClearScreensAction = { +type: 'CLEAR_SCREENS', @@ -128,7 +129,22 @@ ); return baseGetStateForAction(clearedState, navigateAction, options); } else { - return baseGetStateForAction(lastState, action, options); + const result = baseGetStateForAction(lastState, action, options); + if ( + result !== null && + result?.index && + result.index > lastState.index && + lastState.routes[lastState.index].params?.disableNavigation + ) { + const disableNavigation: Function = + lastState.routes[lastState.index].params?.disableNavigation; + const onDiscard = () => { + disableNavigation(action); + }; + exitEditAlert(onDiscard); + return lastState; + } + return result; } }, actionCreators: { diff --git a/native/chat/message-list-container.react.js b/native/chat/message-list-container.react.js --- a/native/chat/message-list-container.react.js +++ b/native/chat/message-list-container.react.js @@ -293,6 +293,35 @@ } }, [isSearching, navigationStack, setParams, threadInfo]); + const shouldBlockNavigation = React.useMemo( + () => !!inputState.editState.editedMessage, + [inputState.editState.editedMessage], + ); + + const removeEditMode = React.useCallback( + action => { + inputState.setEditedMessage(null, () => { + setParams({ disableNavigation: null }); + props.navigation.dispatch(action); + }); + }, + [inputState, props.navigation, setParams], + ); + + React.useEffect(() => { + if (shouldBlockNavigation) { + setParams({ disableNavigation: removeEditMode }); + } else { + setParams({ disableNavigation: null }); + } + }, [ + shouldBlockNavigation, + isSearching, + props.navigation, + setParams, + removeEditMode, + ]); + const hideSearch = React.useCallback(() => { setBaseThreadInfo(threadInfo); setParams({ searching: false }); diff --git a/native/chat/message-list-types.js b/native/chat/message-list-types.js --- a/native/chat/message-list-types.js +++ b/native/chat/message-list-types.js @@ -7,6 +7,7 @@ import type { ThreadInfo } from 'lib/types/thread-types.js'; import { type UserInfo } from 'lib/types/user-types.js'; +import type { ChatRouterNavigationAction } from './chat-router.js'; import type { MarkdownRules } from '../markdown/rules.react.js'; import { useTextMessageRulesFunc } from '../markdown/rules.react.js'; import { MessageListRouteName } from '../navigation/route-names.js'; @@ -15,6 +16,7 @@ +threadInfo: ThreadInfo, +pendingPersonalThreadUserInfo?: UserInfo, +searching?: boolean, + +disableNavigation?: ?(ChatRouterNavigationAction) => void, }; export type MessageListContextType = {