@applicaster/zapp-react-native-utils 12.0.0-rc.39 → 12.0.0-rc.40
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 +2 -2
- package/reactHooks/navigation/index.ts +48 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.0-rc.
|
|
3
|
+
"version": "12.0.0-rc.40",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "12.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-rc.40",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -146,6 +146,15 @@ export const useRoute = (): {
|
|
|
146
146
|
pathname: string;
|
|
147
147
|
} => {
|
|
148
148
|
const pathname = usePathname() || "";
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* compose `useRoute()` output data
|
|
152
|
+
*/
|
|
153
|
+
const composeRouteData = (screenData: VariousScreenData) => ({
|
|
154
|
+
screenData,
|
|
155
|
+
pathname,
|
|
156
|
+
});
|
|
157
|
+
|
|
149
158
|
const navigator = useNavigation();
|
|
150
159
|
|
|
151
160
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
@@ -157,9 +166,7 @@ export const useRoute = (): {
|
|
|
157
166
|
const currentStack = navigator.getStackForPathname(pathname);
|
|
158
167
|
const { modalState } = useModalStore();
|
|
159
168
|
const hookModalState = useZappHooksModalState();
|
|
160
|
-
|
|
161
169
|
const modalScreenData = modalState.screen;
|
|
162
|
-
|
|
163
170
|
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
164
171
|
|
|
165
172
|
const videoModalScreenData =
|
|
@@ -193,36 +200,58 @@ export const useRoute = (): {
|
|
|
193
200
|
// if path is hook grab screenData from screenData
|
|
194
201
|
|
|
195
202
|
if (isModalPathname(pathname)) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return { screenData, pathname };
|
|
203
|
+
return composeRouteData(modalScreenData ?? ({} as ZappEntry));
|
|
199
204
|
}
|
|
200
205
|
|
|
201
206
|
if (isVideoModalPathname(pathname)) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return { screenData, pathname };
|
|
207
|
+
return composeRouteData(videoModalScreenData as LegacyNavigationScreenData);
|
|
205
208
|
}
|
|
206
209
|
|
|
207
210
|
if (isHookModalPathname(pathname)) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return { screenData, pathname };
|
|
211
|
+
return composeRouteData(hookModalScreenData);
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
if (isHookPathname(pathname)) {
|
|
214
|
-
|
|
215
|
+
/**
|
|
216
|
+
* HACK
|
|
217
|
+
*
|
|
218
|
+
* This condition relies on hacky approach to get the current hook screen data
|
|
219
|
+
* using navigator.screenData for some cases.
|
|
220
|
+
* This is used when hook is in sequence.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
// case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
|
|
224
|
+
if (!currentStack) {
|
|
225
|
+
return composeRouteData(navigator.screenData);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const isValidHookInCurrentRouteScreenData =
|
|
215
229
|
"hookPlugin" in currentRouteScreenData &&
|
|
216
|
-
currentRouteScreenData.hookPlugin
|
|
217
|
-
? currentRouteScreenData
|
|
218
|
-
: navigator.screenData;
|
|
230
|
+
!!currentRouteScreenData.hookPlugin?.module;
|
|
219
231
|
|
|
220
|
-
|
|
221
|
-
|
|
232
|
+
let screenData;
|
|
233
|
+
|
|
234
|
+
// case 2: stack has valid hook data
|
|
235
|
+
if (isValidHookInCurrentRouteScreenData) {
|
|
236
|
+
screenData = currentRouteScreenData;
|
|
237
|
+
}
|
|
222
238
|
|
|
223
|
-
|
|
239
|
+
const navigatorScreenData = navigator.screenData as NavigatorEntry;
|
|
240
|
+
|
|
241
|
+
// case 3: current hookPlugin is missing weight, but navigator.screenData has weight, use navigator.screenData
|
|
242
|
+
if (
|
|
243
|
+
screenData.hookPlugin.identifier ===
|
|
244
|
+
navigatorScreenData?.hookPlugin?.identifier &&
|
|
245
|
+
!screenData.hookPlugin?.weight &&
|
|
246
|
+
navigatorScreenData?.hookPlugin?.weight
|
|
247
|
+
) {
|
|
248
|
+
screenData = navigator.screenData;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return composeRouteData(screenData);
|
|
252
|
+
}
|
|
224
253
|
|
|
225
|
-
return
|
|
254
|
+
return composeRouteData(currentRouteScreenData);
|
|
226
255
|
};
|
|
227
256
|
|
|
228
257
|
type Callbacks = Partial<{
|