@umituz/react-native-design-system 2.9.2 → 2.9.4
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.4",
|
|
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",
|
|
@@ -1,32 +1,97 @@
|
|
|
1
1
|
import { useNavigation } from "@react-navigation/native";
|
|
2
2
|
import type { NavigationProp, ParamListBase } from "@react-navigation/native";
|
|
3
|
-
import {
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Navigation result type - clean and simple
|
|
7
|
+
*/
|
|
8
|
+
export interface AppNavigationResult {
|
|
9
|
+
navigate: (screen: string, params?: Record<string, unknown>) => void;
|
|
10
|
+
push: (screen: string, params?: Record<string, unknown>) => void;
|
|
11
|
+
goBack: () => void;
|
|
12
|
+
reset: (screen: string, params?: Record<string, unknown>) => void;
|
|
13
|
+
replace: (screen: string, params?: Record<string, unknown>) => void;
|
|
14
|
+
pop: (count?: number) => void;
|
|
15
|
+
popToTop: () => void;
|
|
16
|
+
canGoBack: () => boolean;
|
|
17
|
+
getState: () => ReturnType<NavigationProp<ParamListBase>["getState"]>;
|
|
18
|
+
getParent: () => NavigationProp<ParamListBase> | undefined;
|
|
19
|
+
}
|
|
4
20
|
|
|
5
21
|
/**
|
|
6
22
|
* useAppNavigation Hook
|
|
7
23
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
24
|
+
* Clean navigation API without complex type casting.
|
|
25
|
+
* Use: const navigation = useAppNavigation();
|
|
26
|
+
* navigation.navigate("ScreenName", { param: value });
|
|
11
27
|
*/
|
|
12
|
-
export function useAppNavigation
|
|
13
|
-
const navigation = useNavigation<NavigationProp<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
export function useAppNavigation(): AppNavigationResult {
|
|
29
|
+
const navigation = useNavigation<NavigationProp<ParamListBase>>();
|
|
30
|
+
|
|
31
|
+
const navigate = useCallback(
|
|
32
|
+
(screen: string, params?: Record<string, unknown>) => {
|
|
33
|
+
(navigation.navigate as (name: string, params?: object) => void)(screen, params);
|
|
34
|
+
},
|
|
35
|
+
[navigation]
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const push = useCallback(
|
|
39
|
+
(screen: string, params?: Record<string, unknown>) => {
|
|
40
|
+
navigation.dispatch({ type: "PUSH", payload: { name: screen, params } });
|
|
41
|
+
},
|
|
42
|
+
[navigation]
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const goBack = useCallback(() => {
|
|
46
|
+
if (navigation.canGoBack()) {
|
|
47
|
+
navigation.goBack();
|
|
48
|
+
}
|
|
49
|
+
}, [navigation]);
|
|
50
|
+
|
|
51
|
+
const reset = useCallback(
|
|
52
|
+
(screen: string, params?: Record<string, unknown>) => {
|
|
53
|
+
navigation.reset({ index: 0, routes: [{ name: screen, params }] });
|
|
54
|
+
},
|
|
55
|
+
[navigation]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const replace = useCallback(
|
|
59
|
+
(screen: string, params?: Record<string, unknown>) => {
|
|
60
|
+
navigation.dispatch({ type: "REPLACE", payload: { name: screen, params } });
|
|
61
|
+
},
|
|
62
|
+
[navigation]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const pop = useCallback(
|
|
66
|
+
(count = 1) => {
|
|
67
|
+
navigation.dispatch({ type: "POP", payload: { count } });
|
|
68
|
+
},
|
|
69
|
+
[navigation]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const popToTop = useCallback(() => {
|
|
73
|
+
navigation.dispatch({ type: "POP_TO_TOP" });
|
|
74
|
+
}, [navigation]);
|
|
75
|
+
|
|
76
|
+
const canGoBack = useCallback(() => navigation.canGoBack(), [navigation]);
|
|
77
|
+
|
|
78
|
+
const getState = useCallback(() => navigation.getState(), [navigation]);
|
|
79
|
+
|
|
80
|
+
const getParent = useCallback(() => navigation.getParent(), [navigation]);
|
|
81
|
+
|
|
82
|
+
return useMemo(
|
|
83
|
+
() => ({
|
|
84
|
+
navigate,
|
|
85
|
+
push,
|
|
86
|
+
goBack,
|
|
87
|
+
reset,
|
|
88
|
+
replace,
|
|
89
|
+
pop,
|
|
90
|
+
popToTop,
|
|
91
|
+
canGoBack,
|
|
92
|
+
getState,
|
|
93
|
+
getParent,
|
|
94
|
+
}),
|
|
95
|
+
[navigate, push, goBack, reset, replace, pop, popToTop, canGoBack, getState, getParent]
|
|
96
|
+
);
|
|
32
97
|
}
|
|
@@ -1,155 +1,148 @@
|
|
|
1
1
|
import { NavigationContainerRef, CommonActions, StackActions } from '@react-navigation/native';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Get the current navigation reference.
|
|
23
|
+
*/
|
|
24
|
+
export const getRef = (): NavigationContainerRef<any> | null => navigationRef;
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Check if the navigator is ready.
|
|
28
|
+
*/
|
|
29
|
+
export const isReady = (): boolean => navigationRef?.isReady() ?? false;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
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
|
-
|
|
129
|
-
|
|
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
|
-
|
|
133
|
-
this.navigate('Profile');
|
|
108
|
+
if (navigationRef?.isReady()) {
|
|
109
|
+
navigationRef.dispatch(StackActions.popToTop());
|
|
134
110
|
}
|
|
111
|
+
};
|
|
135
112
|
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
141
|
-
this.navigateToParent(name, params);
|
|
120
|
+
if (navigationRef?.isReady()) {
|
|
121
|
+
navigationRef.dispatch(StackActions.pop(count));
|
|
142
122
|
}
|
|
123
|
+
};
|
|
143
124
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
+
};
|