diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js --- a/native/chat/chat-input-bar.react.js +++ b/native/chat/chat-input-bar.react.js @@ -115,6 +115,7 @@ import type { LayoutEvent } from '../types/react-native.js'; import { type AnimatedViewStyle, AnimatedView } from '../types/styles.js'; import { runTiming } from '../utils/animation-utils.js'; +import { exitEditAlert } from '../utils/edit-messages-utils.js'; import { nativeTypeaheadRegex } from '../utils/typeahead-utils.js'; /* eslint-disable import/no-named-as-default-member */ @@ -864,19 +865,7 @@ this.exitEditMode(); return; } - Alert.alert('Are you sure?', 'Your edits will be discarded.', [ - { - text: 'Continue editing', - style: 'cancel', - }, - { - text: 'Discard edit', - style: 'destructive', - onPress: () => { - this.exitEditMode(); - }, - }, - ]); + exitEditAlert(this.exitEditMode); }; exitEditMode = () => { diff --git a/native/chat/text-message-tooltip-modal.react.js b/native/chat/text-message-tooltip-modal.react.js --- a/native/chat/text-message-tooltip-modal.react.js +++ b/native/chat/text-message-tooltip-modal.react.js @@ -20,6 +20,7 @@ type TooltipMenuProps, } from '../tooltip/tooltip.react.js'; import type { ChatTextMessageInfoItemWithHeight } from '../types/chat-types.js'; +import { exitEditAlert } from '../utils/edit-messages-utils.js'; export type TextMessageTooltipModalParams = TooltipParams<{ +item: ChatTextMessageInfoItemWithHeight, @@ -69,7 +70,14 @@ mode: 'replace', }); }; - inputState.setEditedMessage(messageInfo, updateInputBar); + const enterEditMode = () => { + inputState.setEditedMessage(messageInfo, updateInputBar); + }; + if (inputState.editState.editedMessage) { + exitEditAlert(enterEditMode); + } else { + enterEditMode(); + } }, [inputState, messageInfo, text]); const renderEditIcon = React.useCallback( style => , diff --git a/native/utils/edit-messages-utils.js b/native/utils/edit-messages-utils.js --- a/native/utils/edit-messages-utils.js +++ b/native/utils/edit-messages-utils.js @@ -1,6 +1,7 @@ // @flow import * as React from 'react'; +import Alert from 'react-native/Libraries/Alert/Alert.js'; import { FeatureFlagsContext } from '../components/feature-flags-provider.react.js'; @@ -11,4 +12,20 @@ return !!featureFlagConfig['EDIT_BUTTON_DISPLAY']; } -export { useShouldRenderEditButton }; +function exitEditAlert(onDiscard: () => void): void { + Alert.alert('Are you sure?', 'Your edits will be discarded.', [ + { + text: 'Continue editing', + style: 'cancel', + }, + { + text: 'Discard edit', + style: 'destructive', + onPress: () => { + onDiscard(); + }, + }, + ]); +} + +export { useShouldRenderEditButton, exitEditAlert };