Animate dots on error

This commit is contained in:
Diego Mello 2020-04-23 17:44:00 -03:00
parent f11c924521
commit 570e9715ac
4 changed files with 14 additions and 17 deletions

View File

@ -87,6 +87,7 @@ module.exports = {
"no-regex-spaces": 2, "no-regex-spaces": 2,
"no-undef": 2, "no-undef": 2,
"no-unreachable": 2, "no-unreachable": 2,
"no-unused-expressions": 0,
"no-unused-vars": [2, { "no-unused-vars": [2, {
"vars": "all", "vars": "all",
"args": "after-used" "args": "after-used"

View File

@ -1,25 +1,30 @@
import React, { useState, forwardRef, useImperativeHandle } from 'react'; import React, {
useState, forwardRef, useImperativeHandle, useRef
} from 'react';
import { View, Text } from 'react-native'; import { View, Text } from 'react-native';
import { Col, Row, Grid } from 'react-native-easy-grid'; import { Col, Row, Grid } from 'react-native-easy-grid';
import _ from 'lodash'; import _ from 'lodash';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import * as Animatable from 'react-native-animatable';
import * as Haptics from 'expo-haptics';
import styles from './styles'; import styles from './styles';
import Button from './Button'; import Button from './Button';
import Dots from './Dots'; import Dots from './Dots';
import { TYPE } from '../constants'; import { TYPE } from '../constants';
import { themes } from '../../../constants/colors'; import { themes } from '../../../constants/colors';
import { PASSCODE_LENGTH } from '../../../constants/localAuthentication';
const PASSCODE_LENGTH = 6;
const Base = forwardRef(({ const Base = forwardRef(({
theme, type, onEndProcess, previousPasscode, title, subtitle theme, type, onEndProcess, previousPasscode, title, subtitle
}, ref) => { }, ref) => {
const dotsRef = useRef();
const [passcode, setPasscode] = useState(''); const [passcode, setPasscode] = useState('');
const wrongPasscode = () => { const wrongPasscode = () => {
setPasscode(''); setPasscode('');
console.log('TODO: wrong animation and vibration'); dotsRef?.current?.shake(500);
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
}; };
const onPressNumber = text => setPasscode((p) => { const onPressNumber = text => setPasscode((p) => {
@ -27,27 +32,17 @@ const Base = forwardRef(({
if (currentPasscode?.length === PASSCODE_LENGTH) { if (currentPasscode?.length === PASSCODE_LENGTH) {
switch (type) { switch (type) {
case TYPE.CHOOSE: case TYPE.CHOOSE:
// if (this.props.validationRegex && this.props.validationRegex.test(currentPasscode)) {
// this.showError(true);
// } else {
// // this.endProcess(currentPasscode);
onEndProcess(currentPasscode); onEndProcess(currentPasscode);
// }
break; break;
case TYPE.CONFIRM: case TYPE.CONFIRM:
console.log('currentPasscode', currentPasscode, previousPasscode);
if (currentPasscode !== previousPasscode) { if (currentPasscode !== previousPasscode) {
// this.showError();
alert('SHOW ERROR'); alert('SHOW ERROR');
} else { } else {
// this.endProcess(currentPasscode);
onEndProcess(currentPasscode); onEndProcess(currentPasscode);
} }
break; break;
case TYPE.ENTER: case TYPE.ENTER:
// this.props.endProcess(currentPasscode);
onEndProcess(currentPasscode); onEndProcess(currentPasscode);
// await delay(300);
break; break;
default: default:
break; break;
@ -76,9 +71,9 @@ const Base = forwardRef(({
<Text style={[styles.textTitle, { color: themes[theme].titleText }]}>{title}</Text> <Text style={[styles.textTitle, { color: themes[theme].titleText }]}>{title}</Text>
{subtitle ? <Text style={[styles.textSubtitle, { color: themes[theme].bodyText }]}>{subtitle}</Text> : null} {subtitle ? <Text style={[styles.textSubtitle, { color: themes[theme].bodyText }]}>{subtitle}</Text> : null}
</View> </View>
<View style={styles.flexCirclePasscode}> <Animatable.View ref={dotsRef} style={styles.flexCirclePasscode}>
<Dots passcode={passcode} theme={theme} length={PASSCODE_LENGTH} /> <Dots passcode={passcode} theme={theme} length={PASSCODE_LENGTH} />
</View> </Animatable.View>
<Grid style={styles.grid}> <Grid style={styles.grid}>
<Row style={styles.row}> <Row style={styles.row}>
{_.range(1, 4).map(i => ( {_.range(1, 4).map(i => (

View File

@ -53,6 +53,7 @@
"react": "16.9.0", "react": "16.9.0",
"react-native": "0.61.5", "react-native": "0.61.5",
"react-native-action-sheet": "^2.2.0", "react-native-action-sheet": "^2.2.0",
"react-native-animatable": "^1.3.3",
"react-native-appearance": "^0.3.1", "react-native-appearance": "^0.3.1",
"react-native-audio": "^4.3.0", "react-native-audio": "^4.3.0",
"react-native-background-timer": "2.1.1", "react-native-background-timer": "2.1.1",

View File

@ -9912,7 +9912,7 @@ react-native-action-sheet@^2.2.0:
resolved "https://registry.yarnpkg.com/react-native-action-sheet/-/react-native-action-sheet-2.2.0.tgz#309a87f53bf4e7b17fdd9d24b10b8dcbaebb7230" resolved "https://registry.yarnpkg.com/react-native-action-sheet/-/react-native-action-sheet-2.2.0.tgz#309a87f53bf4e7b17fdd9d24b10b8dcbaebb7230"
integrity sha512-4lsuxH+Cn3/aUEs1VCwqvLhEFyXNqYTkT67CzgTwlifD9Ij4OPQAIs8D+HUD9zBvWc4NtT6cyG1lhArPVMQeVw== integrity sha512-4lsuxH+Cn3/aUEs1VCwqvLhEFyXNqYTkT67CzgTwlifD9Ij4OPQAIs8D+HUD9zBvWc4NtT6cyG1lhArPVMQeVw==
react-native-animatable@1.3.3: react-native-animatable@1.3.3, react-native-animatable@^1.3.3:
version "1.3.3" version "1.3.3"
resolved "https://registry.yarnpkg.com/react-native-animatable/-/react-native-animatable-1.3.3.tgz#a13a4af8258e3bb14d0a9d839917e9bb9274ec8a" resolved "https://registry.yarnpkg.com/react-native-animatable/-/react-native-animatable-1.3.3.tgz#a13a4af8258e3bb14d0a9d839917e9bb9274ec8a"
integrity sha512-2ckIxZQAsvWn25Ho+DK3d1mXIgj7tITkrS4pYDvx96WyOttSvzzFeQnM2od0+FUMzILbdHDsDEqZvnz1DYNQ1w== integrity sha512-2ckIxZQAsvWn25Ho+DK3d1mXIgj7tITkrS4pYDvx96WyOttSvzzFeQnM2od0+FUMzILbdHDsDEqZvnz1DYNQ1w==