From 27259195f7abfea0cc09495395ba6eff51862563 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 23 Apr 2020 18:22:08 -0300 Subject: [PATCH] Shake --- app/containers/Passcode/Base/index.js | 10 +++++++--- app/containers/Passcode/PasscodeChoose.js | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/containers/Passcode/Base/index.js b/app/containers/Passcode/Base/index.js index 4542ab6ea..4740b4f5f 100644 --- a/app/containers/Passcode/Base/index.js +++ b/app/containers/Passcode/Base/index.js @@ -18,6 +18,7 @@ import { PASSCODE_LENGTH } from '../../../constants/localAuthentication'; const Base = forwardRef(({ theme, type, onEndProcess, previousPasscode, title, subtitle, onError }, ref) => { + const rootRef = useRef(); const dotsRef = useRef(); const [passcode, setPasscode] = useState(''); @@ -27,6 +28,10 @@ const Base = forwardRef(({ Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error); }; + const animate = (animation, duration = 500) => { + rootRef?.current?.[animation](duration); + }; + const onPressNumber = text => setPasscode((p) => { const currentPasscode = p + text; if (currentPasscode?.length === PASSCODE_LENGTH) { @@ -36,7 +41,6 @@ const Base = forwardRef(({ break; case TYPE.CONFIRM: if (currentPasscode !== previousPasscode) { - // alert('SHOW ERROR'); onError(); } else { onEndProcess(currentPasscode); @@ -62,11 +66,11 @@ const Base = forwardRef(({ }); useImperativeHandle(ref, () => ({ - wrongPasscode + wrongPasscode, animate })); return ( - + {title} diff --git a/app/containers/Passcode/PasscodeChoose.js b/app/containers/Passcode/PasscodeChoose.js index ae2987bc1..832840987 100644 --- a/app/containers/Passcode/PasscodeChoose.js +++ b/app/containers/Passcode/PasscodeChoose.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useRef } from 'react'; import PropTypes from 'prop-types'; import Base from './Base'; @@ -7,6 +7,7 @@ import { TYPE } from './constants'; const PasscodeEnter = ({ theme, type, finishProcess }) => { + const confirmRef = useRef(null); const [subtitle, setSubtitle] = useState(null); const [status, setStatus] = useState(type); const [previousPasscode, setPreviouPasscode] = useState(null); @@ -21,11 +22,13 @@ const PasscodeEnter = ({ const onError = () => { setStatus(TYPE.CHOOSE); setSubtitle('Passcodes don\'t match. Try again.'); + confirmRef?.current?.animate('shake'); }; if (status === TYPE.CONFIRM) { return (