2020-05-08 17:04:37 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View } from 'react-native';
|
2021-02-01 17:18:55 +00:00
|
|
|
import range from 'lodash/range';
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
import { themes } from '../../../constants/colors';
|
2022-03-23 00:43:59 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
const SIZE_EMPTY = 12;
|
|
|
|
const SIZE_FULL = 16;
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IPasscodeDots {
|
|
|
|
passcode: string;
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2022-03-23 00:43:59 +00:00
|
|
|
const Dots = React.memo(({ passcode, length }: IPasscodeDots) => {
|
|
|
|
const { theme } = useTheme();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.dotsContainer}>
|
|
|
|
{range(length).map(val => {
|
|
|
|
const lengthSup = passcode.length >= val + 1;
|
|
|
|
const height = lengthSup ? SIZE_FULL : SIZE_EMPTY;
|
|
|
|
const width = lengthSup ? SIZE_FULL : SIZE_EMPTY;
|
|
|
|
let backgroundColor = '';
|
|
|
|
if (lengthSup && passcode.length > 0) {
|
|
|
|
backgroundColor = themes[theme].passcodeDotFull;
|
|
|
|
} else {
|
|
|
|
backgroundColor = themes[theme].passcodeDotEmpty;
|
|
|
|
}
|
|
|
|
const borderRadius = lengthSup ? SIZE_FULL / 2 : SIZE_EMPTY / 2;
|
|
|
|
const marginRight = lengthSup ? 10 - (SIZE_FULL - SIZE_EMPTY) / 2 : 10;
|
|
|
|
const marginLeft = lengthSup ? 10 - (SIZE_FULL - SIZE_EMPTY) / 2 : 10;
|
|
|
|
return (
|
|
|
|
<View style={styles.dotsView}>
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
borderRadius,
|
|
|
|
backgroundColor,
|
|
|
|
marginRight,
|
|
|
|
marginLeft
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
export default Dots;
|