@umituz/react-native-design-system 2.9.1 → 2.9.3
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": "@umituz/react-native-design-system",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.3",
|
|
4
4
|
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, and onboarding utilities",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -26,8 +26,10 @@ export function StackNavigator<T extends ParamListBase>({ config }: StackNavigat
|
|
|
26
26
|
try {
|
|
27
27
|
NavigationValidator.validateScreens(config.screens, "stack");
|
|
28
28
|
NavigationValidator.validateInitialRoute(config.initialRouteName, config.screens);
|
|
29
|
-
} catch {
|
|
30
|
-
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (__DEV__) {
|
|
31
|
+
console.error('[StackNavigator] Validation failed:', error);
|
|
32
|
+
}
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
const { screens } = config;
|
|
@@ -32,8 +32,10 @@ export function TabsNavigator<T extends ParamListBase>({
|
|
|
32
32
|
config.initialRouteName,
|
|
33
33
|
config.screens
|
|
34
34
|
);
|
|
35
|
-
} catch {
|
|
36
|
-
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (__DEV__) {
|
|
37
|
+
console.error('[TabsNavigator] Validation failed:', error);
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
// Memoize filtered screens
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { useNavigation } from "@react-navigation/native";
|
|
2
2
|
import type { NavigationProp, ParamListBase } from "@react-navigation/native";
|
|
3
|
+
import { AppNavigation } from "../utils/AppNavigation";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* useAppNavigation Hook
|
|
6
7
|
*
|
|
7
|
-
* A wrapper
|
|
8
|
-
*
|
|
8
|
+
* A unified wrapper that returns the unified AppNavigation object
|
|
9
|
+
* but enriched with context-specific features from React Navigation.
|
|
10
|
+
*
|
|
11
|
+
* Ensures components and non-component logic use the EXACT same navigation interface.
|
|
9
12
|
*/
|
|
10
|
-
export function useAppNavigation<T extends ParamListBase>()
|
|
11
|
-
|
|
13
|
+
export function useAppNavigation<T extends ParamListBase>() {
|
|
14
|
+
const navigation = useNavigation<NavigationProp<T>>();
|
|
15
|
+
|
|
16
|
+
// We return a merge of the standard navigation object and our unified AppNavigation actions.
|
|
17
|
+
// This ensures that even if called via a hook, actions like goBack() go through our
|
|
18
|
+
// unified implementation (including logging and safety checks).
|
|
19
|
+
return {
|
|
20
|
+
...navigation,
|
|
21
|
+
...AppNavigation,
|
|
22
|
+
} as NavigationProp<T> & typeof AppNavigation;
|
|
12
23
|
}
|
|
@@ -1,123 +1,148 @@
|
|
|
1
1
|
import { NavigationContainerRef, CommonActions, StackActions } from '@react-navigation/native';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* Global Navigation Implementation
|
|
5
|
+
* Single source of truth for all navigation actions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
let navigationRef: NavigationContainerRef<any> | null = null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Set the global navigation reference.
|
|
12
|
+
* Should be called in the root NavigationContainer.
|
|
13
|
+
*/
|
|
14
|
+
export const setRef = (ref: NavigationContainerRef<any> | null): void => {
|
|
15
|
+
if (__DEV__) {
|
|
16
|
+
console.log('[AppNavigation] Setting navigation ref', !!ref);
|
|
17
|
+
}
|
|
18
|
+
navigationRef = ref;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the current navigation reference.
|
|
23
|
+
*/
|
|
24
|
+
export const getRef = (): NavigationContainerRef<any> | null => navigationRef;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if the navigator is ready.
|
|
28
|
+
*/
|
|
29
|
+
export const isReady = (): boolean => navigationRef?.isReady() ?? false;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check if the navigator can go back.
|
|
33
|
+
*/
|
|
34
|
+
export const canGoBack = (): boolean => navigationRef?.canGoBack() ?? false;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Navigate to a specific route.
|
|
38
|
+
*/
|
|
39
|
+
export const navigate = (name: string, params?: object): void => {
|
|
40
|
+
if (__DEV__) {
|
|
41
|
+
console.log('[AppNavigation] Navigating to:', name, params);
|
|
42
|
+
}
|
|
43
|
+
if (navigationRef?.isReady()) {
|
|
44
|
+
navigationRef.navigate(name, params);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Push a new route onto the stack.
|
|
50
|
+
*/
|
|
51
|
+
export const push = (name: string, params?: object): void => {
|
|
52
|
+
if (__DEV__) {
|
|
53
|
+
console.log('[AppNavigation] Pushing:', name, params);
|
|
54
|
+
}
|
|
55
|
+
if (navigationRef?.isReady()) {
|
|
56
|
+
navigationRef.dispatch(StackActions.push(name, params));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Go back to the previous screen.
|
|
62
|
+
*/
|
|
63
|
+
export const goBack = (): void => {
|
|
64
|
+
if (__DEV__) {
|
|
65
|
+
console.log('[AppNavigation] Going back');
|
|
66
|
+
}
|
|
67
|
+
if (navigationRef?.isReady() && navigationRef.canGoBack()) {
|
|
68
|
+
navigationRef.goBack();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Reset the navigation state.
|
|
74
|
+
*/
|
|
75
|
+
export const reset = (name: string, params?: object): void => {
|
|
76
|
+
if (__DEV__) {
|
|
77
|
+
console.log('[AppNavigation] Resetting to:', name, params);
|
|
78
|
+
}
|
|
79
|
+
if (navigationRef?.isReady()) {
|
|
80
|
+
navigationRef.dispatch(
|
|
81
|
+
CommonActions.reset({
|
|
82
|
+
index: 0,
|
|
83
|
+
routes: [{ name, params }],
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Replace the current route.
|
|
91
|
+
*/
|
|
92
|
+
export const replace = (name: string, params?: object): void => {
|
|
93
|
+
if (__DEV__) {
|
|
94
|
+
console.log('[AppNavigation] Replacing with:', name, params);
|
|
95
|
+
}
|
|
96
|
+
if (navigationRef?.isReady()) {
|
|
97
|
+
navigationRef.dispatch(StackActions.replace(name, params));
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Pop to the top of the stack.
|
|
103
|
+
*/
|
|
104
|
+
export const popToTop = (): void => {
|
|
105
|
+
if (__DEV__) {
|
|
106
|
+
console.log('[AppNavigation] Popping to top');
|
|
107
|
+
}
|
|
108
|
+
if (navigationRef?.isReady()) {
|
|
109
|
+
navigationRef.dispatch(StackActions.popToTop());
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Pop specific number of screens.
|
|
115
|
+
*/
|
|
116
|
+
export const pop = (count: number = 1): void => {
|
|
117
|
+
if (__DEV__) {
|
|
118
|
+
console.log('[AppNavigation] Popping:', count);
|
|
119
|
+
}
|
|
120
|
+
if (navigationRef?.isReady()) {
|
|
121
|
+
navigationRef.dispatch(StackActions.pop(count));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the current route name.
|
|
127
|
+
*/
|
|
128
|
+
export const getCurrentRoute = (): string | undefined => {
|
|
129
|
+
return navigationRef?.getCurrentRoute()?.name;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Unified AppNavigation Object for both static and hook-based usage.
|
|
134
|
+
*/
|
|
135
|
+
export const AppNavigation = {
|
|
136
|
+
setRef,
|
|
137
|
+
getRef,
|
|
138
|
+
isReady,
|
|
139
|
+
canGoBack,
|
|
140
|
+
navigate,
|
|
141
|
+
push,
|
|
142
|
+
goBack,
|
|
143
|
+
reset,
|
|
144
|
+
replace,
|
|
145
|
+
popToTop,
|
|
146
|
+
pop,
|
|
147
|
+
getCurrentRoute,
|
|
148
|
+
};
|