import React, {FC, useState, ReactElement} from 'react'; import { View, Text, TouchableOpacity, ViewStyle, TextStyle, ScrollView, } from 'react-native'; export interface StepperProps { active: number; content: ReactElement[]; onNext: Function; onBack: Function; onFinish: Function; wrapperStyle?: ViewStyle; stepStyle?: ViewStyle; stepTextStyle?: TextStyle; buttonStyle?: ViewStyle; buttonTextStyle?: TextStyle; showButton?: boolean; } const search = (keyName: number, myArray: number[]): boolean => { let value = false; myArray.map((val) => { if (val === keyName) { value = true; } }); return value; }; const Stepper: FC = (props) => { const { active, content, onBack, onNext, onFinish, wrapperStyle, stepStyle, stepTextStyle, buttonStyle, buttonTextStyle, showButton = true, } = props; const [step, setStep] = useState([0]); const pushData = (val: number) => { setStep((prev) => [...prev, val]); }; const removeData = () => { setStep((prev) => { prev.pop(); return prev; }); }; return ( {content.map((_, i) => { return ( {i !== 0 && ( )} {search(i, step) ? ( ) : ( {i + 1} )} ); })} {content[active]} {showButton && ( {active !== 0 && ( { removeData(); onBack(); }}> Back )} {content.length - 1 !== active && ( { pushData(active + 1); onNext(); }}> Next )} {content.length - 1 === active && ( onFinish()}> Finish )} )} ); }; export default Stepper;