diff --git a/app/containers/Passcode/ButtonNumber.js b/app/containers/Passcode/Button.js similarity index 79% rename from app/containers/Passcode/ButtonNumber.js rename to app/containers/Passcode/Button.js index 1d72c01dd..3f3417e6f 100644 --- a/app/containers/Passcode/ButtonNumber.js +++ b/app/containers/Passcode/Button.js @@ -2,21 +2,25 @@ import React from 'react'; import { TouchableHighlight, Text } from 'react-native'; import styles from './styles'; +import { themes } from '../../constants/colors'; -const ButtonNumber = ({ text }) => ( +const ButtonNumber = ({ + text, disabled, theme, onPress +}) => ( this.setState({ textButtonSelected: text })} // onHideUnderlay={() => this.setState({ textButtonSelected: "" })} // onPress={() => { // this.onPressButtonNumber(text); // }} + onPress={() => onPress && onPress(text)} // accessible // accessibilityLabel={text} > diff --git a/app/containers/Passcode/PasscodeDots.js b/app/containers/Passcode/Dots.js similarity index 79% rename from app/containers/Passcode/PasscodeDots.js rename to app/containers/Passcode/Dots.js index 11c7bf4f4..9cd9c2128 100644 --- a/app/containers/Passcode/PasscodeDots.js +++ b/app/containers/Passcode/Dots.js @@ -5,28 +5,28 @@ import _ from 'lodash'; import styles from './styles'; import { themes } from '../../constants/colors'; -const PASSWORD_LENGTH = 6; const SIZE_EMPTY = 8; const SIZE_FULL = 12; -const PasscodeDots = ({ - password, +const Dots = ({ + passcode, moveData, showError, changeScreen, attemptFailed, - theme + theme, + length }) => ( - - {_.range(PASSWORD_LENGTH).map((val) => { - const lengthSup = ((password.length >= val + 1 && !changeScreen) || showError) && !attemptFailed; + + {_.range(length).map((val) => { + const lengthSup = ((passcode.length >= val + 1 && !changeScreen) || showError) && !attemptFailed; const opacity = lengthSup ? 1 : 0.5; const height = lengthSup ? SIZE_FULL : SIZE_EMPTY; const width = lengthSup ? SIZE_FULL : SIZE_EMPTY; let color = ''; if (showError) { color = themes[theme].dangerColor; - } else if (lengthSup && password.length > 0) { + } else if (lengthSup && passcode.length > 0) { color = themes[theme].titleText; } else { color = themes[theme].bodyText; @@ -59,4 +59,4 @@ const PasscodeDots = ({ ); -export default PasscodeDots; +export default Dots; diff --git a/app/containers/Passcode/index.js b/app/containers/Passcode/index.js index 82c3c69df..99caf6bb9 100644 --- a/app/containers/Passcode/index.js +++ b/app/containers/Passcode/index.js @@ -1,112 +1,79 @@ -import React from 'react'; +import React, { useState } from 'react'; import { View } from 'react-native'; import { Col, Row, Grid } from 'react-native-easy-grid'; import _ from 'lodash'; import styles from './styles'; -import ButtonNumber from './ButtonNumber'; -import PasscodeDots from './PasscodeDots'; +import Button from './Button'; +import Dots from './Dots'; import Title from './Title'; import Subtitle from './Subtitle'; +const PASSCODE_LENGTH = 6; + const Passcode = ({ theme }) => { + const [passcode, setPasscode] = useState(''); + + const handleEnd = () => { + alert('END') + }; + + const onPressNumber = text => setPasscode((p) => { + const newPasscode = p + text; + if (newPasscode?.length === PASSCODE_LENGTH) { + handleEnd(); + return ''; + } + return newPasscode; + }); + + const onPressDelete = () => setPasscode((p) => { + if (p?.length > 0) { + const newPasscode = p.slice(0, -1); + return newPasscode; + } + return ''; + }); + return ( - - - + + + <Subtitle theme={theme} /> </View> - <View style={styles.flexCirclePassword}> - <PasscodeDots password='123' theme={theme} /> + <View style={styles.flexCirclePasscode}> + <Dots passcode={passcode} theme={theme} length={PASSCODE_LENGTH} /> </View> <Grid style={styles.grid}> - <Row - style={[ - styles.row - ]} - > + <Row style={styles.row}> {_.range(1, 4).map(i => ( - <Col - key={i} - style={[ - styles.colButtonCircle - ]} - > - <ButtonNumber text={i} /> + <Col key={i} style={styles.colButtonCircle}> + <Button text={i} theme={theme} onPress={onPressNumber} /> </Col> ))} </Row> - <Row - style={[ - styles.row - ]} - > + <Row style={styles.row}> {_.range(4, 7).map(i => ( - <Col - key={i} - style={[ - styles.colButtonCircle - ]} - > - <ButtonNumber text={i} /> + <Col key={i} style={styles.colButtonCircle}> + <Button text={i} theme={theme} onPress={onPressNumber} /> </Col> ))} </Row> - <Row - style={[ - styles.row - ]} - > + <Row style={styles.row}> {_.range(7, 10).map(i => ( - <Col - key={i} - style={[ - styles.colButtonCircle - ]} - > - <ButtonNumber text={i} /> + <Col key={i} style={styles.colButtonCircle}> + <Button text={i} theme={theme} onPress={onPressNumber} /> </Col> ))} </Row> - <Row - style={[ - styles.row - ]} - > - <Col - style={[ - styles.colButtonCircle - ]} - /> - <Col - style={[ - styles.colButtonCircle - ]} - > - <ButtonNumber text='0' /> + <Row style={styles.row}> + <Col style={styles.colButtonCircle} /> + <Col style={styles.colButtonCircle}> + <Button text='0' theme={theme} onPress={onPressNumber} /> </Col> - <Col - style={[ - styles.colButtonCircle - ]} - > - <ButtonNumber text='X' /> + <Col style={styles.colButtonCircle}> + <Button text='X' theme={theme} onPress={onPressDelete} /> </Col> </Row> </Grid> diff --git a/app/containers/Passcode/styles.js b/app/containers/Passcode/styles.js index 03f7b4d61..617d924e0 100644 --- a/app/containers/Passcode/styles.js +++ b/app/containers/Passcode/styles.js @@ -68,12 +68,12 @@ export default StyleSheet.create({ fontWeight: '200', textAlign: 'center' }, - flexCirclePassword: { + flexCirclePasscode: { flex: 2, justifyContent: 'center', alignItems: 'center' }, - topViewCirclePassword: { + topViewCirclePasscode: { flexDirection: 'row', height: 'auto', justifyContent: 'center',