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 @@ -64,6 +64,7 @@ draftKeyFromThreadID, } from 'lib/shared/thread-utils.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; +import type { SetState } from 'lib/types/hook-types.js'; import type { LoadingStatus } from 'lib/types/loading-types.js'; import type { PhotoPaste } from 'lib/types/media-types.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; @@ -308,12 +309,13 @@ +navigation: ?ChatNavigationProp<'MessageList'>, +overlayContext: ?OverlayContextType, +messageEditingContext: ?MessageEditingContextType, + +selectionState: SyncedSelectionData, + +setSelectionState: SetState, }; type State = { +text: string, +textEdited: boolean, +buttonsExpanded: boolean, - +selectionState: SyncedSelectionData, +isExitingDuringEditMode: boolean, }; class ChatInputBar extends React.PureComponent { @@ -342,7 +344,6 @@ text: props.draft, textEdited: false, buttonsExpanded: true, - selectionState: { text: props.draft, selection: { start: 0, end: 0 } }, isExitingDuringEditMode: false, }; @@ -671,8 +672,8 @@ } const typeaheadRegexMatches = getTypeaheadRegexMatches( - this.state.selectionState.text, - this.state.selectionState.selection, + this.props.selectionState.text, + this.props.selectionState.selection, nativeMentionTypeaheadRegex, ); @@ -861,8 +862,8 @@ allowImagePasteForThreadID={this.props.threadInfo.id} value={this.state.text} onChangeText={this.updateText} - selection={this.state.selectionState.selection} - onUpdateSyncedSelectionData={this.updateSelectionState} + selection={this.props.selectionState.selection} + onUpdateSyncedSelectionData={this.props.setSelectionState} placeholder="Send a message..." placeholderTextColor={this.props.colors.listInputButton} multiline={true} @@ -920,10 +921,6 @@ this.saveDraft(text); }; - updateSelectionState: (data: SyncedSelectionData) => void = data => { - this.setState({ selectionState: data }); - }; - saveDraft: (text: string) => void = _throttle(text => { this.props.dispatch({ type: updateDraftActionType, @@ -939,8 +936,8 @@ this.setState({ text, textEdited: true, - selectionState: { text, selection }, }); + this.props.setSelectionState({ text, selection }); this.saveDraft(text); this.focusAndUpdateButtonsVisibility(); @@ -1308,6 +1305,12 @@ ); const editMessage = useEditMessage(); + const [selectionState, setSelectionState] = + React.useState({ + text: draft, + selection: { start: 0, end: 0 }, + }); + return ( ); }