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 @@ -10,6 +10,7 @@ GenericNavigationAction, } from '@react-navigation/native'; import { StackRouter, CommonActions } from '@react-navigation/native'; +import Alert from 'react-native/Libraries/Alert/Alert.js'; import type { ThreadInfo } from 'lib/types/thread-types.js'; @@ -67,6 +68,15 @@ +pushNewThread: (threadInfo: ThreadInfo) => void, }; +const displayAlert = () => { + Alert.alert( + 'You are in edit mode', + 'Exit edit mode before navigating to another screen', + [{ text: 'OK' }], + { cancelable: true }, + ); +}; + function ChatRouter( routerOptions: StackRouterOptions, ): Router { @@ -128,7 +138,17 @@ ); 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 + ) { + displayAlert(); + 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,15 @@ } }, [isSearching, navigationStack, setParams, threadInfo]); + const shouldBlockNavigation = React.useMemo( + () => !!inputState.editState.editedMessage, + [inputState.editState.editedMessage], + ); + + React.useEffect(() => { + setParams({ disableNavigation: shouldBlockNavigation }); + }, [shouldBlockNavigation, isSearching, props.navigation, setParams]); + 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 @@ -15,6 +15,7 @@ +threadInfo: ThreadInfo, +pendingPersonalThreadUserInfo?: UserInfo, +searching?: boolean, + +disableNavigation?: boolean, }; export type MessageListContextType = {