Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3395439
D14017.id46075.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D14017.id46075.diff
View Options
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
@@ -351,80 +351,6 @@
};
class ChatInputBar extends React.PureComponent<Props> {
- static mediaGalleryOpen(props: Props): boolean {
- const { keyboardState } = props;
- return !!(keyboardState && keyboardState.mediaGalleryOpen);
- }
-
- static systemKeyboardShowing(props: Props): boolean {
- const { keyboardState } = props;
- return !!(keyboardState && keyboardState.systemKeyboardShowing);
- }
-
- get systemKeyboardShowing(): boolean {
- return ChatInputBar.systemKeyboardShowing(this.props);
- }
-
- componentDidUpdate(prevProps: Props) {
- if (
- this.props.textEdited &&
- this.props.text &&
- this.props.threadInfo.id !== prevProps.threadInfo.id
- ) {
- this.props.dispatch({
- type: moveDraftActionType,
- payload: {
- oldKey: draftKeyFromThreadID(prevProps.threadInfo.id),
- newKey: draftKeyFromThreadID(this.props.threadInfo.id),
- },
- });
- } else if (!this.props.textEdited && this.props.draft !== prevProps.draft) {
- this.props.setText(this.props.draft);
- }
- if (this.props.isActive && !prevProps.isActive) {
- this.props.addEditInputMessageListener();
- } else if (!this.props.isActive && prevProps.isActive) {
- this.props.removeEditInputMessageListener();
- }
-
- const currentText = trimMessage(this.props.text);
- const prevText = trimMessage(prevProps.text);
-
- if (
- (currentText === '' && prevText !== '') ||
- (currentText !== '' && prevText === '')
- ) {
- this.props.updateSendButton(currentText);
- }
-
- const systemKeyboardIsShowing = ChatInputBar.systemKeyboardShowing(
- this.props,
- );
- const systemKeyboardWasShowing =
- ChatInputBar.systemKeyboardShowing(prevProps);
- if (systemKeyboardIsShowing && !systemKeyboardWasShowing) {
- this.props.hideButtons();
- } else if (!systemKeyboardIsShowing && systemKeyboardWasShowing) {
- this.props.expandButtons();
- }
-
- const imageGalleryIsOpen = ChatInputBar.mediaGalleryOpen(this.props);
- const imageGalleryWasOpen = ChatInputBar.mediaGalleryOpen(prevProps);
- if (!imageGalleryIsOpen && imageGalleryWasOpen) {
- this.props.hideButtons();
- } else if (imageGalleryIsOpen && !imageGalleryWasOpen) {
- this.props.expandButtons();
- this.props.setIOSKeyboardHeight();
- }
-
- if (
- this.props.messageEditingContext?.editState.editedMessage &&
- !prevProps.messageEditingContext?.editState.editedMessage
- ) {
- this.props.blockNavigation();
- }
- }
-
render(): React.Node {
const isMember = viewerIsMember(this.props.threadInfo);
let joinButton = null;
@@ -1422,6 +1348,91 @@
keyboardState?.dismissKeyboard();
}, [keyboardState]);
+ const prevThreadInfoID = React.useRef<?string>();
+ const prevDraft = React.useRef<?string>();
+
+ React.useEffect(() => {
+ if (
+ textEdited &&
+ text &&
+ prevThreadInfoID.current &&
+ props.threadInfo.id !== prevThreadInfoID.current
+ ) {
+ dispatch({
+ type: moveDraftActionType,
+ payload: {
+ oldKey: draftKeyFromThreadID(prevThreadInfoID.current),
+ newKey: draftKeyFromThreadID(props.threadInfo.id),
+ },
+ });
+ } else if (!textEdited && draft !== prevDraft.current) {
+ setText(draft);
+ }
+ prevThreadInfoID.current = props.threadInfo.id;
+ prevDraft.current = draft;
+ }, [dispatch, draft, props.threadInfo.id, text, textEdited]);
+
+ const prevIsActiveRef = React.useRef(isActive);
+ React.useEffect(() => {
+ if (isActive && !prevIsActiveRef.current) {
+ addEditInputMessageListener();
+ } else if (!isActive && prevIsActiveRef) {
+ removeEditInputMessageListener();
+ }
+ prevIsActiveRef.current = isActive;
+ }, [addEditInputMessageListener, isActive, removeEditInputMessageListener]);
+
+ const prevTextRef = React.useRef(text);
+ React.useEffect(() => {
+ const currentText = trimMessage(text);
+ const prevText = trimMessage(prevTextRef.current);
+ prevTextRef.current = currentText;
+
+ if (
+ (currentText === '' && prevText !== '') ||
+ (currentText !== '' && prevText === '')
+ ) {
+ updateSendButton(currentText);
+ }
+ }, [text, updateSendButton]);
+
+ const systemKeyboardWasShowingRef = React.useRef<?boolean>();
+ React.useEffect(() => {
+ const systemKeyboardShowing = keyboardState?.systemKeyboardShowing;
+ if (systemKeyboardShowing && !systemKeyboardWasShowingRef.current) {
+ hideButtons();
+ } else if (!systemKeyboardShowing && systemKeyboardWasShowingRef.current) {
+ expandButtons();
+ }
+ systemKeyboardWasShowingRef.current = systemKeyboardShowing;
+ }, [expandButtons, hideButtons, keyboardState?.systemKeyboardShowing]);
+
+ const mediaGalleryWasOpenRef = React.useRef<?boolean>();
+ React.useEffect(() => {
+ const mediaGalleryOpen = keyboardState?.mediaGalleryOpen;
+ if (!mediaGalleryOpen && mediaGalleryWasOpenRef.current) {
+ hideButtons();
+ } else if (mediaGalleryOpen && !mediaGalleryWasOpenRef.current) {
+ expandButtons();
+ setIOSKeyboardHeight();
+ }
+ mediaGalleryWasOpenRef.current = mediaGalleryOpen;
+ }, [
+ expandButtons,
+ hideButtons,
+ keyboardState?.mediaGalleryOpen,
+ setIOSKeyboardHeight,
+ ]);
+
+ const prevEditedMessage = React.useRef<?MessageInfo>();
+ React.useEffect(() => {
+ const editedMessage = messageEditingContext?.editState.editedMessage;
+ if (editedMessage && !prevEditedMessage.current) {
+ blockNavigation();
+ }
+ prevEditedMessage.current = editedMessage;
+ }, [blockNavigation, messageEditingContext?.editState.editedMessage]);
+
return (
<ChatInputBar
{...props}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 2, 5:06 AM (9 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605753
Default Alt Text
D14017.id46075.diff (5 KB)
Attached To
Mode
D14017: [native] Migrate componentDidUpdate() in ChatInputBar to function component
Attached
Detach File
Event Timeline
Log In to Comment