Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4ed5a8

Browse files
Linking (#71)
* linking config for NavigationContainer * add example linking config
1 parent db66ce4 commit d4ed5a8

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

‎src/Example.bs.js‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var React = require("react");
4+
var Js_dict = require("rescript/lib/js/js_dict.js");
45
var Caml_option = require("rescript/lib/js/caml_option.js");
56
var ReactNative = require("react-native");
67
var Stack$ReactNavigation = require("./Stack.bs.js");
@@ -71,8 +72,49 @@ var $$Navigator1ドル = include1ドル.$$Navigator;
7172

7273
var $$Screen1ドル = include1ドル.$$Screen;
7374

75+
var linking_prefixes = ["https://www.example.com"];
76+
77+
var linking_config = {
78+
initialRouteName: "app",
79+
screens: Js_dict.fromArray([[
80+
"app",
81+
{
82+
screens: Js_dict.fromArray([
83+
[
84+
"tab1",
85+
{
86+
screens: Js_dict.fromArray([[
87+
"home",
88+
{
89+
path: ""
90+
}
91+
]])
92+
}
93+
],
94+
[
95+
"tab2",
96+
{
97+
screens: Js_dict.fromArray([[
98+
"config",
99+
{
100+
path: "/config"
101+
}
102+
]])
103+
}
104+
]
105+
])
106+
}
107+
]])
108+
};
109+
110+
var linking = {
111+
prefixes: linking_prefixes,
112+
config: linking_config
113+
};
114+
74115
function Example$RootStackScreen(props) {
75116
return React.createElement(Native.NavigationContainer, {
117+
linking: linking,
76118
children: React.createElement($$Navigator1ドル.make, {
77119
screenOptions: (function (param) {
78120
return {
@@ -101,6 +143,7 @@ var RootStackScreen = {
101143
$$Navigator: $$Navigator1ドル,
102144
$$Screen: $$Screen1ドル,
103145
Group: RootStackScreen_Group,
146+
linking: linking,
104147
make: Example$RootStackScreen
105148
};
106149

‎src/Example.res‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,40 @@ module MainStackScreen = {
4242
module RootStackScreen = {
4343
include Stack.Make()
4444

45+
let linking = {
46+
open Native.Linking
47+
{
48+
prefixes: ["https://www.example.com"],
49+
config: {
50+
initialRouteName: "app",
51+
screens: [
52+
(
53+
"app",
54+
{
55+
screens: [
56+
(
57+
"tab1",
58+
{
59+
screens: [("home", {path: ""})]->Js.Dict.fromArray,
60+
},
61+
),
62+
(
63+
"tab2",
64+
{
65+
screens: [("config", {path: "/config"})]->Js.Dict.fromArray,
66+
},
67+
),
68+
]->Js.Dict.fromArray,
69+
},
70+
),
71+
]->Js.Dict.fromArray,
72+
},
73+
}
74+
}
75+
4576
@react.component
4677
let make = () =>
47-
<Native.NavigationContainer>
78+
<Native.NavigationContainerlinking>
4879
<Navigator screenOptions={_ => {presentation: #modal}}>
4980
<Screen name="Main" component=MainStackScreen.make />
5081
<Screen name="MyModal">

‎src/Native.bs.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33

4+
var Linking = {};
5+
46
var NavigationContainer = {};
57

68
var ServerContainer = {};
@@ -9,6 +11,7 @@ var CommonActions = {};
911

1012
var Link = {};
1113

14+
exports.Linking = Linking;
1215
exports.NavigationContainer = NavigationContainer;
1316
exports.ServerContainer = ServerContainer;
1417
exports.CommonActions = CommonActions;

‎src/Native.res‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ external darkTheme: theme = "DarkTheme"
1919
@module("@react-navigation/native")
2020
external useTheme: unit => theme = "useTheme"
2121

22+
module Linking = {
23+
type rec config = {
24+
path?: string,
25+
exact?: bool,
26+
initialRouteName?: string,
27+
screens?: screens,
28+
}
29+
and screens = dict<config>
30+
31+
type t = {
32+
enabled?: bool,
33+
prefixes: array<string>,
34+
config?: config,
35+
}
36+
}
37+
2238
module NavigationContainer = {
2339
type state = Js.Json.t
2440
type navigationState = state => unit
@@ -30,6 +46,7 @@ module NavigationContainer = {
3046
~onStateChange: navigationState=?,
3147
~onReady: unit => unit=?,
3248
~theme: theme=?,
49+
~linking: Linking.t=?,
3350
~children: React.element,
3451
~independent: bool=?,
3552
) => React.element = "NavigationContainer"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /