From e88680be363e5ce2c4b56a41afd82268711ef32c Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 25 Oct 2024 16:45:14 +0800 Subject: [PATCH 1/2] disable immediate autofocus, except for mobile safari --- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx index 02121ce26906..024e12fec56f 100644 --- a/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -16,6 +16,7 @@ import useNetwork from '@hooks/useNetwork'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import * as Browser from '@libs/Browser'; import * as ErrorUtils from '@libs/ErrorUtils'; import * as ValidationUtils from '@libs/ValidationUtils'; import * as User from '@userActions/User'; @@ -116,9 +117,15 @@ function BaseValidateCodeForm({ if (focusTimeoutRef.current) { clearTimeout(focusTimeoutRef.current); } - focusTimeoutRef.current = setTimeout(() => { + + if (!Browser.isMobileSafari()) { + focusTimeoutRef.current = setTimeout(() => { + inputValidateCodeRef.current?.focusLastSelected(); + }, CONST.ANIMATED_TRANSITION); + } else { inputValidateCodeRef.current?.focusLastSelected(); - }, CONST.ANIMATED_TRANSITION); + } + return () => { if (!focusTimeoutRef.current) { return; @@ -188,7 +195,7 @@ function BaseValidateCodeForm({ errorText={formError?.validateCode ? translate(formError?.validateCode) : ErrorUtils.getLatestErrorMessage(account ?? {})} hasError={!isEmptyObject(validateError)} onFulfill={validateAndSubmitForm} - autoFocus + autoFocus={false} /> Date: Tue, 29 Oct 2024 10:55:20 +0800 Subject: [PATCH 2/2] add comment --- .../ValidateCodeForm/BaseValidateCodeForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx b/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx index 024e12fec56f..2e8b7f5dfbda 100644 --- a/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx +++ b/src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx @@ -118,6 +118,7 @@ function BaseValidateCodeForm({ clearTimeout(focusTimeoutRef.current); } + // Keyboard won't show if we focus the input with a delay, so we need to focus immediately. if (!Browser.isMobileSafari()) { focusTimeoutRef.current = setTimeout(() => { inputValidateCodeRef.current?.focusLastSelected();