From 74c85b4eb3443d342f6c103343ef7bf3e4545b5d Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 11 Oct 2023 22:06:38 +0700 Subject: [PATCH 1/2] fix: 28841 keyboard opens for a second when user switches to password protected PDF --- .../Attachments/AttachmentCarousel/index.native.js | 4 ++-- src/components/PDFView/PDFPasswordForm.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/Attachments/AttachmentCarousel/index.native.js b/src/components/Attachments/AttachmentCarousel/index.native.js index bd12020341be..bcea50698b3b 100644 --- a/src/components/Attachments/AttachmentCarousel/index.native.js +++ b/src/components/Attachments/AttachmentCarousel/index.native.js @@ -104,10 +104,10 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose, * @returns {JSX.Element} */ const renderItem = useCallback( - ({item}) => ( + ({item, isActive}) => ( setShouldShowArrows(!shouldShowArrows)} /> ), diff --git a/src/components/PDFView/PDFPasswordForm.js b/src/components/PDFView/PDFPasswordForm.js index 42d2202de8b7..76764ca96a86 100644 --- a/src/components/PDFView/PDFPasswordForm.js +++ b/src/components/PDFView/PDFPasswordForm.js @@ -50,6 +50,8 @@ function PDFPasswordForm({isFocused, isPasswordInvalid, shouldShowLoadingIndicat const [shouldShowForm, setShouldShowForm] = useState(false); const textInputRef = useRef(null); + const focusTimeoutRef = useRef(null); + const errorText = useMemo(() => { if (isPasswordInvalid) { return translate('attachmentView.passwordIncorrect'); @@ -67,7 +69,15 @@ function PDFPasswordForm({isFocused, isPasswordInvalid, shouldShowLoadingIndicat if (!textInputRef.current) { return; } - textInputRef.current.focus(); + focusTimeoutRef.current = setTimeout(() => { + textInputRef.current.focus(); + }, CONST.ANIMATED_TRANSITION); + return () => { + if (!focusTimeoutRef.current) { + return; + } + clearTimeout(focusTimeoutRef.current); + }; }, [isFocused]); const updatePassword = (newPassword) => { From 0a7b80be93eddab1ae39d6eb46ec6915ea983793 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 16 Oct 2023 18:13:57 +0700 Subject: [PATCH 2/2] fix: add comment --- src/components/PDFView/PDFPasswordForm.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/PDFView/PDFPasswordForm.js b/src/components/PDFView/PDFPasswordForm.js index 76764ca96a86..58a4e64a28a5 100644 --- a/src/components/PDFView/PDFPasswordForm.js +++ b/src/components/PDFView/PDFPasswordForm.js @@ -69,6 +69,10 @@ function PDFPasswordForm({isFocused, isPasswordInvalid, shouldShowLoadingIndicat if (!textInputRef.current) { return; } + /** + * We recommend using setTimeout to wait for the animation to finish and then focus on the input + * Relevant thread: https://expensify.slack.com/archives/C01GTK53T8Q/p1694660990479979 + */ focusTimeoutRef.current = setTimeout(() => { textInputRef.current.focus(); }, CONST.ANIMATED_TRANSITION);