From 97692b56d4981ec4a5f6d6494db1daa1a9fe490d Mon Sep 17 00:00:00 2001 From: Danh Date: Fri, 2 Jun 2023 11:03:25 +0700 Subject: [PATCH 1/7] try fix ios --- src/pages/Verify/VerifyCodeModal/OtpInput.tsx | 10 ++++++++-- src/pages/Verify/VerifyCodeModal/index.tsx | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/pages/Verify/VerifyCodeModal/OtpInput.tsx b/src/pages/Verify/VerifyCodeModal/OtpInput.tsx index 342b920ced..944460671e 100644 --- a/src/pages/Verify/VerifyCodeModal/OtpInput.tsx +++ b/src/pages/Verify/VerifyCodeModal/OtpInput.tsx @@ -39,6 +39,8 @@ interface OTPInputProps { inputStyle?: React.CSSProperties /** The type that will be passed to the input being rendered */ inputType?: AllowedInputTypes + onFocus?: () => void + onBlur?: () => void } const OTPInput = ({ @@ -50,6 +52,8 @@ const OTPInput = ({ inputType = 'text', containerStyle, inputStyle, + onFocus, + onBlur, }: OTPInputProps) => { const [activeInput, setActiveInput] = React.useState(0) const inputRefs = React.useRef>([]) @@ -95,10 +99,12 @@ const OTPInput = ({ } const handleFocus = () => (index: number) => { + onFocus?.() setActiveInput(index) } - const onBlur = () => { + const handleBlur = () => { + onBlur?.() setActiveInput(activeInput - 1) } @@ -194,7 +200,7 @@ const OTPInput = ({ ref: element => (inputRefs.current[index] = element), onChange: handleChange, onFocus: () => handleFocus()(index), - onBlur, + onBlur: handleBlur, onKeyDown, onPaste, autoComplete: 'off', diff --git a/src/pages/Verify/VerifyCodeModal/index.tsx b/src/pages/Verify/VerifyCodeModal/index.tsx index 8193a9fdfa..0e0c940e2c 100644 --- a/src/pages/Verify/VerifyCodeModal/index.tsx +++ b/src/pages/Verify/VerifyCodeModal/index.tsx @@ -89,14 +89,6 @@ export default function VerifyCodeModal({ const notify = useNotify() const [isTyping, setIsTyping] = useState(false) - useEffect(() => { - const onResize = () => { - setIsTyping(window.innerHeight < 450) - } - window.addEventListener('resize', onResize) - return () => window.removeEventListener('resize', onResize) - }, []) - const [expiredDuration, setExpireDuration] = useState(defaultTime) const canShowResend = expiredDuration < (timeExpire - 1) * TIMES_IN_SECS.ONE_MIN @@ -213,7 +205,16 @@ export default function VerifyCodeModal({ value={otp} onChange={onChange} numInputs={6} - renderInput={props => } + renderInput={props => ( + setIsTyping(true)} + onBlur={() => setIsTyping(false)} + /> + )} />