Repository navigation
fix: issue 23908 #27190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: issue 23908 #27190
Changes from all commits
002241b
920d7c8
09fe747
3951fd7
d0e69fe
1b7e45d
b0dcc75
164f88d
b887abd
77da6ed
418ddd4
b79780d
b2f4e3a
98d573e
3a246e6
b96510d
a74b2b2
e4a381f
97aaa26
c24df9c
4e9083f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import * as Composer from '../actions/Composer'; | ||
|
|
||
| export default (shouldShow) => { | ||
| Composer.setShouldShowComposeInput(shouldShow); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import {Keyboard} from 'react-native'; | ||
| import * as Composer from '../actions/Composer'; | ||
|
|
||
| let keyboardDidHideListener = null; | ||
| export default (shouldShow) => { | ||
| if (keyboardDidHideListener) { | ||
| keyboardDidHideListener.remove(); | ||
| keyboardDidHideListener = null; | ||
| } | ||
|
|
||
| if (!shouldShow) { | ||
| Composer.setShouldShowComposeInput(false); | ||
| return; | ||
| } | ||
|
|
||
| // If keyboard is already hidden, we should show composer immediately because keyboardDidHide event won't be called | ||
| if (!Keyboard.isVisible()) { | ||
| Composer.setShouldShowComposeInput(true); | ||
| return; | ||
| } | ||
|
|
||
| keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => { | ||
| Composer.setShouldShowComposeInput(true); | ||
| keyboardDidHideListener.remove(); | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,12 @@ function ReportActionItem(props) { | |
| const originalReportID = ReportUtils.getOriginalReportID(props.report.reportID, props.action); | ||
| const originalReport = props.report.reportID === originalReportID ? props.report : ReportUtils.getReport(originalReportID); | ||
|
|
||
| // When active action changes, we need to update the `isContextMenuActive` state | ||
| const isActiveReportActionForMenu = ReportActionContextMenu.isActiveReportAction(props.action.reportActionID); | ||
| useEffect(() => { | ||
| setIsContextMenuActive(isActiveReportActionForMenu); | ||
| }, [isActiveReportActionForMenu]); | ||
|
Comment on lines
+141
to
+145
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this effect depends on temporary data it is not synced with the lifecycle of other components creating inconsistencies between states of components. It caused #28029 |
||
|
|
||
| const updateHiddenState = useCallback( | ||
| (isHiddenValue) => { | ||
| setIsHidden(isHiddenValue); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ import containerComposeStyles from '../../../styles/containerComposeStyles'; | |
| import Composer from '../../../components/Composer'; | ||
| import * as Report from '../../../libs/actions/Report'; | ||
| import {withReportActionsDrafts} from '../../../components/OnyxProvider'; | ||
| import openReportActionComposeViewWhenClosingMessageEdit from '../../../libs/openReportActionComposeViewWhenClosingMessageEdit'; | ||
| import setShouldShowComposeInputKeyboardAware from '../../../libs/setShouldShowComposeInputKeyboardAware'; | ||
| import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; | ||
| import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton'; | ||
| import Icon from '../../../components/Icon'; | ||
|
|
@@ -28,7 +28,6 @@ import ExceededCommentLength from '../../../components/ExceededCommentLength'; | |
| import CONST from '../../../CONST'; | ||
| import refPropTypes from '../../../components/refPropTypes'; | ||
| import * as ComposerUtils from '../../../libs/ComposerUtils'; | ||
| import * as ComposerActions from '../../../libs/actions/Composer'; | ||
| import * as User from '../../../libs/actions/User'; | ||
| import PressableWithFeedback from '../../../components/Pressable/PressableWithFeedback'; | ||
| import getButtonState from '../../../libs/getButtonState'; | ||
|
|
@@ -84,8 +83,6 @@ const defaultProps = { | |
| }; | ||
|
|
||
| // native ids | ||
| const saveButtonID = 'saveButton'; | ||
| const cancelButtonID = 'cancelButton'; | ||
| const emojiButtonID = 'emojiButton'; | ||
| const messageEditInput = 'messageEditInput'; | ||
|
|
||
|
|
@@ -130,6 +127,12 @@ function ReportActionItemMessageEdit(props) { | |
| isFocusedRef.current = isFocused; | ||
| }, [isFocused]); | ||
|
|
||
| // We consider the report action active if it's focused, its emoji picker is open or its context menu is open | ||
| const isActive = useCallback( | ||
| () => isFocusedRef.current || EmojiPickerAction.isActive(props.action.reportActionID) || ReportActionContextMenu.isActiveReportAction(props.action.reportActionID), | ||
| [props.action.reportActionID], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| // For mobile Safari, updating the selection prop on an unfocused input will cause it to automatically gain focus | ||
| // and subsequent programmatic focus shifts (e.g., modal focus trap) to show the blue frame (:focus-visible style), | ||
|
|
@@ -145,16 +148,23 @@ function ReportActionItemMessageEdit(props) { | |
| } | ||
|
|
||
| return () => { | ||
| // Skip if this is not the focused message so the other edit composer stays focused. | ||
| // In small screen devices, when EmojiPicker is shown, the current edit message will lose focus, we need to check this case as well. | ||
| if (!isFocusedRef.current && !EmojiPickerAction.isActive(props.action.reportActionID)) { | ||
| // Skip if the current report action is not active | ||
| if (!isActive()) { | ||
| return; | ||
| } | ||
|
|
||
| if (EmojiPickerAction.isActive(props.action.reportActionID)) { | ||
| EmojiPickerAction.clearActive(); | ||
| } | ||
| if (ReportActionContextMenu.isActiveReportAction(props.action.reportActionID)) { | ||
| ReportActionContextMenu.clearActiveReportAction(); | ||
| } | ||
|
|
||
| // Show the main composer when the focused message is deleted from another client | ||
| // to prevent the main composer stays hidden until we swtich to another chat. | ||
| ComposerActions.setShouldShowComposeInput(true); | ||
| setShouldShowComposeInputKeyboardAware(true); | ||
|
Comment on lines
-156
to
+165
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB. Do we need to make this keyboard aware? Will this introduce any delay?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. I think showing composer after keyboard is closed is good. If keyboard isn't visible, this would show composer immediately |
||
| }; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps -- this cleanup needs to be called only on unmount | ||
| }, [props.action.reportActionID]); | ||
|
|
||
| /** | ||
|
|
@@ -227,9 +237,11 @@ function ReportActionItemMessageEdit(props) { | |
| const deleteDraft = useCallback(() => { | ||
| debouncedSaveDraft.cancel(); | ||
| Report.saveReportActionDraft(props.reportID, props.action.reportActionID, ''); | ||
| ComposerActions.setShouldShowComposeInput(true); | ||
| ReportActionComposeFocusManager.clear(); | ||
| ReportActionComposeFocusManager.focus(); | ||
|
|
||
| if (isActive()) { | ||
| ReportActionComposeFocusManager.clear(); | ||
| ReportActionComposeFocusManager.focus(); | ||
| } | ||
|
Comment on lines
-232
to
+244
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may be causing a regression. Can we remove the condition here? Currently if we delete a message the focus is not set back to the main composer but it should
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that solution won't work. We still need to find a way to fix the regression though
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should focus the main composer if the deleted message is active. Please let me know if I am wrong
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct but apparently this is not the behavior Screen.Recording.2023-09-14.at.5.29.25.PM.mov
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed the bug of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is resolved, right? Because I too agree the expected behaviour is that composer should get the focus.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, thanks. |
||
|
|
||
| // Scroll to the last comment after editing to make sure the whole comment is clearly visible in the report. | ||
| if (props.index === 0) { | ||
|
|
@@ -238,7 +250,7 @@ function ReportActionItemMessageEdit(props) { | |
| keyboardDidHideListener.remove(); | ||
| }); | ||
| } | ||
| }, [props.action.reportActionID, debouncedSaveDraft, props.index, props.reportID, reportScrollManager]); | ||
| }, [props.action.reportActionID, debouncedSaveDraft, props.index, props.reportID, reportScrollManager, isActive]); | ||
|
|
||
| /** | ||
| * Save the draft of the comment to be the new comment message. This will take the comment out of "edit mode" with | ||
|
|
@@ -273,6 +285,7 @@ function ReportActionItemMessageEdit(props) { | |
|
|
||
| // When user tries to save the empty message, it will delete it. Prompt the user to confirm deleting. | ||
| if (!trimmedNewDraft) { | ||
| textInputRef.current.blur(); | ||
| ReportActionContextMenu.showDeleteModal(props.reportID, props.action, false, deleteDraft, () => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())); | ||
| return; | ||
| } | ||
|
|
@@ -325,14 +338,15 @@ function ReportActionItemMessageEdit(props) { | |
| <PressableWithFeedback | ||
| onPress={deleteDraft} | ||
| style={styles.chatItemSubmitButton} | ||
| nativeID={cancelButtonID} | ||
| accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON} | ||
| accessibilityLabel={translate('common.close')} | ||
| // disable dimming | ||
| hoverDimmingValue={1} | ||
| pressDimmingValue={1} | ||
| hoverStyle={StyleUtils.getButtonBackgroundColorStyle(CONST.BUTTON_STATES.ACTIVE)} | ||
| pressStyle={StyleUtils.getButtonBackgroundColorStyle(CONST.BUTTON_STATES.PRESSED)} | ||
| // Keep focus on the composer when cancel button is clicked. | ||
| onMouseDown={(e) => e.preventDefault()} | ||
| > | ||
| {({hovered, pressed}) => ( | ||
| <Icon | ||
|
|
@@ -369,21 +383,23 @@ function ReportActionItemMessageEdit(props) { | |
| onFocus={() => { | ||
| setIsFocused(true); | ||
| reportScrollManager.scrollToIndex({animated: true, index: props.index}, true); | ||
| ComposerActions.setShouldShowComposeInput(false); | ||
| setShouldShowComposeInputKeyboardAware(false); | ||
|
|
||
| // Clear active report action when another action gets focused | ||
| if (!EmojiPickerAction.isActive(props.action.reportActionID)) { | ||
| EmojiPickerAction.clearActive(); | ||
| } | ||
| if (!ReportActionContextMenu.isActiveReportAction(props.action.reportActionID)) { | ||
| ReportActionContextMenu.clearActiveReportAction(); | ||
| } | ||
|
Comment on lines
+388
to
+394
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we do this on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. We should keep active report action until another draft gets focused. This wasn't already confirmed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @s-alves10 This is not resolved yet. Can we do this any other way?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we confirmed this in the proposal Note: I guess we can clear active in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the new approach can cause a regression.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I don't think this is a blocker for now. Will need to test though |
||
| }} | ||
| onBlur={(event) => { | ||
| setIsFocused(false); | ||
| const relatedTargetId = lodashGet(event, 'nativeEvent.relatedTarget.id'); | ||
|
|
||
| // Return to prevent re-render when save/cancel button is pressed which cancels the onPress event by re-rendering | ||
| if (_.contains([saveButtonID, cancelButtonID, emojiButtonID], relatedTargetId)) { | ||
| return; | ||
| } | ||
|
|
||
| if (messageEditInput === relatedTargetId) { | ||
| if (_.contains([messageEditInput, emojiButtonID], relatedTargetId)) { | ||
| return; | ||
| } | ||
| openReportActionComposeViewWhenClosingMessageEdit(); | ||
| setShouldShowComposeInputKeyboardAware(true); | ||
| }} | ||
| selection={selection} | ||
| onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} | ||
|
|
@@ -407,12 +423,13 @@ function ReportActionItemMessageEdit(props) { | |
| <PressableWithFeedback | ||
| style={[styles.chatItemSubmitButton, hasExceededMaxCommentLength ? {} : styles.buttonSuccess]} | ||
| onPress={publishDraft} | ||
| nativeID={saveButtonID} | ||
| disabled={hasExceededMaxCommentLength} | ||
| accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON} | ||
| accessibilityLabel={translate('common.saveChanges')} | ||
| hoverDimmingValue={1} | ||
| pressDimmingValue={0.2} | ||
| // Keep focus on the composer when send button is clicked. | ||
| onMouseDown={(e) => e.preventDefault()} | ||
| > | ||
| <Icon | ||
| src={Expensicons.Checkmark} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.