From 50e7b280d74931d1ae4af301676cede93e343be2 Mon Sep 17 00:00:00 2001 From: Sochima Biereagu Date: Sat, 11 Sep 2021 14:49:08 +0100 Subject: [PATCH 1/2] Several code improvements --- App.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/App.tsx b/App.tsx index 84303a33..8ab27601 100644 --- a/App.tsx +++ b/App.tsx @@ -14,10 +14,17 @@ const CodeInput = () => { const [code, setCode] = useState(''); const [containerIsFocused, setContainerIsFocused] = useState(false); - const codeDigitsArray = new Array(CODE_LENGTH); + const codeDigitsArray = [...Array(CODE_LENGTH)]; const ref = useRef(null); + const setCodeInput = (input: string) => { + if (input.length === 0) setCode(input); + const last = input[input.length - 1]; + // make sure the input is numeric before updating + if (+last >= 0 && +last <= 9) setCode(input); + }; + const handleOnPress = () => { setContainerIsFocused(true); ref?.current?.focus(); @@ -37,10 +44,10 @@ const CodeInput = () => { const isFocused = isCurrentDigit || (isLastDigit && isCodeFull); - const containerStyle = - containerIsFocused && isFocused - ? {...style.inputContainer, ...style.inputContainerFocused} - : style.inputContainer; + const containerStyle = [ + style.code_input_inputContainer, + isFocused && containerIsFocused && style.code_input_inputContainerFocused, + ]; return ( @@ -57,8 +64,9 @@ const CodeInput = () => { Date: Sat, 11 Sep 2021 17:07:29 +0100 Subject: [PATCH 2/2] Update App.tsx --- App.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/App.tsx b/App.tsx index 8ab27601..492824e5 100644 --- a/App.tsx +++ b/App.tsx @@ -21,6 +21,7 @@ const CodeInput = () => { const setCodeInput = (input: string) => { if (input.length === 0) setCode(input); const last = input[input.length - 1]; + if (last?.trim() === '') return; // ignore space, (+' ') == 0 // make sure the input is numeric before updating if (+last >= 0 && +last <= 9) setCode(input); };