@umituz/react-native-design-system 2.9.2 → 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.2",
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",
@@ -5,28 +5,19 @@ import { AppNavigation } from "../utils/AppNavigation";
5
5
  /**
6
6
  * useAppNavigation Hook
7
7
  *
8
- * A unified wrapper around React Navigation's useNavigation hook.
9
- * Standardizes navigation usage across all packages and apps by
10
- * providing a consistent interface that bridges static and hook-based navigation.
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.
11
12
  */
12
13
  export function useAppNavigation<T extends ParamListBase>() {
13
14
  const navigation = useNavigation<NavigationProp<T>>();
14
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).
15
19
  return {
16
20
  ...navigation,
17
- // Standardized actions using the global AppNavigation utility for consistency
18
- goBack: () => AppNavigation.goBack(),
19
- navigate: (name: any, params?: any) => AppNavigation.navigate(name, params),
20
- push: (name: any, params?: any) => AppNavigation.push(name, params),
21
- replace: (name: any, params?: any) => AppNavigation.replace(name, params),
22
- reset: (name: any, params?: any) => AppNavigation.reset(name, params),
23
- pop: (count?: number) => AppNavigation.pop(count),
24
- popToTop: () => AppNavigation.popToTop(),
25
- } as NavigationProp<T> & {
26
- push: (name: string, params?: object) => void;
27
- replace: (name: string, params?: object) => void;
28
- reset: (name: string, params?: object) => void;
29
- pop: (count?: number) => void;
30
- popToTop: () => void;
31
- };
21
+ ...AppNavigation,
22
+ } as NavigationProp<T> & typeof AppNavigation;
32
23
  }
@@ -1,155 +1,148 @@
1
1
  import { NavigationContainerRef, CommonActions, StackActions } from '@react-navigation/native';
2
2
 
3
3
  /**
4
- * AppNavigation - Global Navigation Utility
5
- *
6
- * Provides static access to navigation methods from anywhere in the app.
7
- * Must be initialized with setRef in the root NavigationContainer.
4
+ * Global Navigation Implementation
5
+ * Single source of truth for all navigation actions.
8
6
  */
9
- export class AppNavigation {
10
- private static navigationRef: NavigationContainerRef<any> | null = null;
11
7
 
12
- static setRef(ref: NavigationContainerRef<any> | null): void {
13
- if (__DEV__) {
14
- console.log('[AppNavigation] Setting navigation ref', !!ref);
15
- }
16
- this.navigationRef = ref;
17
- }
8
+ let navigationRef: NavigationContainerRef<any> | null = null;
18
9
 
19
- static getRef(): NavigationContainerRef<any> | null {
20
- return this.navigationRef;
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);
21
17
  }
18
+ navigationRef = ref;
19
+ };
22
20
 
23
- static isReady(): boolean {
24
- return this.navigationRef?.isReady() ?? false;
25
- }
21
+ /**
22
+ * Get the current navigation reference.
23
+ */
24
+ export const getRef = (): NavigationContainerRef<any> | null => navigationRef;
26
25
 
27
- static canGoBack(): boolean {
28
- return this.navigationRef?.canGoBack() ?? false;
29
- }
26
+ /**
27
+ * Check if the navigator is ready.
28
+ */
29
+ export const isReady = (): boolean => navigationRef?.isReady() ?? false;
30
30
 
31
- static navigate(name: string, params?: object): void {
32
- if (__DEV__) {
33
- console.log('[AppNavigation] Navigating to:', name, params);
34
- }
35
- if (this.navigationRef?.isReady()) {
36
- this.navigationRef.navigate(name, params);
37
- }
38
- }
31
+ /**
32
+ * Check if the navigator can go back.
33
+ */
34
+ export const canGoBack = (): boolean => navigationRef?.canGoBack() ?? false;
39
35
 
40
- static push(name: string, params?: object): void {
41
- if (__DEV__) {
42
- console.log('[AppNavigation] Pushing:', name, params);
43
- }
44
- if (this.navigationRef?.isReady()) {
45
- this.navigationRef.dispatch(StackActions.push(name, params));
46
- }
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);
47
42
  }
48
-
49
- static goBack(): void {
50
- if (__DEV__) {
51
- console.log('[AppNavigation] Going back');
52
- }
53
- if (this.navigationRef?.isReady() && this.navigationRef.canGoBack()) {
54
- this.navigationRef.goBack();
55
- }
43
+ if (navigationRef?.isReady()) {
44
+ navigationRef.navigate(name, params);
56
45
  }
46
+ };
57
47
 
