@applicaster/zapp-react-native-utils 12.0.0-alpha.5353184830 → 12.0.0-alpha.5400461972
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/actionsExecutor/ActionExecutorContext.tsx +16 -8
- package/analyticsUtils/AnalyticsEvents/index.ts +6 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/analyticsPlugins.ts +25 -0
- package/analyticsUtils/events.ts +6 -0
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/analyticsUtils/index.tsx +6 -0
- package/appUtils/HooksManager/index.js +3 -1
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +12 -3
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
- package/appUtils/keyCodes/keys.web.js +1 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/conts.ts +5 -0
- package/appUtils/playerManager/player.ts +47 -4
- package/appUtils/playerManager/playerFactory.ts +15 -1
- package/appUtils/playerManager/playerNative.ts +35 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
- package/appUtils/playerManager/usePlayerState.tsx +13 -1
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/cellUtils/__tests__/cellUtils.test.ts +48 -0
- package/cellUtils/__tests__/fixtures.ts +13 -0
- package/cellUtils/index.ts +40 -2
- package/dateUtils/index.ts +11 -0
- package/focusManager/index.ts +1 -1
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
- package/functionUtils/__tests__/functionUtils.test.js +244 -248
- package/headersUtils/index.ts +1 -0
- package/inflatedUrlUtils/index.ts +4 -4
- package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
- package/localizationUtils/index.ts +13 -19
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +10 -1
- package/manifestUtils/index.js +5 -1
- package/manifestUtils/secondaryImage/index.js +18 -15
- package/modalState/index.ts +57 -0
- package/navigationUtils/index.ts +56 -7
- package/numberUtils/index.ts +4 -0
- package/package.json +3 -2
- package/playerUtils/configurationGenerator.ts +11 -1
- package/pluginUtils/index.ts +11 -7
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
- package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
- package/reactHooks/cell-click/__tests__/index.test.js +11 -2
- package/reactHooks/cell-click/index.ts +4 -4
- package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
- package/reactHooks/feed/useInflatedUrl.ts +44 -15
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
- package/reactHooks/layout/types/index.ts +2 -0
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
- package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
- package/reactHooks/navigation/__mocks__/index.ts +15 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
- package/reactHooks/navigation/index.ts +204 -86
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
- package/reactHooks/screen/index.ts +2 -0
- package/reactHooks/screen/useScreenContext.ts +5 -4
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/screen/useTargetScreenData.ts +7 -0
- package/reactHooks/state/useRivers.ts +3 -1
- package/reactHooks/useListenEventBusEvent.ts +1 -4
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
- package/riverComponetsMeasurementProvider/index.tsx +2 -2
- package/stringUtils/index.ts +5 -0
- package/testUtils/getByTestId.ts +14 -0
- package/testUtils/index.tsx +38 -23
- package/types.ts +4 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
2
|
/* eslint max-len: off */
|
|
3
3
|
|
|
4
|
-
import React, { useEffect, useMemo } from "react";
|
|
4
|
+
import React, { useContext, useEffect, useMemo } from "react";
|
|
5
5
|
import { BackHandler, InteractionManager, NativeModules } from "react-native";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
7
|
|
|
@@ -17,18 +17,104 @@ import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-component
|
|
|
17
17
|
import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
18
18
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
19
19
|
import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
|
|
20
|
-
import { getNavigationProps } from "@applicaster/zapp-react-native-utils/navigationUtils";
|
|
21
20
|
import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
|
|
22
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
getNavigationProps,
|
|
23
|
+
getRiverFromRoute,
|
|
24
|
+
getTargetRoute,
|
|
25
|
+
} from "../../navigationUtils";
|
|
23
26
|
import { platformSelect } from "../../reactUtils";
|
|
24
27
|
import { useConnectionInfo } from "../connection";
|
|
25
28
|
import { getTargetScreenData } from "../screen/useTargetScreenData";
|
|
26
|
-
import { useNavbarState } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
|
|
27
29
|
|
|
30
|
+
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
31
|
+
import { useNavbarState } from "../screen";
|
|
28
32
|
import { useNavigation } from "./useNavigation";
|
|
33
|
+
import { useModalStore } from "../../modalState";
|
|
34
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
29
35
|
|
|
30
36
|
export { useNavigation } from "./useNavigation";
|
|
31
37
|
|
|
38
|
+
/**
|
|
39
|
+
* This function helps to decide wether the navbar should be presented on the screen
|
|
40
|
+
* based on route and / or screen Data
|
|
41
|
+
*
|
|
42
|
+
* Currently the scenarios include
|
|
43
|
+
* - players => false
|
|
44
|
+
* - search screen plugin => false
|
|
45
|
+
* - hooks with `showNavBar: true` or `presentFullScreen` not set to true, defaults to no navbar for hook screens
|
|
46
|
+
* - screens with `allow_screen_plugin_presentation` in general property => false
|
|
47
|
+
*
|
|
48
|
+
* @param {String} route current route of the screen
|
|
49
|
+
* @param {Object} screenData payload associated with the currently presented screen
|
|
50
|
+
* @returns {Boolean}
|
|
51
|
+
*/
|
|
52
|
+
export function isNavBarVisible(
|
|
53
|
+
route: string,
|
|
54
|
+
screenData: ZappRiver = {} as ZappRiver,
|
|
55
|
+
showNavBar: boolean,
|
|
56
|
+
canGoBack: boolean,
|
|
57
|
+
videoModalState: QuickBrickVideoModalState | null = null
|
|
58
|
+
) {
|
|
59
|
+
/* screenData is not actual navigator.data
|
|
60
|
+
* or navigator.screenData,
|
|
61
|
+
* but navigator.data.screen */
|
|
62
|
+
if (route.includes("playable")) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
videoModalState?.mode === "FULLSCREEN" &&
|
|
68
|
+
videoModalState?.visible === true
|
|
69
|
+
) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (screenData?.type === "qb_search_screen" && !isTV()) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* Match if screen is Hook */
|
|
78
|
+
if (route.startsWith("/hooks/")) {
|
|
79
|
+
const module = screenData?.module;
|
|
80
|
+
|
|
81
|
+
if (module?.presentFullScreen) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return module?.showNavBar ?? false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (screenData?.hookPlugin) {
|
|
89
|
+
const hookPlugin = screenData?.hookPlugin?.module;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (
|
|
97
|
+
screenData?.general?.allow_screen_plugin_presentation ||
|
|
98
|
+
screenData?.general?.hide_app_nav_bar
|
|
99
|
+
) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const hideSecondaryLevel = screenData?.navigations?.some(
|
|
104
|
+
(navigation) => navigation.styles?.hide_secondary_level_menu
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
if (canGoBack && hideSecondaryLevel) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (typeof showNavBar === "boolean" && !showNavBar) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
32
118
|
const { ProfilerBridge } = NativeModules;
|
|
33
119
|
|
|
34
120
|
export const usePathname = () => React.useContext(PathnameContext);
|
|
@@ -43,6 +129,88 @@ export const useBackHandler = (cb: () => boolean) => {
|
|
|
43
129
|
}, [cb]);
|
|
44
130
|
};
|
|
45
131
|
|
|
132
|
+
// starts with modal/
|
|
133
|
+
const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
|
|
134
|
+
|
|
135
|
+
const isVideoModalPathname = (pathname: string) =>
|
|
136
|
+
/^video-modal\//.test(pathname);
|
|
137
|
+
|
|
138
|
+
const isHookModalPathname = (pathname: string) =>
|
|
139
|
+
/^hooks-modal\//.test(pathname);
|
|
140
|
+
|
|
141
|
+
const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
142
|
+
|
|
143
|
+
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
144
|
+
|
|
145
|
+
export const useRoute = (): {
|
|
146
|
+
screenData: VariousScreenData;
|
|
147
|
+
pathname: string;
|
|
148
|
+
} => {
|
|
149
|
+
const pathname = usePathname() || "";
|
|
150
|
+
const navigator = useNavigation();
|
|
151
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
152
|
+
|
|
153
|
+
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
154
|
+
"plugins",
|
|
155
|
+
"rivers",
|
|
156
|
+
"contentTypes",
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
const { modalState } = useModalStore();
|
|
160
|
+
const hookModalState = useZappHooksModalState();
|
|
161
|
+
|
|
162
|
+
const modalScreenData = modalState.screen;
|
|
163
|
+
|
|
164
|
+
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
165
|
+
|
|
166
|
+
const videoModalScreenData =
|
|
167
|
+
navigator.videoModalState?.item &&
|
|
168
|
+
legacyScreenData(
|
|
169
|
+
{
|
|
170
|
+
entry: navigator.videoModalState?.item as ZappEntry,
|
|
171
|
+
screen: getTargetScreenData(
|
|
172
|
+
navigator.videoModalState?.item as ZappEntry,
|
|
173
|
+
rivers,
|
|
174
|
+
contentTypes
|
|
175
|
+
),
|
|
176
|
+
},
|
|
177
|
+
plugins
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// There are 4 route scenarios
|
|
181
|
+
// For regular screens take date from navigator stack.
|
|
182
|
+
// is path is model grab screenData from modal state
|
|
183
|
+
// if path is video modal grab screenData from video state
|
|
184
|
+
// if path is hook modal grab screenData from hook state
|
|
185
|
+
// if path is hook grab screenData from screenData
|
|
186
|
+
|
|
187
|
+
if (isModalPathname(pathname)) {
|
|
188
|
+
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
189
|
+
|
|
190
|
+
return { screenData, pathname };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isVideoModalPathname(pathname)) {
|
|
194
|
+
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
195
|
+
|
|
196
|
+
return { screenData, pathname };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (isHookModalPathname(pathname)) {
|
|
200
|
+
const screenData = hookModalScreenData;
|
|
201
|
+
|
|
202
|
+
return { screenData, pathname };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (isHookPathname(pathname)) {
|
|
206
|
+
return { screenData: screenDataContext, pathname };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const screenData = screenDataContext;
|
|
210
|
+
|
|
211
|
+
return { screenData, pathname };
|
|
212
|
+
};
|
|
213
|
+
|
|
46
214
|
type Callbacks = Partial<{
|
|
47
215
|
handleHookPresent: ({
|
|
48
216
|
route,
|
|
@@ -209,7 +377,7 @@ export const useRunIfLongPress = (
|
|
|
209
377
|
React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
210
378
|
|
|
211
379
|
const resetTimeout = () => {
|
|
212
|
-
clearTimeout(pressTimeout.current);
|
|
380
|
+
clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
|
|
213
381
|
};
|
|
214
382
|
|
|
215
383
|
const startTimeout = (cb: () => void) => {
|
|
@@ -231,82 +399,12 @@ export const useRunIfLongPress = (
|
|
|
231
399
|
* @returns boolean - navbar visiblity status
|
|
232
400
|
*/
|
|
233
401
|
export const useIsNavBarVisible = (): boolean => {
|
|
234
|
-
const visible = useNavbarState()
|
|
402
|
+
const { visible } = useNavbarState();
|
|
235
403
|
|
|
236
404
|
return useMemo(() => visible, [visible]);
|
|
237
405
|
};
|
|
238
406
|
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
const isVideoModalPathname = (pathname: string) =>
|
|
242
|
-
/^video-modal\//.test(pathname);
|
|
243
|
-
|
|
244
|
-
const isHookModalPathname = (pathname: string) =>
|
|
245
|
-
/^hooks-modal\//.test(pathname);
|
|
246
|
-
|
|
247
|
-
export const useRoute = () => {
|
|
248
|
-
const pathname = usePathname() || "";
|
|
249
|
-
const navigator = useNavigation();
|
|
250
|
-
|
|
251
|
-
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
252
|
-
"plugins",
|
|
253
|
-
"rivers",
|
|
254
|
-
"contentTypes",
|
|
255
|
-
]);
|
|
256
|
-
|
|
257
|
-
const currentStack = navigator.getStackForPathname(pathname);
|
|
258
|
-
const modalState = navigator.modalState;
|
|
259
|
-
const hookModalState = useZappHooksModalState();
|
|
260
|
-
|
|
261
|
-
const modalScreenData = modalState.screen;
|
|
262
|
-
|
|
263
|
-
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
264
|
-
|
|
265
|
-
const videoModalScreenData =
|
|
266
|
-
navigator.videoModalState?.item &&
|
|
267
|
-
legacyScreenData(
|
|
268
|
-
{
|
|
269
|
-
entry: navigator.videoModalState?.item,
|
|
270
|
-
screen: getTargetScreenData(
|
|
271
|
-
navigator.videoModalState?.item,
|
|
272
|
-
rivers,
|
|
273
|
-
contentTypes
|
|
274
|
-
),
|
|
275
|
-
},
|
|
276
|
-
plugins
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
const currentRouteScreenData = legacyScreenData(
|
|
280
|
-
{
|
|
281
|
-
screen:
|
|
282
|
-
currentStack?.state?.screen ??
|
|
283
|
-
navigator.data?.screen ??
|
|
284
|
-
({} as ZappRiver),
|
|
285
|
-
entry: currentStack?.state?.entry ?? ({} as ZappEntry),
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
plugins
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
// There are 4 route scenarios
|
|
292
|
-
// For regular screens take date from navigator stack.
|
|
293
|
-
// is path is model grab screenData from modal state
|
|
294
|
-
// if path is video modal grab screenData from video state
|
|
295
|
-
// if path is hook modal grab screenData from hook state
|
|
296
|
-
|
|
297
|
-
const screenData = isModalPathname(pathname)
|
|
298
|
-
? modalScreenData
|
|
299
|
-
: isVideoModalPathname(pathname)
|
|
300
|
-
? videoModalScreenData
|
|
301
|
-
: isHookModalPathname(pathname)
|
|
302
|
-
? hookModalScreenData
|
|
303
|
-
: currentRouteScreenData;
|
|
304
|
-
|
|
305
|
-
return { screenData, pathname };
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
export const useGetBottomTabBarHeight = (): number => {
|
|
309
|
-
const insets = useSafeAreaInsets();
|
|
407
|
+
const useGetNavBarTopBorderWidth = (): number => {
|
|
310
408
|
const navigator = useNavigation();
|
|
311
409
|
|
|
312
410
|
const navProps = getNavigationProps({
|
|
@@ -315,18 +413,38 @@ export const useGetBottomTabBarHeight = (): number => {
|
|
|
315
413
|
category: "menu",
|
|
316
414
|
});
|
|
317
415
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const TAB_BAR_HEIGHT_IOS = 49;
|
|
322
|
-
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
416
|
+
return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
|
|
417
|
+
};
|
|
323
418
|
|
|
324
|
-
|
|
419
|
+
const TAB_BAR_HEIGHT_IOS = 49;
|
|
420
|
+
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
325
421
|
|
|
326
|
-
|
|
327
|
-
|
|
422
|
+
const useGetTabBarHeight = () =>
|
|
423
|
+
platformSelect({
|
|
424
|
+
ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
|
|
328
425
|
android: TAB_BAR_HEIGHT_ANDROID,
|
|
329
426
|
}) as number;
|
|
330
427
|
|
|
331
|
-
|
|
428
|
+
export const useGetBottomTabBarHeight = (): number => {
|
|
429
|
+
const topBorderWidth = useGetNavBarTopBorderWidth();
|
|
430
|
+
const tabBarHeight = useGetTabBarHeight();
|
|
431
|
+
|
|
432
|
+
const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
|
|
433
|
+
|
|
434
|
+
return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// If current screen is active/focused (visible to the user)
|
|
438
|
+
export const useIsScreenActive = () => {
|
|
439
|
+
const pathname = usePathname();
|
|
440
|
+
const { currentRoute, videoModalState } = useNavigation();
|
|
441
|
+
|
|
442
|
+
if (
|
|
443
|
+
videoModalState.visible &&
|
|
444
|
+
["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
|
|
445
|
+
) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return pathname === currentRoute;
|
|
332
450
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import {
|
|
3
|
+
import { cleanup, renderHook } from "@testing-library/react-hooks";
|
|
4
4
|
import configureStore from "redux-mock-store";
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
|
|
@@ -12,6 +12,8 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
|
|
|
12
12
|
useIsRTL: jest.fn(() => mock_rtl_flag),
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
|
|
16
|
+
|
|
15
17
|
const { useCellResolver } = require("../useCellResolver");
|
|
16
18
|
|
|
17
19
|
describe("cellResolver", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
|
|
4
|
-
const mockData
|
|
4
|
+
const mockData = {
|
|
5
5
|
screen: {
|
|
6
6
|
id: "screen-id",
|
|
7
7
|
name: "screen",
|
|
@@ -40,3 +40,5 @@ const mockData: NavigationScreenData = {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export const useScreenContext = jest.fn().mockReturnValue(mockData);
|
|
43
|
+
|
|
44
|
+
export const useNavbarState = () => ({ visible: true });
|
|
@@ -2,11 +2,12 @@ import { useContext, useMemo } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useModalNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext";
|
|
4
4
|
import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
|
|
5
|
-
import { useNavigation } from "../navigation";
|
|
5
|
+
import { useNavigation } from "../navigation/useNavigation";
|
|
6
6
|
|
|
7
7
|
import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
|
|
8
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
8
9
|
|
|
9
|
-
function useScreenContextV2() {
|
|
10
|
+
export function useScreenContextV2() {
|
|
10
11
|
return useContext(ScreenContext);
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -44,9 +45,9 @@ export function useSetNavbarState() {
|
|
|
44
45
|
|
|
45
46
|
export function useScreenContext(): NavigationScreenData {
|
|
46
47
|
const navigator = useNavigation();
|
|
48
|
+
// Cover cases where screenContext is used before navigation is initialized
|
|
49
|
+
const screenData = useContext(ScreenDataContext) || navigator.data;
|
|
47
50
|
|
|
48
|
-
const screenKey = useMemo(() => navigator?.key, [navigator]);
|
|
49
|
-
const screenData = useMemo(() => navigator?.data, [screenKey]);
|
|
50
51
|
const modalScreenData = navigator?.modalData;
|
|
51
52
|
|
|
52
53
|
const isModal = useModalNavigationContext();
|
|
@@ -4,7 +4,7 @@ import { useRivers } from "../state";
|
|
|
4
4
|
|
|
5
5
|
const logger = utilsLogger.addSubsystem("useScreenData");
|
|
6
6
|
|
|
7
|
-
export const useScreenData = (screenId
|
|
7
|
+
export const useScreenData = (screenId: string): ZappRiver => {
|
|
8
8
|
const rivers = useRivers();
|
|
9
9
|
|
|
10
10
|
React.useEffect(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
3
3
|
import * as R from "ramda";
|
|
4
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
4
5
|
|
|
5
6
|
export function getTargetScreenData(
|
|
6
7
|
entry: ZappEntry,
|
|
@@ -35,6 +36,12 @@ export function getTargetScreenData(
|
|
|
35
36
|
return rivers?.[screenId];
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
export function getTargetScreenDataFromEntry(entry: ZappEntry): ZappRiver {
|
|
40
|
+
const { rivers, contentTypes } = appStore.get(["rivers", "contentTypes"]);
|
|
41
|
+
|
|
42
|
+
return getTargetScreenData(entry, rivers, contentTypes);
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
export const useTargetScreenData = (entry: ZappEntry) => {
|
|
39
46
|
const { rivers, contentTypes } = usePickFromState(["rivers", "contentTypes"]);
|
|
40
47
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
2
2
|
|
|
3
|
+
const riversSelector = ["rivers"];
|
|
4
|
+
|
|
3
5
|
export const useRivers = () => {
|
|
4
|
-
const { rivers } = usePickFromState(
|
|
6
|
+
const { rivers } = usePickFromState(riversSelector as any);
|
|
5
7
|
|
|
6
8
|
return rivers;
|
|
7
9
|
};
|
|
@@ -13,10 +13,7 @@ export const useListenEventBusEvent = (
|
|
|
13
13
|
// TODO: remove after implementing ReactNativeEventBusBridge on iOS
|
|
14
14
|
if (Platform.OS === "android") {
|
|
15
15
|
// subscribe to DeviceEventEmitter using subsciption ID
|
|
16
|
-
const sub = DeviceEventEmitter.addListener(
|
|
17
|
-
subscriptionID,
|
|
18
|
-
handler
|
|
19
|
-
);
|
|
16
|
+
const sub = DeviceEventEmitter.addListener(subscriptionID, handler);
|
|
20
17
|
|
|
21
18
|
// ask native to start routing these events to RN
|
|
22
19
|
ReactNativeEventBusBridge.subscribe(subscriptionID, { [source]: events });
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
usePickFromState,
|
|
4
|
-
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
3
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
4
|
+
import { useRivers } from "../../state";
|
|
6
5
|
|
|
7
6
|
export const useVideoModalScreenData = ():
|
|
8
7
|
| (ZappEntry & { targetScreen: any }) // TODO: fix ZappEntry type ( was ZappRiver but conflict )
|
|
@@ -12,11 +11,13 @@ export const useVideoModalScreenData = ():
|
|
|
12
11
|
} = useNavigation();
|
|
13
12
|
|
|
14
13
|
const contentTypes = useContentTypes();
|
|
15
|
-
const
|
|
14
|
+
const rivers = useRivers();
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return React.useMemo(() => {
|
|
17
|
+
if (item?.type?.value) {
|
|
18
|
+
const screenId = contentTypes[item?.type?.value].screen_id;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
return { ...item, targetScreen: rivers?.[screenId] };
|
|
21
|
+
}
|
|
22
|
+
}, [item]);
|
|
22
23
|
};
|
|
@@ -3,7 +3,7 @@ import { NativeModules, StyleSheet, View } from "react-native";
|
|
|
3
3
|
import { getXray } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
4
|
|
|
5
5
|
import { isApplePlatform, isWeb } from "../reactUtils";
|
|
6
|
-
import {
|
|
6
|
+
import { useRivers } from "../reactHooks/state";
|
|
7
7
|
|
|
8
8
|
const layoutReducer = (state, { payload }) => {
|
|
9
9
|
return state.map((item, index, _state) => ({
|
|
@@ -58,7 +58,7 @@ export const ScreenLoadingMeasurements = ({
|
|
|
58
58
|
numberOfComponents,
|
|
59
59
|
riverId,
|
|
60
60
|
}: Props) => {
|
|
61
|
-
const
|
|
61
|
+
const rivers = useRivers();
|
|
62
62
|
const screenData = rivers?.[riverId];
|
|
63
63
|
|
|
64
64
|
const [itemsLayout, dispatchItemLayout] = React.useReducer(
|
package/stringUtils/index.ts
CHANGED
|
@@ -152,3 +152,8 @@ export function objectToCamelCase(obj) {
|
|
|
152
152
|
export function isString(value: unknown): value is string {
|
|
153
153
|
return typeof value === "string" || value instanceof String;
|
|
154
154
|
}
|
|
155
|
+
|
|
156
|
+
/** Checks if a value is a non-empty string */
|
|
157
|
+
export function isNotEmptyString(value: unknown): value is string {
|
|
158
|
+
return isString(value) && value.length > 0;
|
|
159
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const getByTestId = (wrapper, testId) => {
|
|
2
|
+
try {
|
|
3
|
+
if (wrapper?.getByTestId) {
|
|
4
|
+
return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
|
|
5
|
+
} else if (wrapper?.root?.findByProps) {
|
|
6
|
+
return wrapper.root.findAllByProps({ testID: testId })?.[0] ?? undefined;
|
|
7
|
+
}
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
console.log("getByTestId E:", e);
|
|
11
|
+
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
package/testUtils/index.tsx
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { PropsWithChildren } from "react";
|
|
4
4
|
import { View } from "react-native";
|
|
5
5
|
|
|
6
6
|
import { Provider } from "react-redux";
|
|
7
7
|
import thunk from "redux-thunk";
|
|
8
8
|
import configureStore from "redux-mock-store";
|
|
9
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
9
10
|
|
|
10
11
|
import { render } from "@testing-library/react-native";
|
|
12
|
+
import { AnalyticsProvider } from "../analyticsUtils";
|
|
13
|
+
|
|
14
|
+
export { getByTestId } from "./getByTestId";
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
|
|
@@ -19,17 +23,6 @@ import { render } from "@testing-library/react-native";
|
|
|
19
23
|
export const testIDEquals = (testId: any): boolean =>
|
|
20
24
|
R.compose(R.equals(testId), R.invoker(1, "prop")("testID"));
|
|
21
25
|
|
|
22
|
-
export const getByTestId = (wrapper, testId) => {
|
|
23
|
-
try {
|
|
24
|
-
return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.log("getByTestId E:", e);
|
|
28
|
-
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
26
|
/** Helper function for react-test-renderer, accepts type and renderer
|
|
34
27
|
* * @param {*} type React Component type instance or name of component
|
|
35
28
|
* * @param {*} renderer renderer instance
|
|
@@ -45,11 +38,11 @@ export const findByType = (type, renderer) => {
|
|
|
45
38
|
export function createComponentMock(mockName, hasChildren = false) {
|
|
46
39
|
return hasChildren
|
|
47
40
|
? jest.fn(({ children }) => (
|
|
48
|
-
<View
|
|
41
|
+
<View testID={mockName}>
|
|
49
42
|
{typeof children === "function" ? children() : children}
|
|
50
43
|
</View>
|
|
51
44
|
))
|
|
52
|
-
: jest.fn(() => <View
|
|
45
|
+
: jest.fn(() => <View testID={mockName} />);
|
|
53
46
|
}
|
|
54
47
|
|
|
55
48
|
const initialState = {
|
|
@@ -62,16 +55,34 @@ const initialState = {
|
|
|
62
55
|
AppContainer: createComponentMock("appContainer", true),
|
|
63
56
|
DisplayError: createComponentMock("displayError"),
|
|
64
57
|
},
|
|
65
|
-
rivers:
|
|
58
|
+
rivers: { id: "A1234", home: true },
|
|
66
59
|
appSettings: {},
|
|
67
60
|
plugins: [],
|
|
68
|
-
appState: { appReady: true },
|
|
61
|
+
appState: { appReady: true, appLaunched: true },
|
|
62
|
+
appData: { layoutVersion: "v1" },
|
|
63
|
+
contentTypes: null,
|
|
69
64
|
};
|
|
70
65
|
|
|
71
|
-
export const WrappedWithProviders = ({
|
|
72
|
-
|
|
66
|
+
export const WrappedWithProviders = ({
|
|
67
|
+
children,
|
|
68
|
+
store: storeObj = {},
|
|
69
|
+
}: any) => {
|
|
70
|
+
const _store = configureStore([thunk])(
|
|
71
|
+
R.mergeDeepWith(R.concat, { ...initialState }, storeObj)
|
|
72
|
+
);
|
|
73
73
|
|
|
74
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
<SafeAreaProvider
|
|
76
|
+
initialMetrics={{
|
|
77
|
+
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
|
78
|
+
frame: { x: 0, y: 0, width: 0, height: 0 },
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<Provider store={_store}>
|
|
82
|
+
<AnalyticsProvider>{children}</AnalyticsProvider>
|
|
83
|
+
</Provider>
|
|
84
|
+
</SafeAreaProvider>
|
|
85
|
+
);
|
|
75
86
|
};
|
|
76
87
|
|
|
77
88
|
/**
|
|
@@ -80,8 +91,12 @@ export const WrappedWithProviders = ({ children, store = {} }: any) => {
|
|
|
80
91
|
* @param store optional store to pass to the provider
|
|
81
92
|
* @returns
|
|
82
93
|
*/
|
|
83
|
-
export const renderWithProviders = (component,
|
|
84
|
-
return render(
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
export const renderWithProviders = (component, storeObj?: unknown) => {
|
|
95
|
+
return render(component, {
|
|
96
|
+
wrapper: function TestWrapper({ children }: PropsWithChildren<any>) {
|
|
97
|
+
return (
|
|
98
|
+
<WrappedWithProviders store={storeObj}>{children}</WrappedWithProviders>
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
87
102
|
};
|