2021-09-13 20:41:05 +00:00
|
|
|
import React, { useRef, useState } from 'react';
|
2020-05-08 17:04:37 +00:00
|
|
|
import * as Haptics from 'expo-haptics';
|
|
|
|
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
|
|
|
|
|
2022-03-23 00:43:59 +00:00
|
|
|
import Base, { IBase } from './Base';
|
2020-05-08 17:04:37 +00:00
|
|
|
import { TYPE } from './constants';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IPasscodeChoose {
|
2021-11-10 20:50:38 +00:00
|
|
|
force?: boolean;
|
2021-09-13 20:41:05 +00:00
|
|
|
finishProcess: Function;
|
|
|
|
}
|
|
|
|
|
2022-03-23 00:43:59 +00:00
|
|
|
const PasscodeChoose = ({ finishProcess, force = false }: IPasscodeChoose) => {
|
|
|
|
const chooseRef = useRef<IBase>(null);
|
|
|
|
const confirmRef = useRef<IBase>(null);
|
2022-04-14 20:30:41 +00:00
|
|
|
const [subtitle, setSubtitle] = useState<string | null>(null);
|
2020-05-08 17:04:37 +00:00
|
|
|
const [status, setStatus] = useState(TYPE.CHOOSE);
|
2022-03-23 00:43:59 +00:00
|
|
|
const [previousPasscode, setPreviouPasscode] = useState('');
|
2020-05-08 17:04:37 +00:00
|
|
|
|
2022-03-23 00:43:59 +00:00
|
|
|
const firstStep = (p: string) => {
|
2020-05-08 17:04:37 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
setStatus(TYPE.CONFIRM);
|
|
|
|
setPreviouPasscode(p);
|
|
|
|
confirmRef?.current?.clearPasscode();
|
|
|
|
}, 200);
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const changePasscode = (p: string) => finishProcess && finishProcess(p);
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
const onError = () => {
|
|
|
|
setTimeout(() => {
|
|
|
|
setStatus(TYPE.CHOOSE);
|
|
|
|
setSubtitle(I18n.t('Passcode_choose_error'));
|
|
|
|
chooseRef?.current?.animate('shake');
|
|
|
|
chooseRef?.current?.clearPasscode();
|
|
|
|
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
|
|
|
|
}, 200);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status === TYPE.CONFIRM) {
|
|
|
|
return (
|
|
|
|
<Base
|
|
|
|
ref={confirmRef}
|
|
|
|
type={TYPE.CONFIRM}
|
|
|
|
onEndProcess={changePasscode}
|
|
|
|
previousPasscode={previousPasscode}
|
|
|
|
title={I18n.t('Passcode_choose_confirm_title')}
|
|
|
|
onError={onError}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Base
|
|
|
|
ref={chooseRef}
|
|
|
|
type={TYPE.CHOOSE}
|
|
|
|
onEndProcess={firstStep}
|
|
|
|
title={I18n.t('Passcode_choose_title')}
|
|
|
|
subtitle={subtitle || (force ? I18n.t('Passcode_choose_force_set') : null)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default gestureHandlerRootHOC(PasscodeChoose);
|