Skip to content

Commit

Permalink
Merge pull request #25981 from rushatgabhane/fix-crash
Browse files Browse the repository at this point in the history
Don't focus when ref composer is unmounted
  • Loading branch information
mountiny authored Aug 28, 2023
2 parents a14511a + ca245d1 commit 165e1b8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pages/home/report/ReportActionCompose/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,19 @@ function ReportActionCompose({
return translate('reportActionCompose.writeSomething');
}, [report, blockedFromConcierge, translate, conciergePlaceholderRandomIndex]);

const focus = () => {
if (composerRef === null || composerRef.current === null) {
return;
}
composerRef.current.focus(true);
};

const isKeyboardVisibleWhenShowingModalRef = useRef(false);
const restoreKeyboardState = useCallback(() => {
if (!isKeyboardVisibleWhenShowingModalRef.current) {
return;
}
composerRef.current.focus(true);
focus();
isKeyboardVisibleWhenShowingModalRef.current = false;
}, []);

Expand Down Expand Up @@ -403,7 +410,7 @@ function ReportActionCompose({
{DeviceCapabilities.canUseTouchScreen() && isMediumScreenWidth ? null : (
<EmojiPickerButton
isDisabled={isBlockedFromConcierge || disabled}
onModalHide={() => composerRef.current.focus(true)}
onModalHide={focus}
onEmojiSelected={(...args) => composerRef.current.replaceSelectionWithText(...args)}
emojiPickerID={report.reportID}
/>
Expand Down

0 comments on commit 165e1b8

Please sign in to comment.