Skip to content

Commit

Permalink
Linking (#71)
Browse files Browse the repository at this point in the history
* linking config for NavigationContainer

* add example linking config
  • Loading branch information
Freddy03h authored Dec 12, 2024
1 parent db66ce4 commit d4ed5a8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/Example.bs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var React = require("react");
var Js_dict = require("rescript/lib/js/js_dict.js");
var Caml_option = require("rescript/lib/js/caml_option.js");
var ReactNative = require("react-native");
var Stack$ReactNavigation = require("./Stack.bs.js");
Expand Down Expand Up @@ -71,8 +72,49 @@ var $$Navigator$1 = include$1.$$Navigator;

var $$Screen$1 = include$1.$$Screen;

var linking_prefixes = ["https://www.example.com"];

var linking_config = {
initialRouteName: "app",
screens: Js_dict.fromArray([[
"app",
{
screens: Js_dict.fromArray([
[
"tab1",
{
screens: Js_dict.fromArray([[
"home",
{
path: ""
}
]])
}
],
[
"tab2",
{
screens: Js_dict.fromArray([[
"config",
{
path: "/config"
}
]])
}
]
])
}
]])
};

var linking = {
prefixes: linking_prefixes,
config: linking_config
};

function Example$RootStackScreen(props) {
return React.createElement(Native.NavigationContainer, {
linking: linking,
children: React.createElement($$Navigator$1.make, {
screenOptions: (function (param) {
return {
Expand Down Expand Up @@ -101,6 +143,7 @@ var RootStackScreen = {
$$Navigator: $$Navigator$1,
$$Screen: $$Screen$1,
Group: RootStackScreen_Group,
linking: linking,
make: Example$RootStackScreen
};

Expand Down
33 changes: 32 additions & 1 deletion src/Example.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,40 @@ module MainStackScreen = {
module RootStackScreen = {
include Stack.Make()

let linking = {
open Native.Linking
{
prefixes: ["https://www.example.com"],
config: {
initialRouteName: "app",
screens: [
(
"app",
{
screens: [
(
"tab1",
{
screens: [("home", {path: ""})]->Js.Dict.fromArray,
},
),
(
"tab2",
{
screens: [("config", {path: "/config"})]->Js.Dict.fromArray,
},
),
]->Js.Dict.fromArray,
},
),
]->Js.Dict.fromArray,
},
}
}

@react.component
let make = () =>
<Native.NavigationContainer>
<Native.NavigationContainer linking>
<Navigator screenOptions={_ => {presentation: #modal}}>
<Screen name="Main" component=MainStackScreen.make />
<Screen name="MyModal">
Expand Down
3 changes: 3 additions & 0 deletions src/Native.bs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';


var Linking = {};

var NavigationContainer = {};

var ServerContainer = {};
Expand All @@ -9,6 +11,7 @@ var CommonActions = {};

var Link = {};

exports.Linking = Linking;
exports.NavigationContainer = NavigationContainer;
exports.ServerContainer = ServerContainer;
exports.CommonActions = CommonActions;
Expand Down
17 changes: 17 additions & 0 deletions src/Native.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ external darkTheme: theme = "DarkTheme"
@module("@react-navigation/native")
external useTheme: unit => theme = "useTheme"

module Linking = {
type rec config = {
path?: string,
exact?: bool,
initialRouteName?: string,
screens?: screens,
}
and screens = dict<config>

type t = {
enabled?: bool,
prefixes: array<string>,
config?: config,
}
}

module NavigationContainer = {
type state = Js.Json.t
type navigationState = state => unit
Expand All @@ -30,6 +46,7 @@ module NavigationContainer = {
~onStateChange: navigationState=?,
~onReady: unit => unit=?,
~theme: theme=?,
~linking: Linking.t=?,
~children: React.element,
~independent: bool=?,
) => React.element = "NavigationContainer"
Expand Down

0 comments on commit d4ed5a8

Please sign in to comment.