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

Commit 8b4b8f2

Browse files
committed
adding some tab navigator experiments + tab navigator nested support experiment
1 parent 82870c8 commit 8b4b8f2

File tree

6 files changed

+56
-91
lines changed

6 files changed

+56
-91
lines changed

example/src/DrawerExample.re

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ module Drawer =
99
let drawerOptions =
1010
DrawerNavigation.drawerOptions(~activeTintColor="#847", ());
1111

12-
let order = [Dashbord, Settings];
13-
14-
let getItem = tab =>
15-
switch (tab) {
12+
let getItem = drawerItem =>
13+
switch (drawerItem) {
1614
| Dashbord => (
1715
"Dashbord",
1816
(() => <Items.Dashboard />),

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 />, screenOptions())
38+
| TabExample => (<TabExample navigation/>, screenOptions())
3939
};
4040
});
4141

example/src/TabExample.re

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ module Tabs =
1313

1414
let order = [Info, Profile, Settings];
1515

16-
let getTab = tab => {
16+
let getTab = (tab, navigationProp) => {
1717
switch (tab) {
1818
| Info => (
1919
"Info",
20-
((navigation) => <Tabs.Info navigation/>),
20+
(() => <Tabs.Info navigation={navigationProp}/>),
2121
TabNavigator.screenOptions(~title="Info", ()),
2222
)
2323
| Profile => (
2424
"Profile",
25-
((navigation) => <Tabs.Profile navigation/>),
25+
(() => <Tabs.Profile navigation={navigationProp}/>),
2626
TabNavigator.screenOptions(~title="Profile", ()),
2727
)
2828
| Settings => (
2929
"Settings",
30-
((navigation) => <Tabs.Settings navigation/>),
30+
(() => <Tabs.Settings navigation={navigationProp}/>),
3131
TabNavigator.screenOptions(~title="Settings", ()),
3232
)
3333
};
3434
};
3535
});
3636

37-
let make = Tabs.make
37+
let render = Tabs.make;
38+
39+
let make = (~navigation, _children) => {
40+
...(ReasonReact.statelessComponent("TabExample")),
41+
render: _ => ReasonReact.createElement(render,[||])
42+
}

src/ReactNavigation.re

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
module Core = {
22
[@bs.module "@react-navigation/core"]
3-
external stackRouter: ('a, 'b) => ReasonReact.reactElement = "StackRouter";
3+
external stackRouter: ('a, 'b) => ReasonReact.reactClass = "StackRouter";
44

55
[@bs.module "@react-navigation/core"]
6-
external switchRouter: ('a, 'b) => ReasonReact.reactElement = "SwitchRouter";
6+
external switchRouter: ('a, 'b) => ReasonReact.reactClass = "SwitchRouter";
77

88
[@bs.module "@react-navigation/core"]
9-
external createNavigator: ('a, 'b, 'c) => ReasonReact.reactElement = "";
9+
external createNavigator: ('a, 'b, 'c) => ReasonReact.reactClass = "";
1010
};
1111

1212
module Native = {
1313
[@bs.module "@react-navigation/native"]
14-
external createAppContainer: 'a => ReasonReact.reactElement = "";
14+
external createAppContainer: 'a => ReasonReact.reactClass = "";
1515
};
1616

1717
module Stack = {
1818
[@bs.module "react-navigation-stack"]
19-
external stackView: ReasonReact.reactElement = "StackView";
19+
external stackView: ReasonReact.reactClass = "StackView";
2020
};
2121

2222
module Tab = {
@@ -29,11 +29,11 @@ module Tab = {
2929

3030
module Switch = {
3131
[@bs.module "@react-navigation/core"]
32-
external switchView: ReasonReact.reactElement = "SwitchView";
32+
external switchView: ReasonReact.reactClass = "SwitchView";
3333
};
3434

3535
module Drawer = {
3636
[@bs.module "react-navigation-drawer"]
37-
external create: ('a, 'b) => ReasonReact.reactElement =
37+
external create: ('a, 'b) => ReasonReact.reactClass =
3838
"createDrawerNavigator";
3939
};

src/TabNavigator.re

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module type TabConfig = {
5959
let containerName: string;
6060
let tabBarOptions: tabBarOptions;
6161
let getTab:
62-
tabs => (Js.Dict.key, navigation => ReasonReact.reactElement, screenOptions);
62+
(tabs,navigation) => (Js.Dict.key, unit => ReasonReact.reactElement, screenOptions);
6363
};
6464

6565
module Create = (Config: TabConfig) => {
@@ -70,14 +70,27 @@ module Create = (Config: TabConfig) => {
7070

7171
[@bs.deriving abstract]
7272
type routeConfig = {
73-
screen: navigation => ReasonReact.reactElement,
73+
screen: unit => ReasonReact.reactElement,
7474
navigationOptions: screenOptions,
7575
};
7676

77+
module NavigationProp = {
78+
79+
[@bs.send] external navigate: (string) => unit = "navigate";
80+
81+
82+
[@bs.send] external goBack: (unit) => unit = "goBack";
83+
};
84+
85+
let makeNavigationProp = () => {
86+
navigate: routeName => NavigationProp.navigate(routeName),
87+
goBack: () => NavigationProp.goBack(),
88+
};
89+
7790
let tabs =
7891
Config.order
7992
|> List.map(tab => {
80-
let (tabname, screen, screenOptionsConfig) = Config.getTab(tab);
93+
let (tabname, screen, screenOptionsConfig) = Config.getTab(tab, makeNavigationProp());
8194
(
8295
tabname,
8396
routeConfig(~screen, ~navigationOptions=screenOptionsConfig),
@@ -93,19 +106,7 @@ module Create = (Config: TabConfig) => {
93106

94107
let navigator = ReactNavigation.Tab.createBottomTabNavigator(tabs, tabBarOptions)
95108

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+
let make = ReactNavigation.Native.createAppContainer(navigator)
109110

110111
};
111112

0 commit comments

Comments
 (0)