Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to react-navigation 7 #72

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ yarn add rescript-react-navigation
```

`rescript-react-navigation` should be added to `bs-dependencies` in your
`bsconfig.json`:
`rescript.json`:

```diff
{
Expand Down
7,726 changes: 2,768 additions & 4,958 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 14 additions & 12 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 All @@ -24,7 +26,7 @@
],
"files": [
"*.md",
"bsconfig.json",
"rescript.json",
"src/**/*.res",
"src/**/*.resi",
"src/**/*.js",
Expand All @@ -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.1.0",
"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
25 changes: 19 additions & 6 deletions src/BottomTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ open ReactNative

type tabBarLabelPosition = [#"below-icon" | #"beside-icon"]

type tabBarPosition = [#bottom | #top | #left | #right]

type tabBarVariant = [#uikit | #material]

type animation = [
| #fade
| #shift
| #none
]

type tabBarIconOptions = {
focused: bool,
color: string,
Expand All @@ -29,9 +39,8 @@ 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,
tabBarInactiveTintColor?: string,
tabBarActiveBackgroundColor?: string,
Expand All @@ -40,11 +49,15 @@ type rec options = {
tabBarItemStyle?: Style.t,
tabBarStyle?: Style.t,
tabBarBackground?: unit => React.element,
tabBarPosition?: tabBarPosition,
tabBarVariant?: tabBarVariant,
sceneStyle?: Style.t,
\"lazy"?: bool,
unmountOnBlur?: bool,
popToTopOnBlur?: bool,
freezeOnBlur?: bool,
header?: headerParams => React.element,
headerShown?: bool,
animation?: animation,
// Header props from https://reactnavigation.org/docs/elements#header
headerTitle?: Header.headerTitle,
headerTitleAlign?: Header.headerTitleAlign,
Expand Down Expand Up @@ -82,8 +95,8 @@ module type NavigatorModule = {
~screenOptions: screenOptionsParams => options=?,
~backBehavior: backBehavior=?,
~detachInactiveScreens: bool=?,
~sceneContainerStyle: Style.t=?,
~tabBar: unit => React.element=?,
~layout: layoutNavigatorParams => React.element=?,
~children: React.element,
) => React.element
}
Expand Down Expand Up @@ -124,8 +137,8 @@ type navigatorModule
module Make = () => unpack(createBottomTabNavigator()->adaptNavigatorModule)

module Navigation = {
@send external jumpTo: (navigation, string) => unit = "jumpTo"
@send
@send external jumpTo: (navigation, string, ~params: 'params=?) => unit = "jumpTo"
@deprecated("Use `jumpTo` with `~params` instead") @send
external jumpToWithParams: (navigation, string, 'params) => unit = "jumpTo"

@send
Expand Down
21 changes: 16 additions & 5 deletions src/Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,35 @@ type stateEventData = {state: navigationState}

type action

type layoutNavigatorParams = {
state: navigationState,
navigation: navigation,
descriptors: descriptors,
children: React.element,
}

module Navigation = {
type t = navigation

@send external navigate: (t, string) => unit = "navigate"
@send
@send external navigate: (t, string, ~params: 'params=?) => unit = "navigate"
@deprecated("Use `navigate` with `~params` instead") @send
external navigateWithParams: (t, string, 'params) => unit = "navigate"

@send external goBack: (navigation, unit) => unit = "goBack"
@send external navigateDeprecated: (t, string, ~params: 'params=?) => unit = "navigateDeprecated"

@send external goBack: navigation => unit = "goBack"

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

@send external isFocused: (navigation, unit) => bool = "isFocused"
@send external preload: (t, string, ~params: 'params=?) => unit = "preload"

@send external isFocused: navigation => bool = "isFocused"

@send
external dispatch: (t, action) => unit = "dispatch"

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

@send external setParams: (navigation, 'params) => unit = "setParams"

Expand Down
7 changes: 4 additions & 3 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 Expand Up @@ -104,6 +104,7 @@ module type NavigatorModule = {
~detachInactiveScreens: bool=?,
~useLegacyImplementation: bool=?,
~drawerContent: React.component<contentComponentProps>=?,
~layout: layoutNavigatorParams => React.element=?,
~children: React.element=?,
) => React.element
}
Expand Down Expand Up @@ -147,7 +148,7 @@ module Navigation = {
@send
external setOptions: (navigation, options) => unit = "setOptions"

@send external jumpTo: (navigation, ~name: string, ~params: 'params=?, unit) => unit = "jumpTo"
@send external jumpTo: (navigation, ~name: string, ~params: 'params=?) => unit = "jumpTo"
@send external openDrawer: navigation => unit = "openDrawer"
@send external closeDrawer: navigation => unit = "closeDrawer"
@send external toggleDrawer: navigation => unit = "toggleDrawer"
Expand Down
6 changes: 6 additions & 0 deletions src/Elements.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ var Header = {};

var HeaderBackground = {};

var HeaderTitle = {};

var HeaderButton = {};

var HeaderBackButton = {};

exports.Header = Header;
exports.HeaderBackground = HeaderBackground;
exports.HeaderTitle = HeaderTitle;
exports.HeaderButton = HeaderButton;
exports.HeaderBackButton = HeaderBackButton;
/* No side effect */
Loading
Loading