Skip to content

Commit f168502

Browse files
cknittMoOx
authored andcommitted
AppContainer: provide both a functor-based and a functor-less version of the binding. (#4)
1 parent 4268ebd commit f168502

File tree

4 files changed

+79
-34
lines changed

4 files changed

+79
-34
lines changed

src/AppContainer.bs.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
'use strict';
2-
3-
var ReactNavigation = require("react-navigation");
4-
5-
function Make(S) {
6-
var make = ReactNavigation.createAppContainer(S[/* navigator */0]);
7-
return /* module */[/* make */make];
8-
}
9-
10-
exports.Make = Make;
11-
/* react-navigation Not a pure module */
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

src/AppContainer.re

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Low-level, zero-cost bindings to AppContainer.
2+
//
3+
// Usage:
4+
//
5+
// let appContainer = AppContainer.makeAppContainer(rootNavigator);
6+
//
7+
// React.createElement(
8+
// appContainer,
9+
// AppContainer.makeProps(
10+
// ~screenProps, /* ... more props ... */
11+
// (),
12+
// ),
13+
// );
14+
115
type persistNavigationState = NavigationState.t => Js.Promise.t(unit);
216
type loadNavigationState = unit => Js.Promise.t(option(NavigationState.t));
317

@@ -9,27 +23,20 @@ type appContainerProps('screenProps) = {
923
"setNavigatorRef": Js.Nullable.t(NavigationContainer.t) => unit,
1024
};
1125

12-
module Make = (S: {
13-
type screenProps;
14-
let navigator: Navigator.t;
15-
}) => {
16-
[@bs.module "react-navigation"]
17-
external make:
18-
Navigator.t => React.component(appContainerProps(S.screenProps)) =
19-
"createAppContainer";
20-
21-
[@bs.obj]
22-
external makeProps:
23-
(
24-
~persistNavigationState: persistNavigationState=?,
25-
~loadNavigationState: loadNavigationState=?,
26-
~screenProps: S.screenProps=?,
27-
~setNavigatorRef: Js.Nullable.t(NavigationContainer.t) => unit=?,
28-
~key: string=?,
29-
unit
30-
) =>
31-
appContainerProps(S.screenProps) =
32-
"";
26+
[@bs.obj]
27+
external makeProps:
28+
(
29+
~persistNavigationState: persistNavigationState=?,
30+
~loadNavigationState: loadNavigationState=?,
31+
~screenProps: 'screenProps=?,
32+
~setNavigatorRef: Js.Nullable.t(NavigationContainer.t) => unit=?,
33+
~key: string=?,
34+
unit
35+
) =>
36+
appContainerProps('screenProps) =
37+
"";
3338

34-
let make = make(S.navigator);
35-
};
39+
[@bs.module "react-navigation"]
40+
external makeAppContainer:
41+
Navigator.t => React.component(appContainerProps('screenProps)) =
42+
"createAppContainer";

src/AppContainerFunctor.bs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
var ReactNavigation = require("react-navigation");
4+
5+
function Make(S) {
6+
var make = ReactNavigation.createAppContainer(S[/* navigator */0]);
7+
return /* module */[/* make */make];
8+
}
9+
10+
exports.Make = Make;
11+
/* react-navigation Not a pure module */

src/AppContainerFunctor.re

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// High-level, non-zero-cost bindings to AppContainer.
2+
//
3+
// Usage:
4+
//
5+
// module MyAppContainer =
6+
// AppContainer.Make({
7+
// type screenProps = /* my screen props type */;
8+
// let navigator = /* my root navigator component */;
9+
// });
10+
//
11+
// <MyAppContainer screenProps /* ... more props ... */ />
12+
13+
module Make = (S: {
14+
type screenProps;
15+
let navigator: Navigator.t;
16+
}) => {
17+
[@bs.module "react-navigation"]
18+
external make:
19+
Navigator.t =>
20+
React.component(AppContainer.appContainerProps(S.screenProps)) =
21+
"createAppContainer";
22+
23+
[@bs.obj]
24+
external makeProps:
25+
(
26+
~persistNavigationState: AppContainer.persistNavigationState=?,
27+
~loadNavigationState: AppContainer.loadNavigationState=?,
28+
~screenProps: S.screenProps=?,
29+
~setNavigatorRef: Js.Nullable.t(NavigationContainer.t) => unit=?,
30+
~key: string=?,
31+
unit
32+
) =>
33+
AppContainer.appContainerProps(S.screenProps) =
34+
"";
35+
36+
let make = make(S.navigator);
37+
};

0 commit comments

Comments
 (0)