Skip to content

Commit

Permalink
Merge pull request Expensify#26221 from ntdiary/fix-reopen-keyboard
Browse files Browse the repository at this point in the history
reopen keyboard when tap back on gallery page.
  • Loading branch information
aldo-expensify authored Sep 13, 2023
2 parents 2d5bea5 + 63904ab commit 9de0815
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/AttachmentPicker/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -53,7 +54,23 @@ function AttachmentPicker(props) {
if (!fileInput.current) {
return;
}
fileInput.current.addEventListener('cancel', () => onCanceled.current(), {once: true});
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;
}
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
onCanceled.current();
unsubscribeVisibilityListener();
});
},
{once: true},
);
}}
accept={getAcceptableFileTypes(props.type)}
/>
Expand Down

0 comments on commit 9de0815

Please sign in to comment.