Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 28841 keyboard opens for a second when user switches to password protected PDF #29331

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose,
* @returns {JSX.Element}
*/
const renderItem = useCallback(
({item}) => (
({item, isActive}) => (
<CarouselItem
item={item}
isFocused={activeSource === item.source}
isFocused={isActive && activeSource === item.source}
onPress={() => setShouldShowArrows(!shouldShowArrows)}
/>
),
Expand Down
16 changes: 15 additions & 1 deletion src/components/PDFView/PDFPasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -67,7 +69,19 @@ function PDFPasswordForm({isFocused, isPasswordInvalid, shouldShowLoadingIndicat
if (!textInputRef.current) {
return;
}
textInputRef.current.focus();
/**
* 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(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the comment with the link to Slack comment posted by Rory explaining why we should use setTimeout here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burczu Do we really need it? As this approach is used in many places in our app

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do - in general we are trying to avoid using setTimeout in the app so describing why we had to use it is a good habit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment

textInputRef.current.focus();
}, CONST.ANIMATED_TRANSITION);
return () => {
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, [isFocused]);

const updatePassword = (newPassword) => {
Expand Down
Loading