feat: focus secure text entry after successful biometrics input (#1785)

This commit is contained in:
Aman Harwara
2022-10-13 17:56:39 +05:30
committed by GitHub
parent 8553914d08
commit 8068fef4d3
2 changed files with 15 additions and 4 deletions

View File

@@ -214,6 +214,7 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
allowUniversalAccessFromFileURLs={true} allowUniversalAccessFromFileURLs={true}
injectedJavaScriptBeforeContentLoaded={injectedJS} injectedJavaScriptBeforeContentLoaded={injectedJS}
bounces={false} bounces={false}
keyboardDisplayRequiresUserAction={false}
/> />
) )
} }

View File

@@ -10,7 +10,7 @@ import {
removeFromArray, removeFromArray,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { ProtectedIllustration } from '@standardnotes/icons' import { ProtectedIllustration } from '@standardnotes/icons'
import { FunctionComponent, useCallback, useEffect, useState } from 'react' import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import Button from '@/Components/Button/Button' import Button from '@/Components/Button/Button'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import ChallengeModalPrompt from './ChallengePrompt' import ChallengeModalPrompt from './ChallengePrompt'
@@ -51,6 +51,8 @@ const ChallengeModal: FunctionComponent<Props> = ({
challenge, challenge,
onDismiss, onDismiss,
}) => { }) => {
const promptsContainerRef = useRef<HTMLFormElement>(null)
const [values, setValues] = useState<ChallengeModalValues>(() => { const [values, setValues] = useState<ChallengeModalValues>(() => {
const values = {} as ChallengeModalValues const values = {} as ChallengeModalValues
for (const prompt of challenge.prompts) { for (const prompt of challenge.prompts) {
@@ -175,14 +177,21 @@ const ChallengeModal: FunctionComponent<Props> = ({
const biometricPrompt = challenge.prompts.find((prompt) => prompt.validation === ChallengeValidation.Biometric) const biometricPrompt = challenge.prompts.find((prompt) => prompt.validation === ChallengeValidation.Biometric)
const hasOnlyBiometricPrompt = challenge.prompts.length === 1 && !!biometricPrompt const hasOnlyBiometricPrompt = challenge.prompts.length === 1 && !!biometricPrompt
const hasBiometricPromptValue = biometricPrompt && values[biometricPrompt.id].value const wasBiometricInputSuccessful = biometricPrompt && !!values[biometricPrompt.id].value
const hasSecureTextPrompt = challenge.prompts.some((prompt) => prompt.secureTextEntry)
useEffect(() => { useEffect(() => {
const shouldAutoSubmit = hasOnlyBiometricPrompt && hasBiometricPromptValue const shouldAutoSubmit = hasOnlyBiometricPrompt && wasBiometricInputSuccessful
const shouldFocusSecureTextPrompt = hasSecureTextPrompt && wasBiometricInputSuccessful
if (shouldAutoSubmit) { if (shouldAutoSubmit) {
submit() submit()
} else if (shouldFocusSecureTextPrompt) {
const secureTextEntry = promptsContainerRef.current?.querySelector(
'input[type="password"]',
) as HTMLInputElement | null
secureTextEntry?.focus()
} }
}, [hasBiometricPromptValue, hasOnlyBiometricPrompt, submit]) }, [wasBiometricInputSuccessful, hasOnlyBiometricPrompt, submit, hasSecureTextPrompt])
useEffect(() => { useEffect(() => {
const removeListener = application.addAndroidBackHandlerEventListener(() => { const removeListener = application.addAndroidBackHandlerEventListener(() => {
@@ -239,6 +248,7 @@ const ChallengeModal: FunctionComponent<Props> = ({
e.preventDefault() e.preventDefault()
submit() submit()
}} }}
ref={promptsContainerRef}
> >
{challenge.prompts.map((prompt, index) => ( {challenge.prompts.map((prompt, index) => (
<ChallengeModalPrompt <ChallengeModalPrompt