@applicaster/zapp-react-native-utils 12.0.0-rc.8 → 12.0.0-rc.80
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 +13 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
- package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/analyticsPlugins.ts +25 -0
- package/analyticsUtils/events.ts +12 -0
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/analyticsUtils/index.tsx +12 -0
- package/appUtils/HooksManager/index.js +3 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
- package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
- package/appUtils/focusManager/__tests__/index.test.ts +2 -3
- package/appUtils/focusManager/index.ts +76 -56
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +74 -34
- package/appUtils/focusManager/utils/index.ts +100 -0
- package/appUtils/focusManagerAux/index.ts +76 -0
- package/appUtils/focusManagerAux/utils/index.ts +100 -0
- 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 +9 -0
- package/appUtils/keyCodes/keysByPlatform.js +11 -1
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/platform/const.ts +25 -0
- package/appUtils/platform/index.ts +3 -0
- package/appUtils/platform/platformUtils.ts +223 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/conts.ts +5 -0
- package/appUtils/playerManager/index.ts +11 -5
- package/appUtils/playerManager/nativePlayerManager.ts +12 -0
- package/appUtils/playerManager/player.ts +47 -7
- package/appUtils/playerManager/playerFactory.ts +15 -1
- package/appUtils/playerManager/playerNative.ts +40 -14
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
- package/appUtils/playerManager/usePlayerState.tsx +13 -1
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
- package/arrayUtils/index.ts +5 -0
- package/booleanUtils/index.ts +4 -4
- 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/keyboardState/index.ts +0 -0
- 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/__tests__/isLikeNumber.test.ts +18 -0
- package/numberUtils/index.ts +9 -18
- 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 +16 -3
- package/reactHooks/cell-click/index.ts +14 -14
- package/reactHooks/device/index.ts +0 -1
- package/reactHooks/device/useIsTablet.tsx +28 -3
- package/reactHooks/device/useMemoizedIsTablet.ts +1 -1
- package/reactHooks/device/useOrientation.tsx +3 -1
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
- package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
- package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
- package/reactHooks/feed/useFeedRefresh.tsx +9 -7
- 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/index.ts +2 -1
- 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 +235 -80
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
- package/reactHooks/screen/index.ts +4 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
- package/reactHooks/screen/useScreenContext.ts +4 -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/reactUtils/index.ts +102 -0
- 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
- package/reactHooks/device/useIsTablet.android.tsx +0 -14
- package/reactHooks/device/useIsTablet.ios.tsx +0 -7
- package/reactHooks/device/useIsTablet.web.tsx +0 -3
|
@@ -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
|
|
|
@@ -12,23 +12,113 @@ import {
|
|
|
12
12
|
import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
|
|
13
13
|
|
|
14
14
|
import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
LONG_KEY_PRESS_TIMEOUT,
|
|
17
|
+
QUICK_BRICK_NAVBAR,
|
|
18
|
+
QUICK_BRICK_CONTENT,
|
|
19
|
+
} from "@applicaster/quick-brick-core/const";
|
|
16
20
|
import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/ZappHooksModal";
|
|
17
21
|
import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
18
22
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
19
23
|
import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
|
|
20
|
-
import { getNavigationProps } from "@applicaster/zapp-react-native-utils/navigationUtils";
|
|
21
24
|
import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
|
|
22
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
getNavigationProps,
|
|
27
|
+
getRiverFromRoute,
|
|
28
|
+
getTargetRoute,
|
|
29
|
+
} from "../../navigationUtils";
|
|
23
30
|
import { platformSelect } from "../../reactUtils";
|
|
24
31
|
import { useConnectionInfo } from "../connection";
|
|
25
32
|
import { getTargetScreenData } from "../screen/useTargetScreenData";
|
|
26
|
-
import { useNavbarState } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
|
|
27
33
|
|
|
34
|
+
import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
35
|
+
import { useNavbarState } from "../screen";
|
|
28
36
|
import { useNavigation } from "./useNavigation";
|
|
37
|
+
import { useModalStore } from "../../modalState";
|
|
38
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
29
39
|
|
|
30
40
|
export { useNavigation } from "./useNavigation";
|
|
31
41
|
|
|
42
|
+
/**
|
|
43
|
+
* This function helps to decide wether the navbar should be presented on the screen
|
|
44
|
+
* based on route and / or screen Data
|
|
45
|
+
*
|
|
46
|
+
* Currently the scenarios include
|
|
47
|
+
* - players => false
|
|
48
|
+
* - search screen plugin => false
|
|
49
|
+
* - hooks with `showNavBar: true` or `presentFullScreen` not set to true, defaults to no navbar for hook screens
|
|
50
|
+
* - screens with `allow_screen_plugin_presentation` in general property => false
|
|
51
|
+
*
|
|
52
|
+
* @param {String} route current route of the screen
|
|
53
|
+
* @param {Object} screenData payload associated with the currently presented screen
|
|
54
|
+
* @returns {Boolean}
|
|
55
|
+
*/
|
|
56
|
+
export function isNavBarVisible(
|
|
57
|
+
route: string,
|
|
58
|
+
screenData: ZappRiver = {} as ZappRiver,
|
|
59
|
+
showNavBar: boolean,
|
|
60
|
+
canGoBack: boolean,
|
|
61
|
+
videoModalState: QuickBrickVideoModalState | null = null
|
|
62
|
+
) {
|
|
63
|
+
/* screenData is not actual navigator.data
|
|
64
|
+
* or navigator.screenData,
|
|
65
|
+
* but navigator.data.screen */
|
|
66
|
+
if (route.includes("playable")) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
videoModalState?.mode === "FULLSCREEN" &&
|
|
72
|
+
videoModalState?.visible === true
|
|
73
|
+
) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (screenData?.type === "qb_search_screen" && !isTV()) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* Match if screen is Hook */
|
|
82
|
+
if (route.startsWith("/hooks/")) {
|
|
83
|
+
const module = screenData?.module;
|
|
84
|
+
|
|
85
|
+
if (module?.presentFullScreen) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return module?.showNavBar ?? false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (screenData?.hookPlugin) {
|
|
93
|
+
const hookPlugin = screenData?.hookPlugin?.module;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
screenData?.general?.allow_screen_plugin_presentation ||
|
|
102
|
+
screenData?.general?.hide_app_nav_bar
|
|
103
|
+
) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const hideSecondaryLevel = screenData?.navigations?.some(
|
|
108
|
+
(navigation) => navigation.styles?.hide_secondary_level_menu
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (canGoBack && hideSecondaryLevel) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (typeof showNavBar === "boolean" && !showNavBar) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
32
122
|
const { ProfilerBridge } = NativeModules;
|
|
33
123
|
|
|
34
124
|
export const usePathname = () => React.useContext(PathnameContext);
|
|
@@ -43,6 +133,88 @@ export const useBackHandler = (cb: () => boolean) => {
|
|
|
43
133
|
}, [cb]);
|
|
44
134
|
};
|
|
45
135
|
|
|
136
|
+
// starts with modal/
|
|
137
|
+
const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
|
|
138
|
+
|
|
139
|
+
const isVideoModalPathname = (pathname: string) =>
|
|
140
|
+
/^video-modal\//.test(pathname);
|
|
141
|
+
|
|
142
|
+
const isHookModalPathname = (pathname: string) =>
|
|
143
|
+
/^hooks-modal\//.test(pathname);
|
|
144
|
+
|
|
145
|
+
const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
146
|
+
|
|
147
|
+
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
148
|
+
|
|
149
|
+
export const useRoute = (): {
|
|
150
|
+
screenData: VariousScreenData;
|
|
151
|
+
pathname: string;
|
|
152
|
+
} => {
|
|
153
|
+
const pathname = usePathname() || "";
|
|
154
|
+
const navigator = useNavigation();
|
|
155
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
156
|
+
|
|
157
|
+
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
158
|
+
"plugins",
|
|
159
|
+
"rivers",
|
|
160
|
+
"contentTypes",
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
const { modalState } = useModalStore();
|
|
164
|
+
const hookModalState = useZappHooksModalState();
|
|
165
|
+
|
|
166
|
+
const modalScreenData = modalState.screen;
|
|
167
|
+
|
|
168
|
+
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
169
|
+
|
|
170
|
+
const videoModalScreenData =
|
|
171
|
+
navigator.videoModalState?.item &&
|
|
172
|
+
legacyScreenData(
|
|
173
|
+
{
|
|
174
|
+
entry: navigator.videoModalState?.item as ZappEntry,
|
|
175
|
+
screen: getTargetScreenData(
|
|
176
|
+
navigator.videoModalState?.item as ZappEntry,
|
|
177
|
+
rivers,
|
|
178
|
+
contentTypes
|
|
179
|
+
),
|
|
180
|
+
},
|
|
181
|
+
plugins
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// There are 4 route scenarios
|
|
185
|
+
// For regular screens take date from navigator stack.
|
|
186
|
+
// is path is model grab screenData from modal state
|
|
187
|
+
// if path is video modal grab screenData from video state
|
|
188
|
+
// if path is hook modal grab screenData from hook state
|
|
189
|
+
// if path is hook grab screenData from screenData
|
|
190
|
+
|
|
191
|
+
if (isModalPathname(pathname)) {
|
|
192
|
+
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
193
|
+
|
|
194
|
+
return { screenData, pathname };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (isVideoModalPathname(pathname)) {
|
|
198
|
+
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
199
|
+
|
|
200
|
+
return { screenData, pathname };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (isHookModalPathname(pathname)) {
|
|
204
|
+
const screenData = hookModalScreenData;
|
|
205
|
+
|
|
206
|
+
return { screenData, pathname };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (isHookPathname(pathname)) {
|
|
210
|
+
return { screenData: screenDataContext, pathname };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const screenData = screenDataContext;
|
|
214
|
+
|
|
215
|
+
return { screenData, pathname };
|
|
216
|
+
};
|
|
217
|
+
|
|
46
218
|
type Callbacks = Partial<{
|
|
47
219
|
handleHookPresent: ({
|
|
48
220
|
route,
|
|
@@ -209,7 +381,7 @@ export const useRunIfLongPress = (
|
|
|
209
381
|
React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
210
382
|
|
|
211
383
|
const resetTimeout = () => {
|
|
212
|
-
clearTimeout(pressTimeout.current);
|
|
384
|
+
clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
|
|
213
385
|
};
|
|
214
386
|
|
|
215
387
|
const startTimeout = (cb: () => void) => {
|
|
@@ -231,102 +403,85 @@ export const useRunIfLongPress = (
|
|
|
231
403
|
* @returns boolean - navbar visiblity status
|
|
232
404
|
*/
|
|
233
405
|
export const useIsNavBarVisible = (): boolean => {
|
|
234
|
-
const visible = useNavbarState()
|
|
406
|
+
const { visible } = useNavbarState();
|
|
235
407
|
|
|
236
408
|
return useMemo(() => visible, [visible]);
|
|
237
409
|
};
|
|
238
410
|
|
|
239
|
-
const
|
|
411
|
+
const useGetNavBarTopBorderWidth = (): number => {
|
|
412
|
+
const navigator = useNavigation();
|
|
240
413
|
|
|
241
|
-
const
|
|
242
|
-
|
|
414
|
+
const navProps = getNavigationProps({
|
|
415
|
+
navigator,
|
|
416
|
+
title: "",
|
|
417
|
+
category: "menu",
|
|
418
|
+
});
|
|
243
419
|
|
|
244
|
-
|
|
245
|
-
|
|
420
|
+
return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
|
|
421
|
+
};
|
|
246
422
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const navigator = useNavigation();
|
|
423
|
+
const TAB_BAR_HEIGHT_IOS = 49;
|
|
424
|
+
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
250
425
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
426
|
+
const useGetTabBarHeight = () =>
|
|
427
|
+
platformSelect({
|
|
428
|
+
ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
|
|
429
|
+
android: TAB_BAR_HEIGHT_ANDROID,
|
|
430
|
+
}) as number;
|
|
256
431
|
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
const
|
|
432
|
+
export const useGetBottomTabBarHeight = (): number => {
|
|
433
|
+
const topBorderWidth = useGetNavBarTopBorderWidth();
|
|
434
|
+
const tabBarHeight = useGetTabBarHeight();
|
|
260
435
|
|
|
261
|
-
const
|
|
436
|
+
const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
|
|
262
437
|
|
|
263
|
-
|
|
438
|
+
return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
|
|
439
|
+
};
|
|
264
440
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
entry: navigator.videoModalState?.item,
|
|
270
|
-
screen: getTargetScreenData(
|
|
271
|
-
navigator.videoModalState?.item,
|
|
272
|
-
rivers,
|
|
273
|
-
contentTypes
|
|
274
|
-
),
|
|
275
|
-
},
|
|
276
|
-
plugins
|
|
277
|
-
);
|
|
441
|
+
// If current screen is active/focused (visible to the user)
|
|
442
|
+
export const useIsScreenActive = () => {
|
|
443
|
+
const pathname = usePathname();
|
|
444
|
+
const { currentRoute, videoModalState } = useNavigation();
|
|
278
445
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
entry: currentStack?.state?.entry ?? ({} as ZappEntry),
|
|
286
|
-
},
|
|
446
|
+
if (
|
|
447
|
+
videoModalState.visible &&
|
|
448
|
+
["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
|
|
449
|
+
) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
287
452
|
|
|
288
|
-
|
|
289
|
-
|
|
453
|
+
return pathname === currentRoute;
|
|
454
|
+
};
|
|
290
455
|
|
|
291
|
-
|
|
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
|
|
456
|
+
type Return = (prefix: string) => string;
|
|
296
457
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
? videoModalScreenData
|
|
301
|
-
: isHookModalPathname(pathname)
|
|
302
|
-
? hookModalScreenData
|
|
303
|
-
: currentRouteScreenData;
|
|
458
|
+
export const useUniqueRouteSuffix = (): Return => {
|
|
459
|
+
const pathname = usePathname();
|
|
460
|
+
const { currentRoute } = useNavigation();
|
|
304
461
|
|
|
305
|
-
|
|
306
|
-
};
|
|
462
|
+
const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
|
|
307
463
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
464
|
+
const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
|
|
465
|
+
if (isWeb()) {
|
|
466
|
+
// we should use extended route prefix only on Web, where we have stack-navigator
|
|
467
|
+
return `${prefix}___${suffix}`;
|
|
468
|
+
}
|
|
311
469
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
category: "menu",
|
|
316
|
-
});
|
|
470
|
+
// for other platforms use previous version
|
|
471
|
+
return prefix;
|
|
472
|
+
}, []);
|
|
317
473
|
|
|
318
|
-
|
|
319
|
-
|
|
474
|
+
return withUniqueRouteSuffix;
|
|
475
|
+
};
|
|
320
476
|
|
|
321
|
-
|
|
322
|
-
const
|
|
477
|
+
export const useNavbarId = () => {
|
|
478
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
323
479
|
|
|
324
|
-
|
|
480
|
+
return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
|
|
481
|
+
};
|
|
325
482
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
android: TAB_BAR_HEIGHT_ANDROID,
|
|
329
|
-
}) as number;
|
|
483
|
+
export const useContentId = () => {
|
|
484
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
330
485
|
|
|
331
|
-
return
|
|
486
|
+
return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
|
|
332
487
|
};
|
|
@@ -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 });
|
|
@@ -3,23 +3,28 @@ import { Provider } from "react-redux";
|
|
|
3
3
|
import { renderHook } from "@testing-library/react-hooks";
|
|
4
4
|
import configureStore from "redux-mock-store";
|
|
5
5
|
import thunk from "redux-thunk";
|
|
6
|
-
import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
|
|
7
6
|
|
|
8
7
|
const mockStore = configureStore([thunk]);
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
const river_id_2: ZappRiver = {
|
|
10
|
+
name: "River 2",
|
|
11
|
+
id: "A1234",
|
|
12
|
+
home: false,
|
|
13
|
+
home_offline: false,
|
|
14
|
+
supports_offline: false,
|
|
15
|
+
navigations: [],
|
|
16
|
+
hooks: { preload_plugins: [] },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
jest.mock("../useScreenContext", () => ({
|
|
20
|
+
useScreenContext: () => ({
|
|
21
|
+
screen: river_id_2,
|
|
22
|
+
}),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const { useCurrentScreenData } = require("../useCurrentScreenData");
|
|
26
|
+
|
|
27
|
+
describe("useScreenData", () => {
|
|
23
28
|
const river_id_1 = { id: "B5678" };
|
|
24
29
|
|
|
25
30
|
const store = mockStore({
|
|
@@ -27,17 +32,10 @@ describe("useScreenData", function () {
|
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
const wrapper: React.FC<any> = ({ children }) => (
|
|
30
|
-
<
|
|
31
|
-
value={{
|
|
32
|
-
currentRoute: "/river/river_id_1/river/river_id_2",
|
|
33
|
-
data: { screen: river_id_2 },
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
<Provider store={store}>{children}</Provider>
|
|
37
|
-
</NavigationContext.Provider>
|
|
35
|
+
<Provider store={store}>{children}</Provider>
|
|
38
36
|
);
|
|
39
37
|
|
|
40
|
-
it("should return river data for the current screen/route",
|
|
38
|
+
it("should return river data for the current screen/route", () => {
|
|
41
39
|
const { result } = renderHook(() => useCurrentScreenData(), { wrapper });
|
|
42
40
|
|
|
43
41
|
expect(result.current).toBe(river_id_2);
|
|
@@ -2,9 +2,13 @@ export { useCurrentScreenData } from "./useCurrentScreenData";
|
|
|
2
2
|
|
|
3
3
|
export { useTargetScreenData } from "./useTargetScreenData";
|
|
4
4
|
|
|
5
|
+
export { useScreenData } from "./useScreenData";
|
|
6
|
+
|
|
5
7
|
export {
|
|
6
8
|
useScreenContext,
|
|
7
9
|
useLegacyScreenData,
|
|
8
10
|
useNavbarState,
|
|
9
11
|
useSetNavbarState,
|
|
10
12
|
} from "./useScreenContext";
|
|
13
|
+
|
|
14
|
+
export { useScreenBackgroundColor } from "./useScreenBackgroundColor";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
3
|
+
import { useScreenConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration";
|
|
4
|
+
import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
5
|
+
|
|
6
|
+
export const useScreenBackgroundColor = (screenId: string): string => {
|
|
7
|
+
const { backgroundColor: screenBackgroundColor } =
|
|
8
|
+
useScreenConfiguration(screenId);
|
|
9
|
+
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
|
|
12
|
+
const themeBackgroundColor = React.useMemo(
|
|
13
|
+
() => theme.app_background_color,
|
|
14
|
+
[theme.app_background_color]
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const backgroundColor = ifEmptyUseFallback(
|
|
18
|
+
screenBackgroundColor,
|
|
19
|
+
themeBackgroundColor
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return backgroundColor;
|
|
23
|
+
};
|
|
@@ -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,8 @@ export function useSetNavbarState() {
|
|
|
44
45
|
|
|
45
46
|
export function useScreenContext(): NavigationScreenData {
|
|
46
47
|
const navigator = useNavigation();
|
|
48
|
+
const screenData = useContext(ScreenDataContext);
|
|
47
49
|
|
|
48
|
-
const screenKey = useMemo(() => navigator?.key, [navigator]);
|
|
49
|
-
const screenData = useMemo(() => navigator?.data, [screenKey]);
|
|
50
50
|
const modalScreenData = navigator?.modalData;
|
|
51
51
|
|
|
52
52
|
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
|
};
|