From a450e95b31bd0218013e27a5b4c91eb39e7ace56 Mon Sep 17 00:00:00 2001 From: ntdiary <2471314@gmail.com> Date: Tue, 29 Aug 2023 23:13:36 +0800 Subject: [PATCH 1/4] reopen keyboard when tap back on gallery page. --- src/components/AttachmentPicker/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/AttachmentPicker/index.js b/src/components/AttachmentPicker/index.js index 9ea94ae53d42..8a2e8835a3c5 100644 --- a/src/components/AttachmentPicker/index.js +++ b/src/components/AttachmentPicker/index.js @@ -1,6 +1,7 @@ import React, {useRef} from 'react'; import CONST from '../../CONST'; import {propTypes, defaultProps} from './attachmentPickerPropTypes'; +import Visibility from '../../libs/Visibility'; /** * Returns acceptable FileTypes based on ATTACHMENT_PICKER_TYPE @@ -53,7 +54,16 @@ function AttachmentPicker(props) { if (!fileInput.current) { return; } - fileInput.current.addEventListener('cancel', () => onCanceled.current(), {once: true}); + fileInput.current.addEventListener('cancel', () => { + if (Visibility.isVisible()) { + onCanceled.current(); + return; + } + const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => { + onCanceled.current(); + unsubscribeVisibilityListener(); + }); + }, {once: true}); }} accept={getAcceptableFileTypes(props.type)} /> From a70314254b230d149d99653bcff1f9bb7cd74431 Mon Sep 17 00:00:00 2001 From: ntdiary <2471314@gmail.com> Date: Tue, 29 Aug 2023 23:40:32 +0800 Subject: [PATCH 2/4] fix lint error --- src/components/AttachmentPicker/index.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/AttachmentPicker/index.js b/src/components/AttachmentPicker/index.js index 8a2e8835a3c5..324cc0461c7d 100644 --- a/src/components/AttachmentPicker/index.js +++ b/src/components/AttachmentPicker/index.js @@ -54,16 +54,20 @@ function AttachmentPicker(props) { if (!fileInput.current) { return; } - fileInput.current.addEventListener('cancel', () => { - if (Visibility.isVisible()) { - onCanceled.current(); - return; - } - const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => { - onCanceled.current(); - unsubscribeVisibilityListener(); - }); - }, {once: true}); + fileInput.current.addEventListener( + 'cancel', + () => { + if (Visibility.isVisible()) { + onCanceled.current(); + return; + } + const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => { + onCanceled.current(); + unsubscribeVisibilityListener(); + }); + }, + {once: true}, + ); }} accept={getAcceptableFileTypes(props.type)} /> From 08a94be8e60846fa6ca7f14c4bf00d919b462c1b Mon Sep 17 00:00:00 2001 From: ntdiary <2471314@gmail.com> Date: Thu, 31 Aug 2023 11:55:12 +0800 Subject: [PATCH 3/4] add a comment for visibility listener --- src/components/AttachmentPicker/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/AttachmentPicker/index.js b/src/components/AttachmentPicker/index.js index 324cc0461c7d..ea3a05b41719 100644 --- a/src/components/AttachmentPicker/index.js +++ b/src/components/AttachmentPicker/index.js @@ -57,6 +57,9 @@ function AttachmentPicker(props) { fileInput.current.addEventListener( 'cancel', () => { + // For Android Chrome, the cancel event happens before the page is visible on physical devices, + // which makes it unreliable for us to show the keyboard, while on emulators it happens after the page is visible. + // So here we can delay calling the onCanceled.current function based on visibility in order to reliably show the keyboard. if (Visibility.isVisible()) { onCanceled.current(); return; From 877b75d57a69378d5d8262c971f11a123263f789 Mon Sep 17 00:00:00 2001 From: ntdiary <2471314@gmail.com> Date: Thu, 31 Aug 2023 11:56:02 +0800 Subject: [PATCH 4/4] fix lint --- src/components/AttachmentPicker/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AttachmentPicker/index.js b/src/components/AttachmentPicker/index.js index ea3a05b41719..9930fa49a909 100644 --- a/src/components/AttachmentPicker/index.js +++ b/src/components/AttachmentPicker/index.js @@ -59,7 +59,7 @@ function AttachmentPicker(props) { () => { // For Android Chrome, the cancel event happens before the page is visible on physical devices, // which makes it unreliable for us to show the keyboard, while on emulators it happens after the page is visible. - // So here we can delay calling the onCanceled.current function based on visibility in order to reliably show the keyboard. + // So here we can delay calling the onCanceled.current function based on visibility in order to reliably show the keyboard. if (Visibility.isVisible()) { onCanceled.current(); return;