diff --git a/package.json b/package.json index 88fde988..cabb118a 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "@expo/config-plugins": "^7.0.0 || ^8.0.0", "@react-native/babel-preset": "0.75.3", "@react-native/eslint-config": "^0.73.1", - "@react-navigation/native": "^6.1.18", + "@react-navigation/native": "next", "@types/color": "^3.0.6", "@types/jest": "^29.5.5", "@types/react": "^18.2.44", diff --git a/package.tgz b/package.tgz new file mode 100644 index 00000000..fa3c1aab Binary files /dev/null and b/package.tgz differ diff --git a/src/react-navigation/navigators/createNativeBottomTabNavigator.tsx b/src/react-navigation/navigators/createNativeBottomTabNavigator.tsx index e2bc7252..176d71cb 100644 --- a/src/react-navigation/navigators/createNativeBottomTabNavigator.tsx +++ b/src/react-navigation/navigators/createNativeBottomTabNavigator.tsx @@ -1,13 +1,14 @@ -import type { - DefaultNavigatorOptions, - ParamListBase, - TabActionHelpers, - TabNavigationState, - TabRouterOptions, -} from '@react-navigation/native'; import { - TabRouter, createNavigatorFactory, + type DefaultNavigatorOptions, + type NavigatorTypeBagBase, + type ParamListBase, + type StaticConfig, + type TabActionHelpers, + type TabNavigationState, + TabRouter, + type TabRouterOptions, + type TypedNavigator, useNavigationBuilder, useTheme, } from '@react-navigation/native'; @@ -17,14 +18,17 @@ import type { NativeBottomTabNavigationConfig, NativeBottomTabNavigationEventMap, NativeBottomTabNavigationOptions, + NativeBottomTabNavigationProp, } from '../types'; import NativeBottomTabView from '../views/NativeBottomTabView'; -export type NativeBottomTabNavigatorProps = DefaultNavigatorOptions< +type Props = DefaultNavigatorOptions< ParamListBase, + string | undefined, TabNavigationState, NativeBottomTabNavigationOptions, - NativeBottomTabNavigationEventMap + NativeBottomTabNavigationEventMap, + NativeBottomTabNavigationProp > & TabRouterOptions & NativeBottomTabNavigationConfig; @@ -34,22 +38,19 @@ function NativeBottomTabNavigator({ initialRouteName, backBehavior, children, + layout, screenListeners, screenOptions, tabBarActiveTintColor: customActiveTintColor, tabBarInactiveTintColor: customInactiveTintColor, + UNSTABLE_getStateForRouteNamesChange, ...rest -}: NativeBottomTabNavigatorProps) { +}: Props) { const { colors } = useTheme(); - const activeTintColor = - customActiveTintColor === undefined - ? colors.primary - : customActiveTintColor; - + const activeTintColor = customActiveTintColor ?? colors.primary; const inactiveTintColor = - customInactiveTintColor === undefined - ? Color(colors.text).mix(Color(colors.card), 0.5).hex() - : customInactiveTintColor; + customInactiveTintColor ?? + Color(colors.text).mix(Color(colors.card), 0.5).hex(); const { state, descriptors, navigation, NavigationContent } = useNavigationBuilder< @@ -63,8 +64,10 @@ function NativeBottomTabNavigator({ initialRouteName, backBehavior, children, + layout, screenListeners, screenOptions, + UNSTABLE_getStateForRouteNamesChange, }); return ( @@ -81,9 +84,25 @@ function NativeBottomTabNavigator({ ); } -export default createNavigatorFactory< - TabNavigationState, - NativeBottomTabNavigationOptions, - NativeBottomTabNavigationEventMap, - typeof NativeBottomTabNavigator ->(NativeBottomTabNavigator); +export default function createNativeBottomTabNavigator< + const ParamList extends ParamListBase, + const NavigatorID extends string | undefined = undefined, + const TypeBag extends NavigatorTypeBagBase = { + ParamList: ParamList; + NavigatorID: NavigatorID; + State: TabNavigationState; + ScreenOptions: NativeBottomTabNavigationOptions; + EventMap: NativeBottomTabNavigationEventMap; + NavigationList: { + [RouteName in keyof ParamList]: NativeBottomTabNavigationProp< + ParamList, + RouteName, + NavigatorID + >; + }; + Navigator: typeof NativeBottomTabNavigator; + }, + const Config extends StaticConfig = StaticConfig, +>(config?: Config): TypedNavigator { + return createNavigatorFactory(NativeBottomTabNavigator)(config); +} diff --git a/src/react-navigation/views/NativeBottomTabView.tsx b/src/react-navigation/views/NativeBottomTabView.tsx index 43f74edc..fa95c1fd 100644 --- a/src/react-navigation/views/NativeBottomTabView.tsx +++ b/src/react-navigation/views/NativeBottomTabView.tsx @@ -1,7 +1,8 @@ -import type { - ParamListBase, - TabNavigationState, - Route, +import { + type ParamListBase, + type TabNavigationState, + type Route, + CommonActions, } from '@react-navigation/native'; import type { NativeBottomTabDescriptorMap, @@ -72,7 +73,11 @@ export default function NativeBottomTabView({ type: 'tabPress', target: route.key, }); - navigation.navigate({ key: route.key, name: route.name, merge: true }); + + navigation.dispatch({ + ...CommonActions.navigate(route), + target: state.key, + }); }} /> ); diff --git a/yarn.lock b/yarn.lock index c8e0aeeb..5eacfeed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3657,6 +3657,23 @@ __metadata: languageName: node linkType: hard +"@react-navigation/core@npm:^7.0.0-rc.15": + version: 7.0.0-rc.15 + resolution: "@react-navigation/core@npm:7.0.0-rc.15" + dependencies: + "@react-navigation/routers": ^7.0.0-rc.8 + escape-string-regexp: ^4.0.0 + nanoid: 3.3.7 + query-string: ^7.1.3 + react-is: ^18.2.0 + use-latest-callback: ^0.2.1 + use-sync-external-store: ^1.2.2 + peerDependencies: + react: "*" + checksum: 611b7a3677ef42782027713d8b6327b9be5cd1554bcda7b6df5c402abebf2281704e59f25907723e578a8ddd5d1e8686d47a1b31a57f363e59ed3670efbd8054 + languageName: node + linkType: hard + "@react-navigation/elements@npm:^1.3.31": version: 1.3.31 resolution: "@react-navigation/elements@npm:1.3.31" @@ -3700,6 +3717,22 @@ __metadata: languageName: node linkType: hard +"@react-navigation/native@npm:next": + version: 7.0.0-rc.21 + resolution: "@react-navigation/native@npm:7.0.0-rc.21" + dependencies: + "@react-navigation/core": ^7.0.0-rc.15 + escape-string-regexp: ^4.0.0 + fast-deep-equal: ^3.1.3 + nanoid: 3.3.7 + use-latest-callback: ^0.2.1 + peerDependencies: + react: ">= 18.2.0" + react-native: "*" + checksum: 82967af07faaf7e8f3290b13cacec1bcabdcf89c84ae5de83d8770692ccdcc10d8f2efda78bd2508fdb2d7a689a2aec6a1578c653e8c28fef256cbc7d862fdf6 + languageName: node + linkType: hard + "@react-navigation/routers@npm:^6.1.9": version: 6.1.9 resolution: "@react-navigation/routers@npm:6.1.9" @@ -3709,6 +3742,15 @@ __metadata: languageName: node linkType: hard +"@react-navigation/routers@npm:^7.0.0-rc.8": + version: 7.0.0-rc.8 + resolution: "@react-navigation/routers@npm:7.0.0-rc.8" + dependencies: + nanoid: 3.3.7 + checksum: cb5e7c0b367b38018588cf8c297271691b6a73e7b8e0f7866b9ec322a52db37b09eb971bd6dfe4069b7eebbfe1ff43a4798dbfc2168deaeef8ac5894828b7d2b + languageName: node + linkType: hard + "@react-navigation/stack@npm:^6.4.1": version: 6.4.1 resolution: "@react-navigation/stack@npm:6.4.1" @@ -12466,7 +12508,7 @@ __metadata: languageName: node linkType: hard -"nanoid@npm:^3.1.23, nanoid@npm:^3.3.7": +"nanoid@npm:3.3.7, nanoid@npm:^3.1.23, nanoid@npm:^3.3.7": version: 3.3.7 resolution: "nanoid@npm:3.3.7" bin: @@ -13708,7 +13750,7 @@ __metadata: languageName: node linkType: hard -"react-is@npm:^18.0.0": +"react-is@npm:^18.0.0, react-is@npm:^18.2.0": version: 18.3.1 resolution: "react-is@npm:18.3.1" checksum: e20fe84c86ff172fc8d898251b7cc2c43645d108bf96d0b8edf39b98f9a2cae97b40520ee7ed8ee0085ccc94736c4886294456033304151c3f94978cec03df21 @@ -13771,7 +13813,7 @@ __metadata: "@expo/config-plugins": ^7.0.0 || ^8.0.0 "@react-native/babel-preset": 0.75.3 "@react-native/eslint-config": ^0.73.1 - "@react-navigation/native": ^6.1.18 + "@react-navigation/native": next "@types/color": ^3.0.6 "@types/jest": ^29.5.5 "@types/react": ^18.2.44 @@ -16666,6 +16708,15 @@ __metadata: languageName: node linkType: hard +"use-sync-external-store@npm:^1.2.2": + version: 1.2.2 + resolution: "use-sync-external-store@npm:1.2.2" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + checksum: fe07c071c4da3645f112c38c0e57beb479a8838616ff4e92598256ecce527f2888c08febc7f9b2f0ce2f0e18540ba3cde41eb2035e4fafcb4f52955037098a81 + languageName: node + linkType: hard + "util-deprecate@npm:^1.0.1, util-deprecate@npm:~1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2"