From eb154dda415328841ee20b2d264222958157f645 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 8 Dec 2024 10:26:48 +0100 Subject: [PATCH 1/3] Various fixes and improvements --- package-lock.json | 16 +++++++++------- package.json | 2 +- src/BottomTabs.bs.js | 4 ++-- src/BottomTabs.res | 2 +- src/Core.bs.js | 4 ++-- src/Drawer.bs.js | 4 ++-- src/Drawer.res | 2 +- src/Elements.res | 7 ++++++- src/MaterialBottomTabs.bs.js | 4 ++-- src/MaterialBottomTabs.res | 3 +++ src/MaterialTopTabs.bs.js | 4 ++-- src/MaterialTopTabs.res | 3 +++ src/Native.res | 13 +++++++++++++ src/NativeStack.bs.js | 4 ++-- src/NativeStack.res | 9 +++++---- src/Stack.bs.js | 4 ++-- src/Stack.res | 2 +- 17 files changed, 57 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index f35e408..ac2f096 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rescript-react-navigation", - "version": "6.1.0", + "version": "6.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rescript-react-navigation", - "version": "6.1.0", + "version": "6.2.0", "license": "MIT", "devDependencies": { "@rescript/react": "^0.11.0", @@ -14,7 +14,7 @@ "lint-staged": "^10.0.0", "npmpub": "^5.0.0", "prettier": "^2.0.0", - "rescript": "^10.1.2", + "rescript": "^11.0.0", "rescript-react-native": ">=0.71.1" }, "peerDependencies": { @@ -10034,16 +10034,18 @@ "peer": true }, "node_modules/rescript": { - "version": "10.1.4", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.1.4.tgz", - "integrity": "sha512-FFKlS9AG/XrLepWsyw7B+A9DtQBPWEPDPDKghV831Y2KGbie+eeFBOS0xtRHp0xbt7S0N2Dm6hhX+kTZQ/3Ybg==", + "version": "11.1.4", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.1.4.tgz", + "integrity": "sha512-0bGU0bocihjSC6MsE3TMjHjY0EUpchyrREquLS8VsZ3ohSMD+VHUEwimEfB3kpBI1vYkw3UFZ3WD8R28guz/Vw==", "dev": true, "hasInstallScript": true, "bin": { "bsc": "bsc", - "bsrefmt": "bsrefmt", "bstracing": "lib/bstracing", "rescript": "rescript" + }, + "engines": { + "node": ">=10" } }, "node_modules/rescript-react-native": { diff --git a/package.json b/package.json index 2031700..c83d35b 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "lint-staged": "^10.0.0", "npmpub": "^5.0.0", "prettier": "^2.0.0", - "rescript": "^10.1.2", + "rescript": "^11.0.0", "rescript-react-native": ">=0.71.1" }, "prettier": { diff --git a/src/BottomTabs.bs.js b/src/BottomTabs.bs.js index 68ea997..8312c87 100644 --- a/src/BottomTabs.bs.js +++ b/src/BottomTabs.bs.js @@ -9,9 +9,9 @@ function Make($star) { return Interop.adaptNavigatorModule(BottomTabs.createBottomTabNavigator()); } -var Navigation = {}; +var $$Navigation = {}; exports.TabBarBadge = TabBarBadge; exports.Make = Make; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; /* ./Interop Not a pure module */ diff --git a/src/BottomTabs.res b/src/BottomTabs.res index 1a4620f..c1dca65 100644 --- a/src/BottomTabs.res +++ b/src/BottomTabs.res @@ -46,7 +46,7 @@ type rec options = { header?: headerParams => React.element, headerShown?: bool, // Header props from https://reactnavigation.org/docs/elements#header - headerTitle?: Header.headerTitleProps => React.element, + headerTitle?: Header.headerTitle, headerTitleAlign?: Header.headerTitleAlign, headerTitleAllowFontScaling?: bool, headerTitleStyle?: Style.t, diff --git a/src/Core.bs.js b/src/Core.bs.js index 3e7b04c..03138aa 100644 --- a/src/Core.bs.js +++ b/src/Core.bs.js @@ -5,9 +5,9 @@ var Params = {}; var NavigationEvent = {}; -var Navigation = {}; +var $$Navigation = {}; exports.Params = Params; exports.NavigationEvent = NavigationEvent; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; /* No side effect */ diff --git a/src/Drawer.bs.js b/src/Drawer.bs.js index b722100..c4bdceb 100644 --- a/src/Drawer.bs.js +++ b/src/Drawer.bs.js @@ -7,8 +7,8 @@ function Make($star) { return Interop.adaptNavigatorModule(Drawer.createDrawerNavigator()); } -var Navigation = {}; +var $$Navigation = {}; exports.Make = Make; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; /* ./Interop Not a pure module */ diff --git a/src/Drawer.res b/src/Drawer.res index 72559fa..9278671 100644 --- a/src/Drawer.res +++ b/src/Drawer.res @@ -57,7 +57,7 @@ type rec options = { headerShown?: bool, header?: headerProps => React.element, // Header props from https://reactnavigation.org/docs/elements#header - headerTitle?: Header.headerTitleProps => React.element, + headerTitle?: Header.headerTitle, headerTitleAlign?: Header.headerTitleAlign, headerTitleAllowFontScaling?: bool, headerTitleStyle?: Style.t, diff --git a/src/Elements.res b/src/Elements.res index eb04527..5029630 100644 --- a/src/Elements.res +++ b/src/Elements.res @@ -8,6 +8,11 @@ module Header = { children: string, } + @unboxed + type headerTitle = + | String(string) + | Function(headerTitleProps => React.element) + type headerLeftProps = { tintColor: option, pressColor: option, @@ -28,7 +33,7 @@ module Header = { @react.component @module("@react-navigation/elements") external make: ( ~title: string=?, - ~headerTitle: headerTitleProps => React.element=?, + ~headerTitle: headerTitle=?, ~headerTitleAlign: headerTitleAlign=?, ~headerTitleAllowFontScaling: bool=?, ~headerTitleStyle: Style.t=?, diff --git a/src/MaterialBottomTabs.bs.js b/src/MaterialBottomTabs.bs.js index de1986d..e2fa2ce 100644 --- a/src/MaterialBottomTabs.bs.js +++ b/src/MaterialBottomTabs.bs.js @@ -9,9 +9,9 @@ function Make($star) { return Interop.adaptNavigatorModule(MaterialBottomTabs.createMaterialBottomTabNavigator()); } -var Navigation = {}; +var $$Navigation = {}; exports.TabBarBadge = TabBarBadge; exports.Make = Make; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; /* ./Interop Not a pure module */ diff --git a/src/MaterialBottomTabs.res b/src/MaterialBottomTabs.res index 549dcc1..cda340d 100644 --- a/src/MaterialBottomTabs.res +++ b/src/MaterialBottomTabs.res @@ -80,6 +80,9 @@ type navigatorModule module Make = () => unpack(createMaterialBottomTabNavigator()->adaptNavigatorModule) module Navigation = { + @send + external setOptions: (navigation, options) => unit = "setOptions" + @send external jumpTo: (navigation, string) => unit = "jumpTo" @send external jumpToWithParams: (navigation, string, 'params) => unit = "jumpTo" diff --git a/src/MaterialTopTabs.bs.js b/src/MaterialTopTabs.bs.js index 4688bdc..37c6f6c 100644 --- a/src/MaterialTopTabs.bs.js +++ b/src/MaterialTopTabs.bs.js @@ -7,8 +7,8 @@ function Make($star) { return Interop.adaptNavigatorModule(MaterialTopTabs.createMaterialTopTabNavigator()); } -var Navigation = {}; +var $$Navigation = {}; exports.Make = Make; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; /* ./Interop Not a pure module */ diff --git a/src/MaterialTopTabs.res b/src/MaterialTopTabs.res index 984bfba..7b87485 100644 --- a/src/MaterialTopTabs.res +++ b/src/MaterialTopTabs.res @@ -129,6 +129,9 @@ type navigatorModule module Make = () => unpack(createMaterialTopTabNavigator()->adaptNavigatorModule) module Navigation = { + @send + external setOptions: (navigation, options) => unit = "setOptions" + @send external jumpTo: (navigation, string) => unit = "jumpTo" @send external jumpToWithParams: (navigation, string, 'params) => unit = "jumpTo" diff --git a/src/Native.res b/src/Native.res index 2f41d43..b78025c 100644 --- a/src/Native.res +++ b/src/Native.res @@ -6,10 +6,20 @@ type themeColors = { border: string, 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") external defaultTheme: theme = "DefaultTheme" @module("@react-navigation/native") @@ -122,3 +132,6 @@ module Link = { ~children: React.element, ) => React.element = "Link" } + +@module("@react-navigation/native") +external getFocusedRouteNameFromRoute: Core.route => option = "getFocusedRouteNameFromRoute" diff --git a/src/NativeStack.bs.js b/src/NativeStack.bs.js index 4162e4f..fdedffa 100644 --- a/src/NativeStack.bs.js +++ b/src/NativeStack.bs.js @@ -7,8 +7,8 @@ function Make($star) { return Interop.adaptNavigatorModule(NativeStack.createNativeStackNavigator()); } -var Navigation = {}; +var $$Navigation = {}; exports.Make = Make; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; /* ./Interop Not a pure module */ diff --git a/src/NativeStack.res b/src/NativeStack.res index c3c8ebe..6ab7a6c 100644 --- a/src/NativeStack.res +++ b/src/NativeStack.res @@ -1,6 +1,7 @@ // https://reactnavigation.org/docs/native-stack-navigator/ open Core +open Elements open ReactNative @module("react-native-screens") @@ -140,11 +141,11 @@ type rec options = { headerShadowVisible?: bool, headerTransparent?: bool, headerBlurEffect?: blurEffect, - headerBackground?: unit => React.element, + headerBackground?: Header.headerBackgroundOptions => React.element, headerTintColor?: Color.t, - headerLeft?: unit => React.element, - headerRight?: unit => React.element, - headerTitle?: string, + headerLeft?: Header.headerLeftProps => React.element, + headerRight?: Header.headerRightProps => React.element, + headerTitle?: Header.headerTitle, headerTitleAlign?: headerTitleAlign, headerTitleStyle?: headerTitleStyle, headerSearchBarOptions?: headerSearchBarOptions, diff --git a/src/Stack.bs.js b/src/Stack.bs.js index 00d0949..7a8b89c 100644 --- a/src/Stack.bs.js +++ b/src/Stack.bs.js @@ -9,7 +9,7 @@ function Make($star) { return Interop.adaptNavigatorModule(Stack.createStackNavigator()); } -var Navigation = {}; +var $$Navigation = {}; var TransitionSpecs = {}; @@ -21,7 +21,7 @@ var TransitionPresets = {}; exports.TransitionSpec = TransitionSpec; exports.Make = Make; -exports.Navigation = Navigation; +exports.$$Navigation = $$Navigation; exports.TransitionSpecs = TransitionSpecs; exports.CardStyleInterpolators = CardStyleInterpolators; exports.HeaderStyleInterpolators = HeaderStyleInterpolators; diff --git a/src/Stack.res b/src/Stack.res index feea297..81d2dae 100644 --- a/src/Stack.res +++ b/src/Stack.res @@ -129,7 +129,7 @@ type rec options = { headerTruncatedBackTitle?: string, headerBackTitleStyle?: Style.t, // Header props from https://reactnavigation.org/docs/elements#header - headerTitle?: Header.headerTitleProps => React.element, + headerTitle?: Header.headerTitle, headerTitleAlign?: Header.headerTitleAlign, headerTitleAllowFontScaling?: bool, headerTitleStyle?: Style.t, From 8469a94baf27ec909b7e8c4be546de7a7b6eb6ae Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 8 Dec 2024 10:36:47 +0100 Subject: [PATCH 2/3] Add DrawerItemList --- src/Drawer.bs.js | 3 +++ src/Drawer.res | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/Drawer.bs.js b/src/Drawer.bs.js index c4bdceb..3f9cac7 100644 --- a/src/Drawer.bs.js +++ b/src/Drawer.bs.js @@ -9,6 +9,9 @@ function Make($star) { var $$Navigation = {}; +var DrawerItemList = {}; + exports.Make = Make; exports.$$Navigation = $$Navigation; +exports.DrawerItemList = DrawerItemList; /* ./Interop Not a pure module */ diff --git a/src/Drawer.res b/src/Drawer.res index 9278671..20d0945 100644 --- a/src/Drawer.res +++ b/src/Drawer.res @@ -167,3 +167,8 @@ external useDrawerStatus: unit => drawerStatus = "useDrawerStatus" @module("@react-navigation/drawer") external getDrawerStatusFromState: navigationState => drawerStatus = "getDrawerStatusFromState" + +module DrawerItemList = { + @module("@react-navigation/drawer") + external make: React.component = "DrawerItemList" +} From b61ae6579ea6587c8c0b7591f6f5f271636e7289 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 11 Dec 2024 16:50:55 +0100 Subject: [PATCH 3/3] Remove themeFonts again as that's v7 API --- src/Native.res | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Native.res b/src/Native.res index b78025c..3363a0b 100644 --- a/src/Native.res +++ b/src/Native.res @@ -7,17 +7,9 @@ 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")