Skip to content
This repository was archived by the owner on May 8, 2019. It is now read-only.

Commit 82870c8

Browse files
committed
add Container support
1 parent 952e2d4 commit 82870c8

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

example/src/App.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let stack = StackExample.render;
2-
let tab = TabExample.render;
2+
/* let tab = TabExample.render; */
33
let drawer = DrawerExample.render;
44

55
let switchNavigator = SwitchExample.render;
66

7-
let app = drawer;
7+
let app = stack;

example/src/StackExample.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module Stack =
3535
<Screen navigation text={"Browsing profile of: " ++ userId} />,
3636
screenOptions(~title="Hello " ++ userId, ()),
3737
)
38-
| TabExample => (<TabExample navigation />, screenOptions())
38+
| TabExample => (<TabExample />, screenOptions())
3939
};
4040
});
4141

example/src/TabExample.re

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module Tabs =
66
type tabs = Config.tabs;
77
type order = list(tabs);
88

9+
let containerName="TabExample";
10+
911
let tabBarOptions =
1012
TabNavigator.tabBarOptions(~activeTintColor="#847", ());
1113

@@ -32,9 +34,4 @@ module Tabs =
3234
};
3335
});
3436

35-
let render = Tabs.render;
36-
37-
let make = (~navigation, _children) => {
38-
...(ReasonReact.statelessComponent("TabExample")),
39-
render: _ => Tabs.render
40-
}
37+
let make = Tabs.make

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
"react-navigation": "^3.0.5",
3535
"react-navigation-drawer": "^1.0.5",
3636
"react-navigation-stack": "^1.0.5",
37-
"@react-navigation/core": "^3.0.1",
38-
"@react-navigation/native": "^3.0.3",
3937
"react-navigation-tabs": "1.0.1",
4038
"reason-react": "^0.5.3"
4139
},

src/ReactNavigation.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ module Stack = {
2121

2222
module Tab = {
2323
[@bs.module "react-navigation-tabs"]
24-
external createBottomTabNavigator: ('a, 'b) => ReasonReact.reactElement = "";
24+
external createBottomTabNavigator: ('a, 'b) => ReasonReact.reactClass = "";
2525

2626
[@bs.module "react-navigation-tabs"]
27-
external createMaterialTopTabNavigator: 'a => ReasonReact.reactElement = ""
27+
external createMaterialTopTabNavigator: 'a => ReasonReact.reactClass = ""
2828
};
2929

3030
module Switch = {

src/TabNavigator.re

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ module type TabConfig = {
5656
type tabs;
5757
type order = list(tabs);
5858
let order: order;
59+
let containerName: string;
5960
let tabBarOptions: tabBarOptions;
6061
let getTab:
6162
tabs => (Js.Dict.key, navigation => ReasonReact.reactElement, screenOptions);
6263
};
6364

6465
module Create = (Config: TabConfig) => {
66+
6567
[@bs.deriving abstract]
6668
type navigatorConfig = {initialRouteName: string};
6769

@@ -89,10 +91,21 @@ module Create = (Config: TabConfig) => {
8991
"tabBarOptions": Config.tabBarOptions,
9092
};
9193

92-
/* navigator */
93-
let navigator =
94-
ReactNavigation.Tab.createBottomTabNavigator(tabs, tabBarOptions);
94+
let navigator = ReactNavigation.Tab.createBottomTabNavigator(tabs, tabBarOptions)
95+
96+
let navigatorElement = ReasonReact.createElement(navigator, [||])
97+
98+
module Container = {
99+
let component = ReasonReact.statelessComponent(Config.containerName);
100+
101+
let make = (_children) => {
102+
...component,
103+
render: _self => navigatorElement
104+
};
105+
};
106+
107+
108+
let make = Container.make
109+
110+
};
95111

96-
/* Wrap StackNavigator with the AppContainer - temporary */
97-
let render = ReactNavigation.Native.createAppContainer(navigator);
98-
};

0 commit comments

Comments
 (0)