@idealyst/navigation 1.0.80 → 1.0.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/navigation",
3
- "version": "1.0.80",
3
+ "version": "1.0.82",
4
4
  "description": "Cross-platform navigation library for React and React Native",
5
5
  "readme": "README.md",
6
6
  "main": "src/index.ts",
@@ -38,8 +38,8 @@
38
38
  "publish:npm": "npm publish"
39
39
  },
40
40
  "peerDependencies": {
41
- "@idealyst/components": "^1.0.80",
42
- "@idealyst/theme": "^1.0.80",
41
+ "@idealyst/components": "^1.0.82",
42
+ "@idealyst/theme": "^1.0.82",
43
43
  "@react-navigation/bottom-tabs": "^7.0.0",
44
44
  "@react-navigation/drawer": "^7.0.0",
45
45
  "@react-navigation/native": "^7.0.0",
@@ -6,19 +6,21 @@ import { useUnistyles } from 'react-native-unistyles';
6
6
 
7
7
  const NavigatorContext = createContext<NavigatorContextValue>({
8
8
  navigate: () => {},
9
- params: {},
10
9
  });
11
10
 
12
11
  // Utility function to parse path with parameters and find matching route
13
- const parseParameterizedPath = (path: string, routes: any[]): { routeName: string, params: Record<string, string> } | null => {
12
+ const parseParameterizedPath = (path: string, rootRoute: any): { routeName: string, params: Record<string, string> } | null => {
14
13
  // Handle absolute paths like /event/123
15
14
  if (path.startsWith('/')) {
16
15
  const pathSegments = path.split('/').filter(Boolean);
17
16
 
18
17
  // Find matching route by checking patterns like /event/:id
19
- const findMatchingRoute = (routeList: any[], segments: string[], startIndex = 0): any => {
18
+ const findMatchingRoute = (routeList: any[], segments: string[], startIndex = 0, pathPrefix = ''): any => {
20
19
  for (const route of routeList) {
21
20
  const routeSegments = route.path.split('/').filter(Boolean);
21
+ // Clean up path joining to avoid double slashes
22
+ const cleanPath = route.path.startsWith('/') ? route.path.slice(1) : route.path;
23
+ const fullRoutePath = pathPrefix ? `${pathPrefix}/${cleanPath}` : route.path;
22
24
 
23
25
  if (routeSegments.length === segments.length - startIndex) {
24
26
  let isMatch = true;
@@ -40,13 +42,18 @@ const parseParameterizedPath = (path: string, routes: any[]): { routeName: strin
40
42
  }
41
43
 
42
44
  if (isMatch) {
43
- return { route, params: extractedParams };
45
+ return { route, params: extractedParams, fullPath: fullRoutePath };
44
46
  }
45
47
  }
46
48
 
47
49
  // Check nested routes
48
50
  if (route.routes) {
49
- const nestedMatch = findMatchingRoute(route.routes, segments, startIndex + route.path.split('/').filter(Boolean).length);
51
+ const nestedMatch = findMatchingRoute(
52
+ route.routes,
53
+ segments,
54
+ startIndex + routeSegments.length,
55
+ fullRoutePath
56
+ );
50
57
  if (nestedMatch) {
51
58
  return nestedMatch;
52
59
  }
@@ -55,10 +62,10 @@ const parseParameterizedPath = (path: string, routes: any[]): { routeName: strin
55
62
  return null;
56
63
  };
57
64
 
58
- const match = findMatchingRoute([route], pathSegments);
65
+ const match = findMatchingRoute(rootRoute.routes || [], pathSegments);
59
66
  if (match) {
60
67
  return {
61
- routeName: match.route.path,
68
+ routeName: match.fullPath,
62
69
  params: match.params
63
70
  };
64
71
  }
@@ -70,13 +77,10 @@ const parseParameterizedPath = (path: string, routes: any[]): { routeName: strin
70
77
  const UnwrappedNavigatorProvider = ({ route }: NavigatorProviderProps) => {
71
78
 
72
79
  const navigation = useNavigation();
73
- const currentRoute = useRoute();
74
80
 
75
81
  const navigate = (params: NavigateParams) => {
76
-
77
82
  // Parse parameterized path for mobile
78
- const parsed = parseParameterizedPath(params.path, [route]);
79
-
83
+ const parsed = parseParameterizedPath(params.path, route);
80
84
  if (parsed) {
81
85
  // Navigate to the pattern route with extracted parameters
82
86
  navigation.navigate(parsed.routeName as never, parsed.params as never);
@@ -94,7 +98,6 @@ const UnwrappedNavigatorProvider = ({ route }: NavigatorProviderProps) => {
94
98
  return (
95
99
  <NavigatorContext.Provider value={{
96
100
  navigate,
97
- params: currentRoute.params || {}
98
101
  }}>
99
102
  <RouteComponent />
100
103
  </NavigatorContext.Provider>
@@ -5,14 +5,12 @@ import { buildNavigator } from '../routing';
5
5
 
6
6
  const NavigatorContext = createContext<NavigatorContextValue>({
7
7
  navigate: () => {},
8
- params: {},
9
8
  });
10
9
 
11
10
  export const NavigatorProvider = ({
12
11
  route,
13
12
  }: NavigatorProviderProps) => {
14
13
  const reactRouterNavigate = useNavigate()
15
- const params = useParams()
16
14
 
17
15
  const navigateFunction = (params: NavigateParams) => {
18
16
  if (params.path) {
@@ -44,7 +42,6 @@ export const NavigatorProvider = ({
44
42
  return (
45
43
  <NavigatorContext.Provider value={{
46
44
  navigate: navigateFunction,
47
- params: params || {}
48
45
  }}>
49
46
  <RouteComponent />
50
47
  </NavigatorContext.Provider>
@@ -17,5 +17,4 @@ export type NavigatorProviderProps = {
17
17
  */
18
18
  export type NavigatorContextValue = {
19
19
  navigate: (params: NavigateParams) => void;
20
- params: Record<string, string>;
21
20
  };
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import { View, Text } from '@idealyst/components'
3
3
  import { StackLayoutProps } from '../routing/types'
4
- import { Outlet } from 'react-router'
4
+ import { Outlet } from '..'
5
5
 
6
6
  export interface DefaultStackLayoutProps extends StackLayoutProps {
7
7
  onNavigate: (path: string) => void
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import { View, Text, Button, Icon } from '@idealyst/components'
3
3
  import { TabLayoutProps } from '../routing/types'
4
- import { Outlet } from 'react-router'
4
+ import { Outlet } from '..'
5
5
 
6
6
  export interface DefaultTabLayoutProps extends TabLayoutProps {}
7
7