@applicaster/zapp-react-native-utils 12.0.0-alpha.3977160850 → 12.0.0-alpha.4433422595

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.
Files changed (29) hide show
  1. package/appUtils/HooksManager/index.js +3 -1
  2. package/appUtils/focusManager/index.ts +21 -0
  3. package/appUtils/focusManager/treeDataStructure/Utils/index.js +59 -34
  4. package/appUtils/playerManager/conts.ts +5 -0
  5. package/appUtils/playerManager/player.ts +34 -0
  6. package/appUtils/playerManager/playerFactory.ts +12 -10
  7. package/appUtils/playerManager/playerNative.ts +4 -0
  8. package/cellUtils/index.ts +5 -3
  9. package/manifestUtils/index.js +5 -1
  10. package/manifestUtils/secondaryImage/index.js +18 -15
  11. package/navigationUtils/index.ts +8 -4
  12. package/package.json +2 -2
  13. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  14. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.ts +2 -0
  15. package/reactHooks/layout/__tests__/index.test.js +1 -0
  16. package/reactHooks/layout/types/index.ts +1 -0
  17. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -5
  18. package/reactHooks/navigation/__mocks__/index.ts +2 -0
  19. package/reactHooks/navigation/__mocks__/useNavigation.ts +4 -0
  20. package/reactHooks/navigation/__tests__/index.test.tsx +19 -4
  21. package/reactHooks/navigation/index.ts +80 -20
  22. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  23. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  24. package/reactHooks/screen/useScreenContext.ts +1 -1
  25. package/reactHooks/screen/useScreenData.ts +1 -1
  26. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  27. package/reactHooks/useListenEventBusEvent.ts +1 -4
  28. package/reactHooks/videoModal/index.ts +0 -3
  29. package/testUtils/index.tsx +15 -2
@@ -270,7 +270,9 @@ export function HooksManager({
270
270
  });
271
271
 
272
272
  const isHookInHomescreen = payload?.home;
273
- const isHookFlowBlocker = hookPlugin?.module?.isFlowBlocker();
273
+
274
+ const isHookFlowBlocker =
275
+ hookPlugin?.module?.isFlowBlocker?.() ?? false;
274
276
 
275
277
  // TODO: We technically need to also support the case where there is more than one hook in the stack,
276
278
  // if needed we could add differentiation explicit user cancellation (when we should go to background) and other types of cancellation
