@umituz/react-native-design-system 2.9.3 → 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,23 +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
|
-
*
|
|
11
|
-
* Ensures components and non-component logic use the EXACT same navigation interface.
|
|
24
|
+
* Clean navigation API without complex type casting.
|
|
25
|
+
* Use: const navigation = useAppNavigation();
|
|
26
|
+
* navigation.navigate("ScreenName", { param: value });
|
|
12
27
|
*/
|
|
13
|
-
export function useAppNavigation
|
|
14
|
-
const navigation = useNavigation<NavigationProp<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
);
|
|
23
97
|
}
|