@applicaster/zapp-react-native-utils 12.0.0-alpha.4534459584 → 12.0.0-alpha.5040434238
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/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/helpers/hooks.ts +1 -1
- 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/orientationHelper.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/conts.ts +5 -0
- package/appUtils/playerManager/player.ts +46 -4
- package/appUtils/playerManager/playerFactory.ts +15 -1
- package/appUtils/playerManager/playerNative.ts +30 -0
- package/appUtils/playerManager/usePlayerState.tsx +13 -1
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/cellUtils/__tests__/cellUtils.test.ts +59 -0
- package/cellUtils/__tests__/fixtures.ts +13 -0
- package/cellUtils/index.ts +44 -2
- 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/localizationUtils/__tests__/localizationUtils.test.ts +17 -13
- package/localizationUtils/index.ts +6 -3
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- 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/package.json +3 -2
- package/playerUtils/configurationGenerator.ts +8 -0
- package/pluginUtils/index.ts +11 -7
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.ts +2 -0
- package/reactHooks/cell-click/__tests__/index.test.js +6 -2
- package/reactHooks/cell-click/index.ts +2 -2
- 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/flatList/useLoadNextPageIfNeeded.ts +16 -9
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/index.test.js +23 -30
- package/reactHooks/layout/getDeviceInfo/index.ts +2 -1
- 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 +8 -5
- package/reactHooks/navigation/__mocks__/index.ts +2 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +4 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +234 -78
- package/reactHooks/navigation/index.ts +217 -85
- 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 +1 -1
- 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/screenState/index.ts +8 -0
- package/testUtils/index.tsx +15 -2
- package/reactHooks/device/useIsTablet.android.tsx +0 -14
- package/reactHooks/device/useIsTablet.ios.tsx +0 -7
- package/reactHooks/device/useIsTablet.web.tsx +0 -3
|
@@ -17,18 +17,103 @@ 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";
|
|
29
34
|
|
|
30
35
|
export { useNavigation } from "./useNavigation";
|
|
31
36
|
|
|
37
|
+
/**
|
|
38
|
+
* This function helps to decide wether the navbar should be presented on the screen
|
|
39
|
+
* based on route and / or screen Data
|
|
40
|
+
*
|
|
41
|
+
* Currently the scenarios include
|
|
42
|
+
* - players => false
|
|
43
|
+
* - search screen plugin => false
|
|
44
|
+
* - hooks with `showNavBar: true` or `presentFullScreen` not set to true, defaults to no navbar for hook screens
|
|
45
|
+
* - screens with `allow_screen_plugin_presentation` in general property => false
|
|
46
|
+
*
|
|
47
|
+
* @param {String} route current route of the screen
|
|
48
|
+
* @param {Object} screenData payload associated with the currently presented screen
|
|
49
|
+
* @returns {Boolean}
|
|
50
|
+
*/
|
|
51
|
+
export function isNavBarVisible(
|
|
52
|
+
route: string,
|
|
53
|
+
screenData: ZappRiver = {} as ZappRiver,
|
|
54
|
+
showNavBar: boolean,
|
|
55
|
+
canGoBack: boolean,
|
|
56
|
+
videoModalState: QuickBrickVideoModalState | null = null
|
|
57
|
+
) {
|
|
58
|
+
/* screenData is not actual navigator.data
|
|
59
|
+
* or navigator.screenData,
|
|
60
|
+
* but navigator.data.screen */
|
|
61
|
+
if (route.includes("playable")) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
videoModalState?.mode === "FULLSCREEN" &&
|
|
67
|
+
videoModalState?.visible === true
|
|
68
|
+
) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (screenData?.type === "qb_search_screen" && !isTV()) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Match if screen is Hook */
|
|
77
|
+
if (route.startsWith("/hooks/")) {
|
|
78
|
+
const module = screenData?.module;
|
|
79
|
+
|
|
80
|
+
if (module?.presentFullScreen) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return module?.showNavBar ?? false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (screenData?.hookPlugin) {
|
|
88
|
+
const hookPlugin = screenData?.hookPlugin?.module;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (
|
|
96
|
+
screenData?.general?.allow_screen_plugin_presentation ||
|
|
97
|
+
screenData?.general?.hide_app_nav_bar
|
|
98
|
+
) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const hideSecondaryLevel = screenData?.navigations?.some(
|
|
103
|
+
(navigation) => navigation.styles?.hide_secondary_level_menu
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (canGoBack && hideSecondaryLevel) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (typeof showNavBar === "boolean" && !showNavBar) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
32
117
|
const { ProfilerBridge } = NativeModules;
|
|
33
118
|
|
|
34
119
|
export const usePathname = () => React.useContext(PathnameContext);
|
|
@@ -43,6 +128,103 @@ export const useBackHandler = (cb: () => boolean) => {
|
|
|
43
128
|
}, [cb]);
|
|
44
129
|
};
|
|
45
130
|
|
|
131
|
+
// starts with modal/
|
|
132
|
+
const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
|
|
133
|
+
|
|
134
|
+
const isVideoModalPathname = (pathname: string) =>
|
|
135
|
+
/^video-modal\//.test(pathname);
|
|
136
|
+
|
|
137
|
+
const isHookModalPathname = (pathname: string) =>
|
|
138
|
+
/^hooks-modal\//.test(pathname);
|
|
139
|
+
|
|
140
|
+
const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
141
|
+
|
|
142
|
+
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
143
|
+
|
|
144
|
+
export const useRoute = (): {
|
|
145
|
+
screenData: VariousScreenData;
|
|
146
|
+
pathname: string;
|
|
147
|
+
} => {
|
|
148
|
+
const pathname = usePathname() || "";
|
|
149
|
+
const navigator = useNavigation();
|
|
150
|
+
|
|
151
|
+
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
152
|
+
"plugins",
|
|
153
|
+
"rivers",
|
|
154
|
+
"contentTypes",
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
const currentStack = navigator.getStackForPathname(pathname);
|
|
158
|
+
const { modalState } = useModalStore();
|
|
159
|
+
const hookModalState = useZappHooksModalState();
|
|
160
|
+
|
|
161
|
+
const modalScreenData = modalState.screen;
|
|
162
|
+
|
|
163
|
+
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
164
|
+
|
|
165
|
+
const videoModalScreenData =
|
|
166
|
+
navigator.videoModalState?.item &&
|
|
167
|
+
legacyScreenData(
|
|
168
|
+
{
|
|
169
|
+
entry: navigator.videoModalState?.item as ZappEntry,
|
|
170
|
+
screen: getTargetScreenData(
|
|
171
|
+
navigator.videoModalState?.item as ZappEntry,
|
|
172
|
+
rivers,
|
|
173
|
+
contentTypes
|
|
174
|
+
),
|
|
175
|
+
},
|
|
176
|
+
plugins
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const currentRouteScreenData = legacyScreenData(
|
|
180
|
+
{
|
|
181
|
+
screen: currentStack?.state?.screen ?? navigator.data?.screen ?? {},
|
|
182
|
+
entry: currentStack?.state?.entry ?? {},
|
|
183
|
+
} as NavigationScreenData,
|
|
184
|
+
|
|
185
|
+
plugins
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// There are 4 route scenarios
|
|
189
|
+
// For regular screens take date from navigator stack.
|
|
190
|
+
// is path is model grab screenData from modal state
|
|
191
|
+
// if path is video modal grab screenData from video state
|
|
192
|
+
// if path is hook modal grab screenData from hook state
|
|
193
|
+
// if path is hook grab screenData from screenData
|
|
194
|
+
|
|
195
|
+
if (isModalPathname(pathname)) {
|
|
196
|
+
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
197
|
+
|
|
198
|
+
return { screenData, pathname };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (isVideoModalPathname(pathname)) {
|
|
202
|
+
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
203
|
+
|
|
204
|
+
return { screenData, pathname };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (isHookModalPathname(pathname)) {
|
|
208
|
+
const screenData = hookModalScreenData;
|
|
209
|
+
|
|
210
|
+
return { screenData, pathname };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (isHookPathname(pathname)) {
|
|
214
|
+
const screenData =
|
|
215
|
+
"hookPlugin" in currentRouteScreenData &&
|
|
216
|
+
currentRouteScreenData.hookPlugin.screen_id
|
|
217
|
+
? currentRouteScreenData
|
|
218
|
+
: navigator.screenData;
|
|
219
|
+
|
|
220
|
+
return { screenData, pathname };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const screenData = currentRouteScreenData;
|
|
224
|
+
|
|
225
|
+
return { screenData, pathname };
|
|
226
|
+
};
|
|
227
|
+
|
|
46
228
|
type Callbacks = Partial<{
|
|
47
229
|
handleHookPresent: ({
|
|
48
230
|
route,
|
|
@@ -209,7 +391,7 @@ export const useRunIfLongPress = (
|
|
|
209
391
|
React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
|
|
210
392
|
|
|
211
393
|
const resetTimeout = () => {
|
|
212
|
-
clearTimeout(pressTimeout.current);
|
|
394
|
+
clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
|
|
213
395
|
};
|
|
214
396
|
|
|
215
397
|
const startTimeout = (cb: () => void) => {
|
|
@@ -231,82 +413,12 @@ export const useRunIfLongPress = (
|
|
|
231
413
|
* @returns boolean - navbar visiblity status
|
|
232
414
|
*/
|
|
233
415
|
export const useIsNavBarVisible = (): boolean => {
|
|
234
|
-
const visible = useNavbarState()
|
|
416
|
+
const { visible } = useNavbarState();
|
|
235
417
|
|
|
236
418
|
return useMemo(() => visible, [visible]);
|
|
237
419
|
};
|
|
238
420
|
|
|
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();
|
|
421
|
+
const useGetNavBarTopBorderWidth = (): number => {
|
|
310
422
|
const navigator = useNavigation();
|
|
311
423
|
|
|
312
424
|
const navProps = getNavigationProps({
|
|
@@ -315,18 +427,38 @@ export const useGetBottomTabBarHeight = (): number => {
|
|
|
315
427
|
category: "menu",
|
|
316
428
|
});
|
|
317
429
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const TAB_BAR_HEIGHT_IOS = 49;
|
|
322
|
-
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
430
|
+
return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
|
|
431
|
+
};
|
|
323
432
|
|
|
324
|
-
|
|
433
|
+
const TAB_BAR_HEIGHT_IOS = 49;
|
|
434
|
+
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
325
435
|
|
|
326
|
-
|
|
327
|
-
|
|
436
|
+
const useGetTabBarHeight = () =>
|
|
437
|
+
platformSelect({
|
|
438
|
+
ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
|
|
328
439
|
android: TAB_BAR_HEIGHT_ANDROID,
|
|
329
440
|
}) as number;
|
|
330
441
|
|
|
331
|
-
|
|
442
|
+
export const useGetBottomTabBarHeight = (): number => {
|
|
443
|
+
const topBorderWidth = useGetNavBarTopBorderWidth();
|
|
444
|
+
const tabBarHeight = useGetTabBarHeight();
|
|
445
|
+
|
|
446
|
+
const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
|
|
447
|
+
|
|
448
|
+
return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// If current screen is active/focused (visible to the user)
|
|
452
|
+
export const useIsScreenActive = () => {
|
|
453
|
+
const pathname = usePathname();
|
|
454
|
+
const { currentRoute, videoModalState } = useNavigation();
|
|
455
|
+
|
|
456
|
+
if (
|
|
457
|
+
videoModalState.visible &&
|
|
458
|
+
["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
|
|
459
|
+
) {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return pathname === currentRoute;
|
|
332
464
|
};
|
|
@@ -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,7 +2,7 @@ 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
8
|
|
|
@@ -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/screenState/index.ts
CHANGED
|
@@ -49,3 +49,11 @@ export function useScreenState(
|
|
|
49
49
|
setSelectedEntry: (entryId) => setSelectedEntry(screenId, entryId),
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
export const useScreenScrollStore = create<{
|
|
54
|
+
scrollPosition: number;
|
|
55
|
+
scrollingVelocity: number;
|
|
56
|
+
}>(() => ({
|
|
57
|
+
scrollPosition: 0,
|
|
58
|
+
scrollingVelocity: 0,
|
|
59
|
+
}));
|
package/testUtils/index.tsx
CHANGED
|
@@ -6,8 +6,10 @@ import { View } from "react-native";
|
|
|
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";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
|
|
@@ -69,9 +71,20 @@ const initialState = {
|
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
export const WrappedWithProviders = ({ children, store = {} }: any) => {
|
|
72
|
-
const _store = configureStore([thunk])({ ...initialState, store });
|
|
74
|
+
const _store = configureStore([thunk])({ ...initialState, ...store });
|
|
73
75
|
|
|
74
|
-
return
|
|
76
|
+
return (
|
|
77
|
+
<SafeAreaProvider
|
|
78
|
+
initialMetrics={{
|
|
79
|
+
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
|
80
|
+
frame: { x: 0, y: 0, width: 0, height: 0 },
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
<Provider store={_store}>
|
|
84
|
+
<AnalyticsProvider>{children}</AnalyticsProvider>
|
|
85
|
+
</Provider>
|
|
86
|
+
</SafeAreaProvider>
|
|
87
|
+
);
|
|
75
88
|
};
|
|
76
89
|
|
|
77
90
|
/**
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useWindowDimensions } from "react-native";
|
|
2
|
-
import { useOrientation } from "./useOrientation";
|
|
3
|
-
import { isTablet } from "../layout";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Determines weather the given device is a tablet based on dimensions, orientation, and platform
|
|
7
|
-
* @returns {Boolean} isTablet - returns whether the given device is a tablet
|
|
8
|
-
*/
|
|
9
|
-
export const useIsTablet = (): boolean => {
|
|
10
|
-
const dimensions = useWindowDimensions();
|
|
11
|
-
const orientation = useOrientation();
|
|
12
|
-
|
|
13
|
-
return isTablet(dimensions, orientation);
|
|
14
|
-
};
|