@@ -224,6 +224,12 @@ export const focusManager = (function () {
224
224
  lastAddedParentNode?.children || focusableTree.root.children
225
225
  );
226
226
 
227
+ // console.log("debug_2", "FM setInitialFocus", {
228
+ // preferredFocus,
229
+ // lastAddedParentNode,
230
+ // focusableTree,
231
+ // });
232
+
227
233
  logger.log({ message: "setInitialFocus", data: { preferredFocus } });
228
234
 
229
235
  if (preferredFocus && preferredFocus.length > 0) {
@@ -323,6 +329,8 @@ export const focusManager = (function () {
323
329
  * @returns {React.Component} the registered component
324
330
  */
325
331
  function registerGroup(id, component) {
332
+ // console.log("debug_2", "FM registerGroup", { id, component });
333
+
326
334
  focusableTree.addNode({ id, component });
327
335
 
328
336
  return component;
@@ -338,6 +346,8 @@ export const focusManager = (function () {
338
346
  * @returns {React.Component} the registered component
339
347
  */
340
348
  function registerItem(id, component) {
349
+ // console.log("debug_2", "FM registerItem", { id, component });
350
+
341
351
  focusableTree.addNode({ id, component });
342
352
 
343
353
  if (!currentFocusNode && id === lastFocusedId && !id.includes("menu")) {
@@ -354,6 +364,8 @@ export const focusManager = (function () {
354
364
  * @param {String} id of the group to unregister
355
365
  */
356
366
  function unregisterGroup(id) {
367
+ // console.log("debug_2", "FM unregisterGroup", { id });
368
+
357
369
  focusableTree.findAndRemoveNode(id);
358
370
  }
359
371
 
@@ -365,6 +377,8 @@ export const focusManager = (function () {
365
377
  * @param {String} id of the Focusable to unregister
366
378
  */
367
379
  function unregisterItem(id) {
380
+ // console.log("debug_2", "FM unregisterItem", { id });
381
+
368
382
  focusableTree.findAndRemoveNode(id);
369
383
 
370
384
  if (currentFocusNode && currentFocusNode.id === id) {
@@ -422,6 +436,13 @@ export const focusManager = (function () {
422
436
  currentFocusNode.component.willLoseFocus(currentFocusNode, direction);
423
437
  const nextFocusable = findFocusableNode(direction, currentFocusNode);
424
438
 
439
+ // console.log("debug_2", "FM moveFocus", {
440
+ // direction: direction?.value,
441
+ // currentFocusNode,
442
+ // focusableTree,
443
+ // nextFocusable,
444
+ // });
445
+
425
446
  if (nextFocusable?.component?.isMounted?.()) {
426
447
  const nextRect = nextFocusable.component.getRect();
427
448
 
@@ -1,4 +1,4 @@
1
- import * as R from "ramda";
1
+ import { allPass, pathOr, startsWith } from "ramda";
2
2
  import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
3
3
 
4
4
  import { rejectItemByPath } from "../../../../objectUtils";
@@ -143,7 +143,47 @@ const hasChildren = (target) =>
143
143
 
144
144
  const hasComponent = (target) => !!target?.component;
145
145
 
146
- const hasComponentAndChildren = R.allPass([hasComponent, hasChildren]);
146
+ const hasComponentAndChildren = allPass([hasComponent, hasChildren]);
147
+
148
+ const positiveOrZero = (value) => value >= 0;
149
+
150
+ const excludeFromFocusSearching = pathOr(false, [
151
+ "component",
152
+ "props",
153
+ "excludeFromFocusSearching",
154
+ ]);
155
+
156
+ const isNavBar = (target) => startsWith("navbar", target?.id);
157
+
158
+ const ignoreMenuIfMultipleTargets = (nodes) => {
159
+ if (nodes.length > 1 && nodes.map((n) => n?.target?.id).includes("navbar")) {
160
+ return nodes.filter((n) => !isNavBar(n?.target));
161
+ }
162
+
163
+ return nodes;
164
+ };
165
+
166
+ const toDistance = ({ target, direction, comparisonRect }) => {
167
+ const componentRect = target.component?.getRect();
168
+
169
+ const orientationDistance = measureDistance(
170
+ direction,
171
+ comparisonRect,
172
+ componentRect
173
+ );
174
+
175
+ if (orientationDistance === -1) {
176
+ // ignores offscreen targets when moving up/down
177
+ return null;
178
+ }
179
+
180
+ const euclidDistance = measureEuclidianDistanceToCenter(
181
+ comparisonRect,
182
+ componentRect
183
+ );
184
+
185
+ return orientationDistance > 0 ? euclidDistance : orientationDistance;
186
+ };
147
187
 
148
188
  /**
149
189
  * Get target in shortest distance in specified direction
@@ -173,43 +213,28 @@ export function getTargetInDirection(
173
213
 
174
214
  const distances = targets
175
215
  .filter(hasComponentAndChildren)
176
- .map((target) => {
177
- const componentRect = target.component?.getRect();
178
-
179
- const distance = measureDistance(
180
- direction,
181
- comparisonRect,
182
- componentRect
183
- );
184
-
185
- if (distance === -1) {
186
- // ignores offscreen targets when moving up/down
187
- return null;
188
- }
189
-
190
- return {
191
- distance:
192
- measureDistance(direction, comparisonRect, componentRect) +
193
- measureEuclidianDistanceToCenter(comparisonRect, componentRect) /
194
- 10000,
195
- target,
196
- };
197
- })
198
- .filter((obj) => obj && obj.distance >= 0);
216
+ .filter((target) => !excludeFromFocusSearching(target))
217
+ .map((target) => ({
218
+ distance: toDistance({ target, direction, comparisonRect }),
219
+ target,
220
+ }))
221
+ .filter(({ distance }) => positiveOrZero(distance));
199
222
 
200
223
  const match = distances
201
224
  .sort((a, b) => a.distance - b.distance) // sorts the distances
202
225
  .filter(ignoreMenuIfMultipleTargets)[0]; // filters out multiple targets if necessary // gets the first element
203
226
 
204
- return distances && distances.length > 0 ? match.target : null;
205
- }
206
-
207
- function ignoreMenuIfMultipleTargets(nodes) {
208
- if (nodes.length > 1 && nodes.map((n) => n?.target?.id).includes("navbar")) {
209
- return nodes.filter((n) => n?.target?.id !== "navbar");
210
- }
211
-
212
- return nodes;
227
+ // console.log("debug_2", "FM getTargetInDirection", {
228
+ // direction: direction?.value,
229
+ // currentNode,
230
+ // targetNodes,
231
+ // targets,
232
+ // comparisonRect,
233
+ // distances,
234
+ // match,
235
+ // });
236
+
237
+ return match.target;
213
238
  }
214
239
 
215
240
  /**
@@ -20,6 +20,11 @@ export enum SharedPlayerCallBacksKeys {
20
20
  OnPlayerMute = "onPlayerMute",
21
21
  OnPlayerUnmute = "onPlayerUnmute",
22
22
 
23
+ onVideoFullscreenPlayerDidDismiss = "onVideoFullscreenPlayerDidDismiss",
24
+ onVideoFullscreenPlayerDidPresent = "onVideoFullscreenPlayerDidPresent",
25
+ onVideoFullscreenPlayerWillDismiss = "onVideoFullscreenPlayerWillDismiss",
26
+ onVideoFullscreenPlayerWillPresent = "onVideoFullscreenPlayerWillPresent",
27
+
23
28
  OnAdBegin = "onAdBegin",
24
29
  OnAdBreakBegin = "onAdBreakBegin",
25
30
  OnAdBreakEnd = "onAdBreakEnd",
@@ -414,6 +414,32 @@ export class Player {
414
414
  });
415
415
  };
416
416
 
417
+ onVideoFullscreenPlayerWillDismiss = () => {
418
+ this.invokeListenersUpdate({
419
+ callbackName:
420
+ SharedPlayerCallBacksKeys.onVideoFullscreenPlayerWillDismiss,
421
+ });
422
+ };
423
+
424
+ onVideoFullscreenPlayerDidDismiss = () => {
425
+ this.invokeListenersUpdate({
426
+ callbackName: SharedPlayerCallBacksKeys.onVideoFullscreenPlayerDidDismiss,
427
+ });
428
+ };
429
+
430
+ onVideoFullscreenPlayerWillPresent = () => {
431
+ this.invokeListenersUpdate({
432
+ callbackName:
433
+ SharedPlayerCallBacksKeys.onVideoFullscreenPlayerWillPresent,
434
+ });
435
+ };
436
+
437
+ onVideoFullscreenPlayerDidPresent = () => {
438
+ this.invokeListenersUpdate({
439
+ callbackName: SharedPlayerCallBacksKeys.onVideoFullscreenPlayerDidPresent,
440
+ });
441
+ };
442
+
417
443
  public invokeListenersUpdate = ({
418
444
  callbackName,
419
445
  event = {},
@@ -634,6 +660,12 @@ export class Player {
634
660
  onBufferStart: this.onBufferStart,
635
661
  onBufferComplete: this.onBufferComplete,
636
662
 
663
+ onPlayerClose: this.onPlayerClose,
664
+ onVideoFullscreenPlayerWillPresent: this.onVideoFullscreenPlayerWillPresent,
665
+ onVideoFullscreenPlayerDidPresent: this.onVideoFullscreenPlayerDidPresent,
666
+ onVideoFullscreenPlayerWillDismiss: this.onVideoFullscreenPlayerWillDismiss,
667
+ onVideoFullscreenPlayerDidDismiss: this.onVideoFullscreenPlayerDidDismiss,
668
+
637
669
  // Ads Callbacks:
638
670
  onAdBegin: this.onAdBegin,
639
671
  onAdBreakBegin: this.onAdBreakBegin,
@@ -693,4 +725,6 @@ export class Player {
693
725
  isFullScreenSupported(): boolean {
694
726
  return true;
695
727
  }
728
+
729
+ public supportsNativeControls = (): boolean => false;
696
730
  }
@@ -9,21 +9,23 @@ type PlayerFactoryItem = {
9
9
  };
10
10
 
11
11
  type PlayerFactoryProps = {
12
- player: any,
13
- playerId: string,
14
- autoplay: boolean,
15
- entry: ZappEntry,
16
- muted: boolean,
17
- playerPluginId: string,
18
- screenConfig: Record<string, any>,
19
- playerRole: PlayerRole,
20
- }
12
+ player: any;
13
+ playerId: string;
14
+ autoplay: boolean;
15
+ entry: ZappEntry;
16
+ muted: boolean;
17
+ playerPluginId: string;
18
+ screenConfig: Record<string, any>;
19
+ playerRole: PlayerRole;
20
+ };
21
21
 
22
22
  interface PlayerConstructor {
23
23
  new (params: any): Player;
24
24
  }
25
25
 
26
- export const playerFactory = (config: PlayerFactoryProps): PlayerFactoryItem | null => {
26
+ export const playerFactory = (
27
+ config: PlayerFactoryProps
28
+ ): PlayerFactoryItem | null => {
27
29
  const IDENTIFIER = config?.playerPluginId;
28
30
 
29
31
  if (!IDENTIFIER) {
@@ -5,6 +5,7 @@ import { Player } from "./player";
5
5
  import { findNodeHandle, NativeModules } from "react-native";
6
6
  import { isApplePlatform } from "../../reactUtils";
7
7
  import { PlayerRole } from "./conts";
8
+ import { toBooleanWithDefaultFalse } from "../../booleanUtils";
8
9
 
9
10
  const RNPlayerManager = {
10
11
  QuickBrickPlayerPlugin: isApplePlatform()
@@ -291,4 +292,7 @@ export class PlayerNative extends Player {
291
292
 
292
293
  return !(isFullScreenAudioPlayer && this.isAudioItem());
293
294
  };
295
+
296
+ supportsNativeControls = (): boolean =>
297
+ toBooleanWithDefaultFalse(this.getConfig()?.["supports_native_controls"]);
294
298
  }
@@ -182,8 +182,8 @@ export const getHeight = (width, aspectRatio) => {
182
182
  * @returns {string} duration
183
183
  */
184
184
 
185
- export const getDurationInMinutes = (seconds: number): string => {
186
- if (seconds === (null || undefined)) return "00:00";
185
+ export const getDurationInMinutes = (seconds?: number): string => {
186
+ if (!seconds) return "00:00";
187
187
  const minutes = Math.floor(Number(seconds) / 60);
188
188
  const secondsReminder = Math.floor(Number(seconds)) % 60;
189
189
  const pad = (num: number): string => `${num < 10 ? "0" : ""}${num}`;
@@ -460,7 +460,9 @@ export const getColorFromData = ({
460
460
  }: GetColorFromData): string => {
461
461
  const value = getValue(key);
462
462
 
463
- if (validateColor(value)) {
463
+ // Temporary hack to fix color validation when alpha is floating point number
464
+ // https://github.com/dreamyguy/validate-color/issues/44
465
+ if (validateColor(value.replace(".00", ""))) {
464
466
  return value;
465
467
  }
466
468
 
@@ -22,7 +22,11 @@ const {
22
22
  const { buttonKey } = require("./buttons");
23
23
  const { tvBadges } = require("./tvBadges");
24
24
  const { mobileProgressBar, tvProgressBar } = require("./progressBar");
25
- const { secondaryImage, getUpdatedSecondaryImageKeys } = require("./secondaryImage");
25
+
26
+ const {
27
+ secondaryImage,
28
+ getUpdatedSecondaryImageKeys,
29
+ } = require("./secondaryImage");
26
30
 
27
31
  module.exports = {
28
32
  fontKey,
@@ -132,29 +132,32 @@ function secondaryImage({
132
132
 
133
133
  const POSITION_OVER_IMAGE = toSnakeCase(position_over_image);
134
134
 
135
- const getUpdatedSecondaryImageKeys = (secondaryImageManifest) => secondaryImageManifest.fields.reduce((acc, item) => {
136
- const key = item.key;
135
+ const getUpdatedSecondaryImageKeys = (secondaryImageManifest) =>
136
+ secondaryImageManifest.fields.reduce((acc, item) => {
137
+ const key = item.key;
137
138
 
138
- const conditionalFields = (item.conditional_fields || []).map((field) => field.key);
139
+ const conditionalFields = (item.conditional_fields || []).map(
140
+ (field) => field.key
141
+ );
139
142
 
140
- const updatedConditionalFields = conditionalFields.reduce((acc, field) => {
141
- const updatedKey = field.replace("secondary_image_", "nested_image_");
143
+ const updatedConditionalFields = conditionalFields.reduce((acc, field) => {
144
+ const updatedKey = field.replace("secondary_image_", "nested_image_");
145
+
146
+ return {
147
+ ...acc,
148
+ [updatedKey]: field,
149
+ };
150
+ }, {});
151
+
152
+ const updatedKey = key.replace("secondary_image_", "nested_image_");
142
153
 
143
154
  return {
144
155
  ...acc,
145
- [updatedKey]: field,
156
+ ...updatedConditionalFields,
157
+ [updatedKey]: key,
146
158
  };
147
159
  }, {});
148
160
 
149
- const updatedKey = key.replace("secondary_image_", "nested_image_");
150
-
151
- return {
152
- ...acc,
153
- ...updatedConditionalFields,
154
- [updatedKey]: key,
155
- };
156
- }, {});
157
-
158
161
  module.exports = {
159
162
  secondaryImage,
160
163
  getUpdatedSecondaryImageKeys,
@@ -114,7 +114,11 @@ export function getNavigationProps({
114
114
  } | null {
115
115
  const { activeRiver } = navigator;
116
116
  const { navigations, id: selected, home } = activeRiver; // use useRiver hook instead
117
- const navigation = R.find(R.propEq("category", category), navigations);
117
+
118
+ const navigation: ZappNavigation = R.find(
119
+ R.propEq("category", category),
120
+ navigations
121
+ );
118
122
 
119
123
  if (!navigation) {
120
124
  return null;
@@ -127,9 +131,9 @@ export function getNavigationProps({
127
131
  title,
128
132
  home,
129
133
  styles,
130
- assets,
131
- nav_items,
132
- rules,
134
+ assets: assets as ZappNavBarAssets,
135
+ nav_items: nav_items as any as NavBarItem[],
136
+ rules: rules as any as ZappNavBarRules,
133
137
  };
134
138
  }
135
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.3977160850",
3
+ "version": "12.0.0-alpha.4433422595",
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-alpha.3977160850",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.4433422595",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -12,6 +12,8 @@ jest.mock(
12
12
  })
13
13
  );
14
14
 
15
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
16
+
15
17
  jest.useFakeTimers();
16
18
 
17
19
  const {
@@ -17,6 +17,8 @@ jest.mock(
17
17
 
18
18
  jest.useFakeTimers();
19
19
 
20
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
21
+
20
22
  const { useTrackedView } = require("../useTrackedView");
21
23
 
22
24
  describe("useTrackCurrentAutoScrollingElement", () => {
@@ -44,6 +44,7 @@ jest.mock("../../../reactUtils", () => ({
44
44
 
45
45
  jest.mock("../../navigation", () => ({
46
46
  useNavigation: () => null,
47
+ useIsScreenActive: () => true,
47
48
  }));
48
49
 
49
50
  const { Dimensions } = require("react-native");
@@ -20,6 +20,7 @@ export type Options = {
20
20
  excludeStatusBar?: boolean;
21
21
  rounded?: boolean;
22
22
  deviceInfo?: boolean;
23
+ updateForInactiveScreens?: boolean;
23
24
  };
24
25
 
25
26
  export type Context = "window" | "screen";
@@ -1,4 +1,4 @@
1
- import { useState, useLayoutEffect, useRef, useMemo } from "react";
1
+ import { useLayoutEffect, useMemo, useRef, useState } from "react";
2
2
 
3
3
  import * as R from "ramda";
4
4
 
@@ -8,6 +8,7 @@ import { isTV } from "../../../reactUtils";
8
8
  import { Options, UseDimensions } from "../types";
9
9
  import { getDeviceInfo } from "../getDeviceInfo";
10
10
  import { getInitialDimensions } from "./helpers";
11
+ import { useIsScreenActive } from "../../navigation";
11
12
 
12
13
  function compensateForScaleIfNeeded(context) {
13
14
  return function () {
@@ -32,8 +33,10 @@ const statusBarHeight = StatusBar?.currentHeight;
32
33
  */
33
34
  export const useDimensions: UseDimensions = (
34
35
  context = "window",
35
- fullDimensions = { fullDimensions: false }
36
+ fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
36
37
  ) => {
38
+ const isActive = useIsScreenActive();
39
+
37
40
  if (typeof fullDimensions === "boolean") {
38
41
  // eslint-disable-next-line no-console
39
42
  console.warn(
@@ -73,7 +76,7 @@ export const useDimensions: UseDimensions = (
73
76
 
74
77
  if (newDimensions.width === newDimensions.height) {
75
78
  /**
76
- * Ignoring case occured on iOS when Dimensions.get sometimes returning
79
+ * Ignoring case occurred on iOS when Dimensions.get sometimes returning
77
80
  * wrong `window` sizes
78
81
  * when switch background -> foreground state.
79
82
  * ( TODO fix when 1:1 aspect ratio will be used )
@@ -81,7 +84,7 @@ export const useDimensions: UseDimensions = (
81
84
 
82
85
  // eslint-disable-next-line no-console
83
86
  console.log("change: wrong values - width equal to height, ignoring");
84
- } else {
87
+ } else if (isActive || options.updateForInactiveScreens) {
85
88
  deviceInfo.current = getDeviceInfo(newDimensions);
86
89
  setDimensions(newDimensions);
87
90
  }
@@ -92,7 +95,7 @@ export const useDimensions: UseDimensions = (
92
95
  return () => {
93
96
  activeSubscription.remove();
94
97
  };
95
- }, []);
98
+ }, [isActive]);
96
99
 
97
100
  const memoizedDimensions = useMemo(() => {
98
101
  return { ...applyOptions(dimensions), statusBarHeight };
@@ -23,3 +23,5 @@ export const useNavigation = jest.fn(() => ({
23
23
  export const useNavigationPluginData = jest.fn().mockReturnValue(mockMenu);
24
24
 
25
25
  export const useIsNavBarVisible = jest.fn().mockReturnValue(true);
26
+
27
+ export const useIsScreenActive = jest.fn().mockReturnValue(true);
@@ -0,0 +1,4 @@
1
+ export const useNavigation = jest.fn(() => ({
2
+ data: {},
3
+ currentRoute: "someRoute",
4
+ }));
@@ -45,10 +45,19 @@ const videoItem = {
45
45
  type: { value: "video" },
46
46
  };
47
47
 
48
+ const mockGetStackForPathname = jest.fn().mockReturnValue(homeStack);
49
+
48
50
  const mainStackNavigator = {
49
- getStackForPathname: jest.fn().mockReturnValue(homeStack),
51
+ getStackForPathname: mockGetStackForPathname,
50
52
  getModalState: () => {},
51
53
  videoModalState: {},
54
+ canGoBack: jest.fn(),
55
+ };
56
+
57
+ const _createWrapper = (Wrapper, props) => {
58
+ return function CreatedWrapper({ children }: any) {
59
+ return <Wrapper {...props}>{children}</Wrapper>;
60
+ };
52
61
  };
53
62
 
54
63
  const videoModalNavigator = {
@@ -85,10 +94,16 @@ const store = mockStore({
85
94
  contentTypes,
86
95
  });
87
96
 
88
- const mainStackWrapper = ({ children }) => (
97
+ const mainStackWrapper = ({
98
+ children,
99
+ navigator = {},
100
+ pathname = homeStack.route,
101
+ }) => (
89
102
  <Provider store={store}>
90
- <NavigationContext.Provider value={mainStackNavigator}>
91
- <PathnameContext.Provider value={homeStack.route}>
103
+ <NavigationContext.Provider
104
+ value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
105
+ >
106
+ <PathnameContext.Provider value={pathname}>
92
107
  {children}
93
108
  </PathnameContext.Provider>
94
109
  </NavigationContext.Provider>
@@ -19,9 +19,9 @@ import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Co
19
19
  import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
20
20
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
21
21
  import {
22
+ getNavigationProps,
22
23
  getRiverFromRoute,
23
24
  getTargetRoute,
24
- getNavigationProps,
25
25
  } from "../../navigationUtils";
26
26
  import { platformSelect } from "../../reactUtils";
27
27
  import { useConnectionInfo } from "../connection";
@@ -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,35 +200,58 @@ export const useRoute = (): {
193
200
  // if path is hook grab screenData from screenData
194
201
 
195
202
  if (isModalPathname(pathname)) {
196
- const screenData = modalScreenData ?? ({} as ZappEntry);
197
-
198
- return { screenData, pathname };
203
+ return composeRouteData(modalScreenData ?? ({} as ZappEntry));
199
204
  }
200
205
 
201
206
  if (isVideoModalPathname(pathname)) {
202
- const screenData = videoModalScreenData as LegacyNavigationScreenData;
203
-
204
- return { screenData, pathname };
207
+ return composeRouteData(videoModalScreenData as LegacyNavigationScreenData);
205
208
  }
206
209
 
207
210
  if (isHookModalPathname(pathname)) {
208
- const screenData = hookModalScreenData;
209
-
210
- return { screenData, pathname };
211
+ return composeRouteData(hookModalScreenData);
211
212
  }
212
213
 
213
214
  if (isHookPathname(pathname)) {
214
- const screenData =
215
- "hookPlugin" in currentRouteScreenData
216
- ? currentRouteScreenData
217
- : navigator.screenData;
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
+ }
218
227
 
219
- return { screenData, pathname };
220
- }
228
+ const isValidHookInCurrentRouteScreenData =
229
+ "hookPlugin" in currentRouteScreenData &&
230
+ !!currentRouteScreenData.hookPlugin?.module;
231
+
232
+ let screenData;
221
233
 
222
- const screenData = currentRouteScreenData;
234
+ // case 2: stack has valid hook data
235
+ if (isValidHookInCurrentRouteScreenData) {
236
+ screenData = currentRouteScreenData;
237
+ }
238
+
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
+ }
223
250
 
224
- return { screenData, pathname };
251
+ return composeRouteData(screenData);
252
+ }
253
+
254
+ return composeRouteData(currentRouteScreenData);
225
255
  };
226
256
 
227
257
  type Callbacks = Partial<{
@@ -446,3 +476,33 @@ export const useGetBottomTabBarHeight = (): number => {
446
476
 
447
477
  return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
448
478
  };
479
+
480
+ // If current screen is active/focused (visible to the user)
481
+ export const useIsScreenActive = () => {
482
+ const pathname = usePathname();
483
+ const { currentRoute, videoModalState } = useNavigation();
484
+
485
+ if (
486
+ videoModalState.visible &&
487
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
488
+ ) {
489
+ return false;
490
+ }
491
+
492
+ return pathname === currentRoute;
493
+ };
494
+
495
+ type Return = (prefix: string) => string;
496
+
497
+ export const useUniqueRouteSuffix = (): Return => {
498
+ const pathname = usePathname();
499
+ const { currentRoute } = useNavigation();
500
+
501
+ const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
502
+
503
+ const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
504
+ return `${prefix}___${suffix}`;
505
+ }, []);
506
+
507
+ return withUniqueRouteSuffix;
508
+ };
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { renderHook, cleanup } from "@testing-library/react-hooks";
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: NavigationScreenData = {
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?: string): ZappRiver => {
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
 
@@ -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 });
@@ -2,9 +2,6 @@ import * as R from "ramda";
2
2
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
3
3
  import { useMemoizedIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks/device";
4
4
 
5
- import { LogBox } from "react-native";
6
- LogBox.ignoreAllLogs();
7
-
8
5
  import { useMobileOrientationEffect } from "./useMobileOrientationEffect";
9
6
  import { noop } from "./utils";
10
7
 
@@ -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 <Provider store={_store}>{children}</Provider>;
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
  /**