|
1 | | -// Low-level, zero-cost bindings to AppContainer. |
| 1 | +// There are two ways to use the AppContainer module. |
2 | 2 | // |
3 | | -// Usage: |
| 3 | +// 1. With React.createElement, zero-cost |
| 4 | +// ====================================== |
4 | 5 | // |
5 | | -// let appContainer = AppContainer.makeAppContainer(rootNavigator); |
| 6 | +// open ReactNavigation; |
6 | 7 | // |
7 | | -// React.createElement( |
8 | | -// appContainer, |
9 | | -// AppContainer.makeProps( |
10 | | -// ~screenProps, /* ... more props ... */ |
11 | | -// (), |
12 | | -// ), |
13 | | -// ); |
| 8 | +// let appContainer = AppContainer.makeAppContainer(MyStackNavigator.navigator); |
| 9 | +// |
| 10 | +// [@react.component] |
| 11 | +// let make = () => { |
| 12 | +// let screenProps = {"someProp": 42}; |
| 13 | +// |
| 14 | +// React.createElement( |
| 15 | +// appContainer, |
| 16 | +// AppContainer.makeProps(~screenProps, ()), |
| 17 | +// ); |
| 18 | +// }; |
14 | 19 |
|
15 | 20 | type persistNavigationState = NavigationState.t => Js.Promise.t(unit); |
16 | 21 | type loadNavigationState = unit => Js.Promise.t(option(NavigationState.t)); |
@@ -40,3 +45,46 @@ external makeProps: |
40 | 45 | external makeAppContainer: |
41 | 46 | Navigator.t => React.component(appContainerProps('screenProps)) = |
42 | 47 | "createAppContainer"; |
| 48 | + |
| 49 | +// 2. Without create element, using a functor instead |
| 50 | +// ================================================== |
| 51 | +// |
| 52 | +// open ReactNavigation; |
| 53 | +// |
| 54 | +// module MyAppContainer = |
| 55 | +// AppContainer.Make({ |
| 56 | +// type screenProps = {. "someProp": int}; |
| 57 | +// let navigator = MyStackNavigator.navigator; |
| 58 | +// }); |
| 59 | +// |
| 60 | +// [@react.component] |
| 61 | +// let make = () => { |
| 62 | +// let screenProps = {"someProp": 42}; |
| 63 | +// |
| 64 | +// <MyAppContainer screenProps />; |
| 65 | +// }; |
| 66 | + |
| 67 | +module Make = (S: { |
| 68 | + type screenProps; |
| 69 | + let navigator: Navigator.t; |
| 70 | + }) => { |
| 71 | + [@bs.module "react-navigation"] |
| 72 | + external make: |
| 73 | + Navigator.t => React.component(appContainerProps(S.screenProps)) = |
| 74 | + "createAppContainer"; |
| 75 | + |
| 76 | + [@bs.obj] |
| 77 | + external makeProps: |
| 78 | + ( |
| 79 | + ~persistNavigationState: persistNavigationState=?, |
| 80 | + ~loadNavigationState: loadNavigationState=?, |
| 81 | + ~screenProps: S.screenProps=?, |
| 82 | + ~setNavigatorRef: Js.Nullable.t(NavigationContainer.t) => unit=?, |
| 83 | + ~key: string=?, |
| 84 | + unit |
| 85 | + ) => |
| 86 | + appContainerProps(S.screenProps) = |
| 87 | + ""; |
| 88 | + |
| 89 | + let make = make(S.navigator); |
| 90 | +}; |
0 commit comments