-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: Composer not focused on click while editor's emoji modal is open #28238
Changes from all commits
0f02054
86d30a4
27f6a05
24d1fa9
d262d65
f9a54af
83f7745
801066c
0472812
e7c2fb5
b2dede8
c6b17d5
3f4e9d7
fb99586
6bcd089
b1025c1
3439d49
f100c71
f51ed18
fdfec45
97338fc
759b4a5
a20eace
bb9f370
66ce543
0ae8452
f1b4e20
fe16fc0
f6b25c8
21d8617
df83fc8
599fe46
031ab6c
dc73745
b41e23c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,29 @@ function ReportActionItemMessageEdit( | |
[action.reportActionID], | ||
); | ||
|
||
/** | ||
* Focus the composer text input | ||
* @param shouldDelay - Impose delay before focusing the composer | ||
*/ | ||
const focus = useCallback((shouldDelay = false, forcedSelectionRange?: Selection) => { | ||
focusComposerWithDelay(textInputRef.current)(shouldDelay, forcedSelectionRange); | ||
}, []); | ||
|
||
// Take over focus priority | ||
const setUpComposeFocusManager = useCallback(() => { | ||
ReportActionComposeFocusManager.onComposerFocus(() => { | ||
focus(true, emojiPickerSelectionRef.current ? {...emojiPickerSelectionRef.current} : undefined); | ||
}, true); | ||
}, [focus]); | ||
|
||
useEffect( | ||
// Remove focus callback on unmount to avoid stale callbacks | ||
() => () => { | ||
ReportActionComposeFocusManager.clear(true); | ||
}, | ||
[], | ||
); | ||
|
||
useEffect( | ||
() => { | ||
if (isInitialMount.current) { | ||
|
@@ -274,8 +297,9 @@ function ReportActionItemMessageEdit( | |
Report.deleteReportActionDraft(reportID, action); | ||
|
||
if (isActive()) { | ||
ReportActionComposeFocusManager.clear(); | ||
ReportActionComposeFocusManager.focus(); | ||
ReportActionComposeFocusManager.clear(true); | ||
// Wait for report action compose re-mounting on mWeb | ||
InteractionManager.runAfterInteractions(() => ReportActionComposeFocusManager.focus()); | ||
Comment on lines
+300
to
+302
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. Why are we clearing before focusing? 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. When users edit message, the edit composer will be the priority composer. Then when they cancel edit mode, we need to remove the edit composer focus callback first, so when trigger |
||
} | ||
|
||
// Scroll to the last comment after editing to make sure the whole comment is clearly visible in the report. | ||
|
@@ -424,11 +448,6 @@ function ReportActionItemMessageEdit( | |
[], | ||
); | ||
|
||
/** | ||
* Focus the composer text input | ||
*/ | ||
const focus = focusComposerWithDelay(textInputRef.current); | ||
|
||
useEffect(() => { | ||
validateCommentMaxLength(draft, {reportID}); | ||
}, [draft, reportID, validateCommentMaxLength]); | ||
|
@@ -503,6 +522,8 @@ function ReportActionItemMessageEdit( | |
}); | ||
}); | ||
setShouldShowComposeInputKeyboardAware(false); | ||
// The last composer that had focus should re-gain focus | ||
setUpComposeFocusManager(); | ||
|
||
// Clear active report action when another action gets focused | ||
if (!EmojiPickerAction.isActive(action.reportActionID)) { | ||
|
@@ -546,11 +567,12 @@ function ReportActionItemMessageEdit( | |
<EmojiPickerButton | ||
isDisabled={shouldDisableEmojiPicker} | ||
onModalHide={() => { | ||
focus(true, emojiPickerSelectionRef.current ? {...emojiPickerSelectionRef.current} : undefined); | ||
ReportActionComposeFocusManager.focus(); | ||
}} | ||
onEmojiSelected={addEmojiToTextBox} | ||
id={emojiButtonID} | ||
emojiPickerID={action.reportActionID} | ||
onPress={setUpComposeFocusManager} | ||
/> | ||
</View> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.