added pin prompt

This commit is contained in:
Ksenia Lebedeva 2024-09-13 16:55:41 +02:00
parent d068da24b0
commit 7430890d03
2 changed files with 19 additions and 13 deletions

View File

@ -7,12 +7,13 @@ import DialpadPin from "./DialpadPin";
const { width, height } = Dimensions.get("window");
type DialpadProps = {
prompt: string;
onCancelFunc: () => void;
onNextFunc: (p?: any) => void;
onNextFunc: (p?: any) => boolean;
};
const Dialpad: FC<DialpadProps> = props => {
const {onNextFunc, onCancelFunc} = props;
const {prompt, onNextFunc, onCancelFunc} = props;
const dialPadContent = [1, 2, 3, 4, 5, 6, 7, 8, 9, "", 0, "X"];
const dialPadSize = width * 0.2;
const dialPadTextSize = dialPadSize * 0.36;
@ -21,8 +22,6 @@ const Dialpad: FC<DialpadProps> = props => {
const pinContainerSize = width / 2;
const pinSize = pinContainerSize / pinLength;
const updateCode = (item: never) => {
if (item === "X") {
setCode((prev) => prev.slice(0, -1));
@ -34,17 +33,23 @@ const Dialpad: FC<DialpadProps> = props => {
}
}
const onNext = () => {
if (!onNextFunc(code.join(''))) {
setCode([]);
}
}
return (
<SafeAreaView style={styles.container}>
<View style={styles.textContainer}>
<Text style={styles.pinText}>Create PIN</Text>
<Text style={styles.pinText}>{prompt}</Text>
<Text style={styles.pinSubText}>Enter your secure six-digit code</Text>
<DialpadPin pinLength={pinLength} pinSize={pinSize} code={code} dialPadContent={dialPadContent} />
<DialpadKeypad dialPadContent={dialPadContent} dialPadSize={dialPadSize} dialPadTextSize={dialPadTextSize} updateCodeFunc={updateCode} code={code}/>
</View>
<View style={styles.btnContainer}>
<Button label="Cancel" disabled={false} btnColor="#4A646C" btnWidth="50%" onChangeFunc={onCancelFunc} btnJustifyContent='center'></Button>
<Button label="Next" disabled={false} btnColor="#4A646C" btnWidth="50%" onChangeFunc={() => onNextFunc(code.join(''))} btnJustifyContent='center'></Button>
<Button label="Next" disabled={false} btnColor="#4A646C" btnWidth="50%" onChangeFunc={onNext} btnJustifyContent='center'></Button>
</View>
</SafeAreaView>
)};

View File

@ -20,8 +20,8 @@ const InitializationScreen: FC<InitializationScreenProps> = props => {
const insertPin = (p: string) => {
onChangePin(p);
console.log(p);
setStep(PinSteps.RepeatPin);
return true;
}
const isSamePin = (p: string) => {
@ -29,17 +29,18 @@ const InitializationScreen: FC<InitializationScreenProps> = props => {
}
const submitPin = (p: string) => {
if(isSamePin(p)) {
onPressFunc(pin);
} else {
console.log("err");
if(!isSamePin(p)) {
return false;
}
onPressFunc(pin);
return true;
}
return (
<View>
{ step == PinSteps.InsertPin && <Dialpad onCancelFunc={onCancelFunc} onNextFunc={insertPin}></Dialpad> }
{ step == PinSteps.RepeatPin && <Dialpad onCancelFunc={() => setStep(PinSteps.InsertPin)} onNextFunc={submitPin}></Dialpad> }
{ step == PinSteps.InsertPin && <Dialpad prompt={"Insert Pin"} onCancelFunc={onCancelFunc} onNextFunc={insertPin}></Dialpad> }
{ step == PinSteps.RepeatPin && <Dialpad prompt={"Repeat Pin"} onCancelFunc={() => setStep(PinSteps.InsertPin)} onNextFunc={submitPin}></Dialpad> }
</View>
)};