58
- static reset(name: string, params?: object): void {
59
- if (__DEV__) {
60
- console.log('[AppNavigation] Resetting to:', name, params);
61
- }
62
- if (this.navigationRef?.isReady()) {
63
- this.navigationRef.dispatch(
64
- CommonActions.reset({
65
- index: 0,
66
- routes: [{ name, params }],
67
- })
68
- );
69
- }
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);
70
54
  }
71
-
72
- static replace(name: string, params?: object): void {
73
- if (__DEV__) {
74
- console.log('[AppNavigation] Replacing with:', name, params);
75
- }
76
- if (this.navigationRef?.isReady()) {
77
- this.navigationRef.dispatch(StackActions.replace(name, params));
78
- }
55
+ if (navigationRef?.isReady()) {
56
+ navigationRef.dispatch(StackActions.push(name, params));
79
57
  }
58
+ };
80
59
 
81
- static navigateToNested(parentParams: { screen: string; params?: any }): void {
82
- if (__DEV__) {
83
- console.log('[AppNavigation] Navigating to nested:', parentParams);
84
- }
85
- if (this.navigationRef?.isReady()) {
86
- this.navigationRef.navigate(parentParams.screen, parentParams.params);
87
- }
60
+ /**
61
+ * Go back to the previous screen.
62
+ */
63
+ export const goBack = (): void => {
64
+ if (__DEV__) {
65
+ console.log('[AppNavigation] Going back');
88
66
  }
89
-
90
- static navigateToParent(name: string, params?: object): void {
91
- if (__DEV__) {
92
- console.log('[AppNavigation] Navigating to parent:', name, params);
93
- }
94
- if (this.navigationRef?.isReady()) {
95
- const parent = this.navigationRef.getParent();
96
- if (parent) {
97
- parent.navigate(name, params);
98
- }
99
- }
67
+ if (navigationRef?.isReady() && navigationRef.canGoBack()) {
68
+ navigationRef.goBack();
100
69
  }
70
+ };
101
71
 
102
- static popToTop(): void {
103
- if (__DEV__) {
104
- console.log('[AppNavigation] Popping to top');
105
- }
106
- if (this.navigationRef?.isReady()) {
107
- this.navigationRef.dispatch(StackActions.popToTop());
108
- }
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);
109
78
  }
110
-
111
- static pop(count: number = 1): void {
112
- if (__DEV__) {
113
- console.log('[AppNavigation] Popping:', count);
114
- }
115
- if (this.navigationRef?.isReady()) {
116
- this.navigationRef.dispatch(StackActions.pop(count));
117
- }
79
+ if (navigationRef?.isReady()) {
80
+ navigationRef.dispatch(
81
+ CommonActions.reset({
82
+ index: 0,
83
+ routes: [{ name, params }],
84
+ })
85
+ );
118
86
  }
87
+ };
119
88
 
120
- static getCurrentRoute(): string | undefined {
121
- return this.navigationRef?.getCurrentRoute()?.name;
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);
122
95
  }
123
-
124
- static getCurrentParams<T extends object>(): T | undefined {
125
- return this.navigationRef?.getCurrentRoute()?.params as T | undefined;
96
+ if (navigationRef?.isReady()) {
97
+ navigationRef.dispatch(StackActions.replace(name, params));
126
98
  }
99
+ };
127
100
 
128
- static goToSettings(): void {
129
- this.navigate('Settings');
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');
130
107
  }
131
-
132
- static goToProfile(): void {
133
- this.navigate('Profile');
108
+ if (navigationRef?.isReady()) {
109
+ navigationRef.dispatch(StackActions.popToTop());
134
110
  }
111
+ };
135
112
 
136
- static goToHome(): void {
137
- this.navigate('Home');
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);
138
119
  }
139
-
140
- static openModal(name: string, params?: object): void {
141
- this.navigateToParent(name, params);
120
+ if (navigationRef?.isReady()) {
121
+ navigationRef.dispatch(StackActions.pop(count));
142
122
  }
123
+ };
143
124
 
144
- static closeModal(): void {
145
- if (__DEV__) {
146
- console.log('[AppNavigation] Closing modal');
147
- }
148
- if (this.navigationRef?.isReady()) {
149
- const parent = this.navigationRef.getParent();
150
- if (parent?.canGoBack()) {
151
- parent.goBack();
152
- }
153
- }
154
- }
155
- }
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
+ };