@idealyst/navigation 1.0.61 → 1.0.63
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 +3 -3
- package/src/context/NavigatorContext.native.tsx +5 -3
- package/src/context/NavigatorContext.web.tsx +14 -6
- package/src/context/types.ts +2 -2
- package/src/examples/CustomStackLayout.tsx +63 -0
- package/src/examples/CustomTabLayout.tsx +44 -0
- package/src/examples/ExampleHybridRouter.tsx +34 -32
- package/src/examples/ExampleStackRouter.tsx +22 -24
- package/src/examples/ExampleTabRouter.tsx +42 -37
- package/src/layouts/DefaultStackLayout.tsx +57 -0
- package/src/layouts/DefaultTabLayout.tsx +101 -0
- package/src/layouts/index.ts +4 -1
- package/src/routing/router.native.tsx +40 -179
- package/src/routing/router.web.tsx +192 -335
- package/src/routing/types.ts +64 -17
- package/src/layouts/GeneralLayout/GeneralLayout.styles.tsx +0 -55
- package/src/layouts/GeneralLayout/GeneralLayout.tsx +0 -143
- package/src/layouts/GeneralLayout/README.md +0 -498
- package/src/layouts/GeneralLayout/index.ts +0 -2
- package/src/layouts/GeneralLayout/types.ts +0 -99
- package/src/layouts/TabBarLayout/TabBarLayout.native.tsx +0 -283
- package/src/layouts/TabBarLayout/TabBarLayout.styles.tsx +0 -142
- package/src/layouts/TabBarLayout/TabBarLayout.web.tsx +0 -286
- package/src/layouts/TabBarLayout/index.native.ts +0 -2
- package/src/layouts/TabBarLayout/index.ts +0 -2
- package/src/layouts/TabBarLayout/index.web.ts +0 -2
- package/src/layouts/TabBarLayout/types.ts +0 -176
- package/src/routing/README.md +0 -421
|
@@ -1,192 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NavigatorParam, RouteParam } from './types'
|
|
2
2
|
|
|
3
|
+
import { TypedNavigator } from "@react-navigation/native";
|
|
3
4
|
import { createNativeStackNavigator } from "@react-navigation/native-stack";
|
|
4
5
|
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
|
|
5
|
-
import { createDrawerNavigator } from "@react-navigation/drawer";
|
|
6
|
-
|
|
7
|
-
import { RouteParam, ScreenOptions } from "./types"
|
|
8
|
-
import { TypedNavigator } from "@react-navigation/native";
|
|
9
|
-
import { Icon } from '@idealyst/components';
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Build the Mobile navigator using React Navigation
|
|
9
|
+
* @param params
|
|
10
|
+
* @param parentPath
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export const buildNavigator = (params: NavigatorParam, parentPath = '') => {
|
|
14
|
+
const NavigatorType = getNavigatorType(params);
|
|
15
|
+
return () => (
|
|
16
|
+
<NavigatorType.Navigator>
|
|
17
|
+
{params.routes.map((child) => buildScreen(child, NavigatorType))}
|
|
18
|
+
</NavigatorType.Navigator>
|
|
19
|
+
)
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
|
-
*
|
|
23
|
+
* Get Navigator Type
|
|
24
|
+
* @param params
|
|
25
|
+
* @returns
|
|
17
26
|
*/
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
options.headerTitle = screenOptions.title;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (screenOptions.tabBarLabel) {
|
|
32
|
-
options.tabBarLabel = screenOptions.tabBarLabel;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (screenOptions.tabBarIcon) {
|
|
36
|
-
if (typeof screenOptions.tabBarIcon === 'string') {
|
|
37
|
-
options.tabBarIcon = ({ focused }: { focused: boolean; color: string; size: number }) => (
|
|
38
|
-
<Icon
|
|
39
|
-
name={screenOptions.tabBarIcon as any}
|
|
40
|
-
color={focused ? 'primary' : 'secondary'}
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
43
|
-
} else if (typeof screenOptions.tabBarIcon === 'function') {
|
|
44
|
-
options.tabBarIcon = screenOptions.tabBarIcon
|
|
45
|
-
} else {
|
|
46
|
-
options.tabBarIcon = screenOptions.tabBarIcon;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (screenOptions.tabBarBadge !== undefined) {
|
|
51
|
-
options.tabBarBadge = screenOptions.tabBarBadge;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (screenOptions.tabBarVisible !== undefined) {
|
|
55
|
-
options.tabBarStyle = screenOptions.tabBarVisible ? {} : { display: 'none' };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// headerTitle should override the default title in the header
|
|
59
|
-
if (screenOptions.headerTitle) {
|
|
60
|
-
options.headerTitle = screenOptions.headerTitle;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (screenOptions.headerBackVisible !== undefined) {
|
|
64
|
-
options.headerBackVisible = screenOptions.headerBackVisible;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (screenOptions.headerLeft) {
|
|
68
|
-
options.headerLeft = screenOptions.headerLeft;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (screenOptions.headerRight) {
|
|
72
|
-
options.headerRight = screenOptions.headerRight;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (screenOptions.platformOptions?.native) {
|
|
76
|
-
Object.assign(options, screenOptions.platformOptions.native);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return options;
|
|
80
|
-
};
|
|
27
|
+
const getNavigatorType = (params: NavigatorParam) => {
|
|
28
|
+
switch (params.layout) {
|
|
29
|
+
case 'stack':
|
|
30
|
+
return createNativeStackNavigator();
|
|
31
|
+
case 'tab':
|
|
32
|
+
return createBottomTabNavigator();
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Unsupported navigator type: ${params.layout}`);
|
|
35
|
+
}
|
|
81
36
|
|
|
82
37
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
38
|
+
* Build Screen
|
|
39
|
+
* @param params
|
|
40
|
+
* @param Navigator
|
|
41
|
+
* @param parentPath
|
|
87
42
|
* @returns
|
|
88
43
|
*/
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
44
|
+
const buildScreen = (params: RouteParam, Navigator: TypedNavigator, parentPath = '') => {
|
|
45
|
+
return (
|
|
46
|
+
<Navigator.Screen
|
|
47
|
+
name={params.path}
|
|
48
|
+
component={params.type === 'screen' ? params.component : buildNavigator(params, parentPath + params.path)}
|
|
49
|
+
options={params.options}
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
93
53
|
|
|
94
|
-
function buildComponent() {
|
|
95
|
-
switch (type) {
|
|
96
|
-
case 'stack':
|
|
97
|
-
const Stack = createNativeStackNavigator();
|
|
98
|
-
return (
|
|
99
|
-
<Stack.Navigator
|
|
100
|
-
screenOptions={{
|
|
101
|
-
// Disable screen optimization to ensure theme updates
|
|
102
|
-
freezeOnBlur: false,
|
|
103
|
-
}}
|
|
104
|
-
>
|
|
105
|
-
<Stack.Screen
|
|
106
|
-
name={nextPath}
|
|
107
|
-
component={routeParam.component}
|
|
108
|
-
options={screenOptions}
|
|
109
|
-
/>
|
|
110
|
-
{routeParam.routes?.map((route) => buildNativeRouter(route, nextPath, Stack))}
|
|
111
|
-
</Stack.Navigator>
|
|
112
|
-
)
|
|
113
|
-
case 'tab':
|
|
114
|
-
const Tab = createBottomTabNavigator();
|
|
115
|
-
return (
|
|
116
|
-
<Tab.Navigator
|
|
117
|
-
screenOptions={{
|
|
118
|
-
// Disable screen optimization to ensure theme updates
|
|
119
|
-
lazy: false,
|
|
120
|
-
freezeOnBlur: false,
|
|
121
|
-
}}
|
|
122
|
-
>
|
|
123
|
-
<Tab.Screen
|
|
124
|
-
name={nextPath}
|
|
125
|
-
component={routeParam.component}
|
|
126
|
-
options={screenOptions}
|
|
127
|
-
/>
|
|
128
|
-
{routeParam.routes?.map((route) => buildNativeRouter(route, nextPath, Tab))}
|
|
129
|
-
</Tab.Navigator>
|
|
130
|
-
)
|
|
131
|
-
case 'drawer':
|
|
132
|
-
const Drawer = createDrawerNavigator();
|
|
133
|
-
return (
|
|
134
|
-
<Drawer.Navigator
|
|
135
|
-
screenOptions={{
|
|
136
|
-
// Disable screen optimization to ensure theme updates
|
|
137
|
-
lazy: false,
|
|
138
|
-
freezeOnBlur: false,
|
|
139
|
-
}}
|
|
140
|
-
>
|
|
141
|
-
<Drawer.Screen
|
|
142
|
-
name={nextPath}
|
|
143
|
-
component={routeParam.component}
|
|
144
|
-
options={screenOptions}
|
|
145
|
-
/>
|
|
146
|
-
{routeParam.routes?.map((route) => buildNativeRouter(route, nextPath, Drawer))}
|
|
147
|
-
</Drawer.Navigator>
|
|
148
|
-
)
|
|
149
|
-
case 'modal':
|
|
150
|
-
if (!LastNavigator) {
|
|
151
|
-
throw new Error('LastNavigator is required for modal layout');
|
|
152
|
-
}
|
|
153
|
-
return (
|
|
154
|
-
<>
|
|
155
|
-
<LastNavigator.Screen
|
|
156
|
-
options={{ headerShown: false, presentation: 'modal', ...screenOptions }}
|
|
157
|
-
name={nextPath}
|
|
158
|
-
component={routeParam.component}
|
|
159
|
-
/>
|
|
160
|
-
{routeParam.routes?.map((route) => buildNativeRouter(route, nextPath, LastNavigator))}
|
|
161
|
-
</>
|
|
162
|
-
)
|
|
163
|
-
case undefined:
|
|
164
|
-
if (!LastNavigator) {
|
|
165
|
-
throw new Error('LastNavigator is required for undefined layout - ' + routeParam.path);
|
|
166
|
-
}
|
|
167
|
-
return (
|
|
168
|
-
<>
|
|
169
|
-
<LastNavigator.Screen
|
|
170
|
-
name={nextPath}
|
|
171
|
-
component={routeParam.component}
|
|
172
|
-
options={screenOptions}
|
|
173
|
-
/>
|
|
174
|
-
{routeParam.routes?.map((route) => buildNativeRouter(route, nextPath, LastNavigator))}
|
|
175
|
-
</>
|
|
176
|
-
)
|
|
177
|
-
default:
|
|
178
|
-
throw new Error(`Unknown layout type: ${type}`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const Component = buildComponent();
|
|
182
|
-
if (LastNavigator) {
|
|
183
|
-
return (
|
|
184
|
-
<LastNavigator.Screen
|
|
185
|
-
name={nextPath}
|
|
186
|
-
component={() => Component}
|
|
187
|
-
options={screenOptions}
|
|
188
|
-
/>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
return Component;
|
|
192
|
-
}
|