Skip to content

Commit 9de0815

Browse files
Merge pull request #26221 from ntdiary/fix-reopen-keyboard
reopen keyboard when tap back on gallery page.
2 parents 2d5bea5 + 63904ab commit 9de0815

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/components/AttachmentPicker/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {useRef} from 'react';
22
import CONST from '../../CONST';
33
import {propTypes, defaultProps} from './attachmentPickerPropTypes';
4+
import Visibility from '../../libs/Visibility';
45

56
/**
67
* Returns acceptable FileTypes based on ATTACHMENT_PICKER_TYPE
@@ -53,7 +54,23 @@ function AttachmentPicker(props) {
5354
if (!fileInput.current) {
5455
return;
5556
}
56-
fileInput.current.addEventListener('cancel', () => onCanceled.current(), {once: true});
57+
fileInput.current.addEventListener(
58+
'cancel',
59+
() => {
60+
// For Android Chrome, the cancel event happens before the page is visible on physical devices,
61+
// which makes it unreliable for us to show the keyboard, while on emulators it happens after the page is visible.
62+
// So here we can delay calling the onCanceled.current function based on visibility in order to reliably show the keyboard.
63+
if (Visibility.isVisible()) {
64+
onCanceled.current();
65+
return;
66+
}
67+
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
68+
onCanceled.current();
69+
unsubscribeVisibilityListener();
70+
});
71+
},
72+
{once: true},
73+
);
5774
}}
5875
accept={getAcceptableFileTypes(props.type)}
5976
/>

0 commit comments

Comments
 (0)