From 3f3eaf115d1a4b65fdea2ffe8e1ea4b302eb8db2 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Wed, 17 Feb 2021 18:07:17 -0300 Subject: [PATCH] fix: fix keyboard switching --- src/screens/Authenticate/Authenticate.tsx | 27 +++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/screens/Authenticate/Authenticate.tsx b/src/screens/Authenticate/Authenticate.tsx index f18e1c18..bd966b94 100644 --- a/src/screens/Authenticate/Authenticate.tsx +++ b/src/screens/Authenticate/Authenticate.tsx @@ -30,6 +30,7 @@ import React, { import { Alert, BackHandler, + Keyboard, Platform, ScrollView, TextInput, @@ -86,10 +87,11 @@ export const Authenticate = ({ >(undefined); const [keyboardType, setKeyboardType] = useState< PasscodeKeyboardType | undefined - >(undefined); + >(PasscodeKeyboardType.Default); const [singleValidation] = useState( () => !(challenge.prompts.filter(prompt => prompt.validates).length > 0) ); + const [showSwitchKeyboard, setShowSwitchKeyboard] = useState(false); const [{ challengeValues, challengeValueStates }, dispatch] = useReducer( authenticationReducer, @@ -526,11 +528,16 @@ export const Authenticate = ({ }, []); const onBiometricDirectPress = () => { + Keyboard.dismiss(); + const biometricChallengeValue = Object.values(challengeValues).find( value => value.prompt.validation === ChallengeValidation.Biometric ); const state = challengeValueStates[biometricChallengeValue?.prompt.id!]; - if (state === AuthenticationValueStateType.Locked) { + if ( + state === AuthenticationValueStateType.Locked || + state === AuthenticationValueStateType.Success + ) { return; } @@ -538,6 +545,8 @@ export const Authenticate = ({ }; const onValueChange = (newValue: ChallengeValue) => { + Keyboard.dismiss(); + dispatch({ type: 'setValue', id: newValue.prompt.id.toString(), @@ -581,10 +590,10 @@ export const Authenticate = ({ }; const switchKeyboard = () => { - if (keyboardType === PasscodeKeyboardType.Default) { - setKeyboardType(PasscodeKeyboardType.Numeric); - } else if (keyboardType === PasscodeKeyboardType.Numeric) { + if (keyboardType === PasscodeKeyboardType.Numeric) { setKeyboardType(PasscodeKeyboardType.Default); + } else { + setKeyboardType(PasscodeKeyboardType.Numeric); } }; @@ -625,9 +634,7 @@ export const Authenticate = ({ tinted={active} buttonText={ challengeValue.prompt.validation === - ChallengeValidation.LocalPasscode && - (state === AuthenticationValueStateType.WaitingInput || - state === AuthenticationValueStateType.Fail) + ChallengeValidation.LocalPasscode && showSwitchKeyboard ? 'Change Keyboard' : undefined } @@ -676,6 +683,8 @@ export const Authenticate = ({ } : undefined } + onFocus={() => setShowSwitchKeyboard(true)} + onBlur={() => setShowSwitchKeyboard(false)} /> @@ -753,7 +762,7 @@ export const Authenticate = ({ behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={headerHeight} > - + {(challenge.heading || challenge.subheading) && (