-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow.tsx
43 lines (36 loc) · 1.23 KB
/
flow.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { createFlowNavigator } from "@bam.tech/flow-navigator";
import { Step1Page } from "./Step1Page";
import { Step2Page } from "./Step2Page";
import { createContext, ReactNode, useContext, useState } from "react";
const FlowNavigator = createFlowNavigator();
interface AppContextValue {
step2Enabled: boolean;
setStep2Enabled: React.Dispatch<React.SetStateAction<boolean>>;
}
const AppContext = createContext<AppContextValue | null>(null);
export const AppProvider = ({ children }: { children: ReactNode }) => {
const [step2Enabled, setStep2Enabled] = useState(false);
return (
<AppContext.Provider value={{ step2Enabled, setStep2Enabled }}>
{children}
</AppContext.Provider>
);
};
export const useAppContext = (): AppContextValue => {
const context = useContext(AppContext);
if (!context) {
throw new Error("useAppContext must be used within a AppProvider");
}
return context;
};
export const FlowNavigatorExample = () => {
const { step2Enabled } = useAppContext();
return (
<FlowNavigator.Navigator>
<FlowNavigator.Screen name="Step1" component={Step1Page} />
{step2Enabled && (
<FlowNavigator.Screen name="Step2" component={Step2Page} />
)}
</FlowNavigator.Navigator>
);
};