Skip to content

Commit

Permalink
upgrade to react-navigation 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Freddy03h committed Dec 26, 2024
1 parent fd1d0e7 commit 7dfb18f
Show file tree
Hide file tree
Showing 15 changed files with 2,886 additions and 5,022 deletions.
7,726 changes: 2,768 additions & 4,958 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"access": "public"
},
"peerDependencies": {
"@react-navigation/bottom-tabs": ">=6.1.0",
"@react-navigation/drawer": ">=6.1.0",
"@react-navigation/material-bottom-tabs": ">=6.1.0",
"@react-navigation/material-top-tabs": ">=6.1.0",
"@react-navigation/native": ">=6.1.0",
"@react-navigation/stack": ">=6.1.0",
"@rescript/react": ">=0.11.0",
"rescript-react-native": ">=0.71.0"
"@react-navigation/bottom-tabs": ">=7.0.0",
"@react-navigation/drawer": ">=7.0.0",
"@react-navigation/material-top-tabs": ">=7.0.0",
"@react-navigation/native": ">=7.0.0",
"@react-navigation/stack": ">=7.0.0",
"@rescript/react": ">=0.12.0",
"rescript-react-native": ">=0.73.1"
},
"overrides": {
"react": "^18.0.0"
},
"repository": "https://github.com/rescript-react-native/react-navigation.git",
"license": "MIT",
Expand Down Expand Up @@ -43,13 +45,13 @@
"release": "npmpub"
},
"devDependencies": {
"@rescript/react": "^0.11.0",
"@rescript/react": "^0.12.2",
"husky": "^4.0.0",
"lint-staged": "^10.0.0",
"npmpub": "^5.0.0",
"prettier": "^2.0.0",
"rescript": "^11.0.0",
"rescript-react-native": ">=0.71.1"
"rescript": "^11.0.1",
"rescript-react-native": "^0.73.1"
},
"prettier": {
"trailingComma": "all"
Expand Down
3 changes: 1 addition & 2 deletions bsconfig.json → rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "rescript-react-navigation",
"namespace": "react-navigation",
"jsx": {
"version": 4,
"mode": "classic"
"version": 4
},
"package-specs": {
"module": "commonjs",
Expand Down
6 changes: 3 additions & 3 deletions src/BottomTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type rec options = {
tabBarBadge?: string,
tabBarBadgeStyle?: Style.t,
tabBarAccessibilityLabel?: string,
tabBarTestID?: string,
tabBarButtonTestID?: string,
tabBarButton?: unit => React.element, // TODO: props
tabBarColor?: Color.t,
tabBarActiveTintColor?: string,
Expand All @@ -40,8 +40,9 @@ type rec options = {
tabBarItemStyle?: Style.t,
tabBarStyle?: Style.t,
tabBarBackground?: unit => React.element,
sceneStyle?: Style.t,
\"lazy"?: bool,
unmountOnBlur?: bool,
popToTopOnBlur?: bool,
freezeOnBlur?: bool,
header?: headerParams => React.element,
headerShown?: bool,
Expand Down Expand Up @@ -82,7 +83,6 @@ module type NavigatorModule = {
~screenOptions: screenOptionsParams => options=?,
~backBehavior: backBehavior=?,
~detachInactiveScreens: bool=?,
~sceneContainerStyle: Style.t=?,
~tabBar: unit => React.element=?,
~children: React.element,
) => React.element
Expand Down
4 changes: 4 additions & 0 deletions src/Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ module Navigation = {
@send
external navigateWithParams: (t, string, 'params) => unit = "navigate"

@send external navigateDeprecated: (t, string) => unit = "navigateDeprecated"
@send
external navigateDeprecatedWithParams: (t, string, 'params) => unit = "navigateDeprecated"

@send external goBack: (navigation, unit) => unit = "goBack"

@send
Expand Down
4 changes: 2 additions & 2 deletions src/Drawer.res
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ type rec options = {
drawerHideStatusBarOnOpen?: bool,
drawerStatusBarAnimation?: drawerStatusBarAnimation,
overlayColor?: Color.t,
sceneContainerStyle?: Style.t,
sceneStyle?: Style.t,
gestureEnabled?: bool,
gestureHandlerProps?: gestureHandlerProps,
swipeEnabled?: bool,
swipeEdgeWidth?: float,
swipeMinDistance?: float,
keyboardDismissMode?: keyboardDismissMode,
unmountOnBlur?: bool,
popToTopOnBlur?: bool,
freezeOnBlur?: bool,
headerShown?: bool,
header?: headerProps => React.element,
Expand Down
6 changes: 4 additions & 2 deletions src/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ module Header = {
| String(string)
| Function(headerTitleProps => React.element)

type displayMode = [#default | #generic | #minimal]

type headerLeftProps = {
tintColor: option<Color.t>,
pressColor: option<Color.t>,
pressOpacity: option<float>,
labelVisible: option<bool>,
displayMode: option<displayMode>,
}

type headerRightProps = {
Expand Down Expand Up @@ -66,7 +68,7 @@ module HeaderBackground = {
module HeaderBackButton = {
@react.component @module("@react-navigation/elements")
external make: (
~labelVisible: bool=?,
~displayMode: Header.displayMode=?,
~tintColor: Color.t=?,
~onPress: unit => unit,
) => React.element = "HeaderBackButton"
Expand Down
43 changes: 23 additions & 20 deletions src/Example.bs.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'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 JsxRuntime = require("react/jsx-runtime");
var Stack$ReactNavigation = require("./Stack.bs.js");
var Native = require("@react-navigation/native");

function Example$HomeScreen(props) {
return React.createElement(ReactNative.Text, {
return JsxRuntime.jsx(ReactNative.Text, {
children: "Hello Reasonable Person!"
});
}
Expand All @@ -18,7 +18,7 @@ var HomeScreen = {
};

function Example$ModalScreen(props) {
return React.createElement(ReactNative.Text, {
return JsxRuntime.jsx(ReactNative.Text, {
children: "Hello From Modal"
});
}
Expand All @@ -34,15 +34,15 @@ var $$Navigator = include.$$Navigator;
var $$Screen = include.$$Screen;

function Example$MainStackScreen(props) {
return React.createElement($$Navigator.make, {
children: Caml_option.some(React.createElement($$Screen.make, {
return JsxRuntime.jsx($$Navigator.make, {
children: Caml_option.some(JsxRuntime.jsx($$Screen.make, {
name: "Home",
options: (function (props) {
var params = props.route.params;
return {
title: params !== undefined ? Caml_option.valFromOption(params).name : "Reason",
headerRight: (function (param) {
return React.createElement(ReactNative.Button, {
return JsxRuntime.jsx(ReactNative.Button, {
color: "#f00",
onPress: (function (param) {
props.navigation.navigate("MyModal");
Expand Down Expand Up @@ -113,27 +113,30 @@ var linking = {
};

function Example$RootStackScreen(props) {
return React.createElement(Native.NavigationContainer, {
return JsxRuntime.jsx(Native.NavigationContainer, {
linking: linking,
children: React.createElement($$Navigator$1.make, {
children: JsxRuntime.jsxs($$Navigator$1.make, {
screenOptions: (function (param) {
return {
presentation: "modal"
};
}),
children: Caml_option.some(null)
}, React.createElement($$Screen$1.make, {
name: "Main",
component: Example$MainStackScreen
}), React.createElement($$Screen$1.make, {
name: "MyModal",
children: (function (param) {
return React.createElement(Example$ModalScreen, {
navigation: param.navigation,
route: param.route
});
children: [
JsxRuntime.jsx($$Screen$1.make, {
name: "Main",
component: Example$MainStackScreen
}),
JsxRuntime.jsx($$Screen$1.make, {
name: "MyModal",
children: (function (param) {
return JsxRuntime.jsx(Example$ModalScreen, {
navigation: param.navigation,
route: param.route
});
})
})
}))
]
})
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/MaterialBottomTabs.bs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

var Interop = require("./Interop");
var MaterialBottomTabs = require("@react-navigation/material-bottom-tabs");
var ReactNavigation = require("react-native-paper/react-navigation");

var TabBarBadge = {};

function Make($star) {
return Interop.adaptNavigatorModule(MaterialBottomTabs.createMaterialBottomTabNavigator());
return Interop.adaptNavigatorModule(ReactNavigation.createMaterialBottomTabNavigator());
}

var $$Navigation = {};
Expand Down
2 changes: 1 addition & 1 deletion src/MaterialBottomTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module type NavigatorModule = {
type navigatorModule

%%private(
@module("@react-navigation/material-bottom-tabs")
@module("react-native-paper/react-navigation")
external createMaterialBottomTabNavigator: unit => navigatorModule =
"createMaterialBottomTabNavigator"

Expand Down
4 changes: 2 additions & 2 deletions src/MaterialTopTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type options = {
tabBarIndicator?: unit => React.element,
tabBarIndicatorStyle?: Style.t,
tabBarIndicatorContainerStyle?: Style.t,
tabBarTestID?: string,
tabBarButtonTestID?: string,
tabBarActiveTintColor?: string,
tabBarInactiveTintColor?: string,
tabBarPressColor?: string,
Expand Down Expand Up @@ -57,6 +57,7 @@ type tabBarProps = {
tabStyle?: Style.t,
indicatorStyle?: Style.t,
labelStyle?: Style.t,
sceneStyle?: Style.t,
style?: Style.t,
renderIndicator?: React.component<{"route": route}>,
activeTintColor?: string,
Expand Down Expand Up @@ -86,7 +87,6 @@ module type NavigatorModule = {
~tabBarPosition: tabBarPosition=?,
~keyboardDismissMode: keyboardDismissMode=?,
~initialLayout: layout=?,
~sceneContainerStyle: Style.t=?,
~style: Style.t=?,
~tabBar: tabBarProps => React.element=?,
~children: React.element,
Expand Down
3 changes: 3 additions & 0 deletions src/Native.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

var Linking = {};

var NavigationIndependentTree = {};

var NavigationContainer = {};

var ServerContainer = {};
Expand All @@ -12,6 +14,7 @@ var CommonActions = {};
var Link = {};

exports.Linking = Linking;
exports.NavigationIndependentTree = NavigationIndependentTree;
exports.NavigationContainer = NavigationContainer;
exports.ServerContainer = ServerContainer;
exports.CommonActions = CommonActions;
Expand Down
45 changes: 32 additions & 13 deletions src/Native.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ type themeColors = {
notification: string,
}

type themeFonts = {
regular: ReactNative.Style.t,
medium: ReactNative.Style.t,
bold: ReactNative.Style.t,
heavy: ReactNative.Style.t,
}

type theme = {
dark: bool,
colors: themeColors,
fonts: themeFonts,
}

@module("@react-navigation/native")
Expand All @@ -35,6 +43,11 @@ module Linking = {
}
}

module NavigationIndependentTree = {
@module("@react-navigation/native") @react.component
external make: unit => React.element = "NavigationIndependentTree"
}

module NavigationContainer = {
type state = Js.Json.t
type navigationState = state => unit
Expand All @@ -48,7 +61,7 @@ module NavigationContainer = {
~theme: theme=?,
~linking: Linking.t=?,
~children: React.element,
~independent: bool=?,
~navigationInChildEnabled: bool=?,
) => React.element = "NavigationContainer"

@send
Expand Down Expand Up @@ -115,9 +128,11 @@ module CommonActions = {
@module("@react-navigation/native")
external useLinkTo: string => unit = "useLinkTo"

type linkPropsIn = {
to_: string,
action: unit => unit,
type linkPropsIn<'params> = {
screen?: string,
params?: 'params,
action?: Core.action,
href?: string,
}
type linkPropsOut = {
href: string,
Expand All @@ -126,20 +141,24 @@ type linkPropsOut = {
}

@module("@react-navigation/native")
external useLinkProps: linkPropsIn => linkPropsOut = "useLinkProps"
external useLinkProps: linkPropsIn<'params> => linkPropsOut = "useLinkProps"

type linkBuilderOut<'a> = (string, 'a) => string
type linkBuilderOut<'params> = {
buildHref: (string, 'params) => string,
buildAction: string => Core.action,
}

@module("@react-navigation/native")
external useLinkBuilder: unit => linkBuilderOut<'a> = "useLinkBuilder"
external useLinkBuilder: unit => linkBuilderOut<'params> = "useLinkBuilder"

module Link = {
@module("@react-navigation/native") @react.component
external make: (
~to_: string=?,
~action: unit => unit=?,
~children: React.element,
) => React.element = "Link"
type props<'params> = {
...linkPropsIn<'params>,
children: React.element,
}

@module("@react-navigation/native")
external make: props<'params> => React.element = "Link"
}

@module("@react-navigation/native")
Expand Down
Loading

0 comments on commit 7dfb18f

Please sign in to comment.