@applicaster/zapp-react-native-utils 15.0.0-alpha.3564837831 → 15.0.0-alpha.3634430569

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 (121) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +83 -6
  3. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  4. package/analyticsUtils/analyticsMapper.ts +10 -2
  5. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  6. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  7. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  8. package/appUtils/HooksManager/index.ts +35 -0
  9. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  10. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  11. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  12. package/appUtils/contextKeysManager/index.ts +65 -10
  13. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -1
  14. package/appUtils/focusManager/index.ios.ts +7 -8
  15. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  16. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  17. package/appUtils/focusManagerAux/utils/index.ios.ts +5 -5
  18. package/appUtils/focusManagerAux/utils/index.ts +2 -4
  19. package/appUtils/focusManagerAux/utils/utils.ios.ts +16 -24
  20. package/appUtils/localizationsHelper.ts +4 -0
  21. package/appUtils/playerManager/index.ts +9 -0
  22. package/appUtils/playerManager/player.ts +1 -1
  23. package/appUtils/playerManager/playerNative.ts +2 -1
  24. package/appUtils/playerManager/usePlayer.tsx +5 -3
  25. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  26. package/cloudEventsUtils/index.ts +65 -1
  27. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  28. package/configurationUtils/index.ts +17 -11
  29. package/dateUtils/__tests__/dayjs.test.ts +330 -0
  30. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  31. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  32. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  33. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  34. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  35. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  36. package/errorUtils/__tests__/invariant.test.ts +112 -0
  37. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  38. package/headersUtils/index.ts +2 -1
  39. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  40. package/manifestUtils/_internals/index.js +33 -0
  41. package/manifestUtils/defaultManifestConfigurations/player.js +35 -16
  42. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  43. package/manifestUtils/fieldUtils/index.js +54 -0
  44. package/manifestUtils/index.js +2 -0
  45. package/manifestUtils/keys.js +228 -0
  46. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  47. package/manifestUtils/mobileAction/button/index.js +140 -0
  48. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  49. package/manifestUtils/mobileAction/container/index.js +73 -0
  50. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  51. package/manifestUtils/mobileAction/groups/defaults.js +75 -0
  52. package/manifestUtils/mobileAction/groups/index.js +80 -0
  53. package/manifestUtils/platformIsTV.js +13 -0
  54. package/navigationUtils/index.ts +15 -5
  55. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  56. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  57. package/numberUtils/index.ts +23 -1
  58. package/package.json +4 -4
  59. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  60. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  61. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  62. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  63. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  64. package/reactHooks/cell-click/index.ts +2 -1
  65. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  66. package/reactHooks/connection/__tests__/index.test.js +1 -1
  67. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  68. package/reactHooks/device/useIsTablet.tsx +14 -19
  69. package/reactHooks/events/index.ts +20 -0
  70. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  71. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  72. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +1 -1
  73. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  74. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +1 -1
  75. package/reactHooks/feed/index.ts +0 -2
  76. package/reactHooks/feed/useInflatedUrl.ts +1 -1
  77. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  78. package/reactHooks/index.ts +2 -0
  79. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  80. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  81. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  82. package/reactHooks/navigation/index.ts +15 -4
  83. package/reactHooks/navigation/useRoute.ts +3 -1
  84. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  85. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  86. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  87. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  88. package/reactHooks/resolvers/useComponentResolver.ts +11 -1
  89. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +1 -1
  90. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  91. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  92. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +1 -1
  93. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  94. package/reactHooks/state/index.ts +2 -0
  95. package/reactHooks/state/useComponentScreenState.ts +45 -0
  96. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  97. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  98. package/reactHooks/utils/__tests__/index.test.js +1 -1
  99. package/rectUtils/__tests__/index.test.ts +549 -0
  100. package/rectUtils/index.ts +2 -2
  101. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +161 -0
  102. package/refreshUtils/RefreshCoordinator/index.ts +216 -0
  103. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  104. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  105. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  106. package/screenPickerUtils/index.ts +5 -0
  107. package/screenState/__tests__/index.test.ts +1 -1
  108. package/screenUtils/index.ts +3 -0
  109. package/services/storageServiceSync.web.ts +1 -1
  110. package/stringUtils/index.ts +1 -1
  111. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  112. package/time/__tests__/Timer.test.ts +236 -0
  113. package/typeGuards/__tests__/isString.test.ts +21 -0
  114. package/typeGuards/index.ts +4 -0
  115. package/utils/__tests__/clone.test.ts +158 -0
  116. package/utils/__tests__/path.test.ts +7 -0
  117. package/utils/clone.ts +7 -0
  118. package/utils/index.ts +2 -1
  119. package/reactHooks/componentsMap/index.ts +0 -55
  120. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  121. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -373,3 +373,49 @@ describe("addNode", () => {
373
373
  checkParents(tree.root);
374
374
  });
375
375
  });
376
+
377
+ describe("findInTree", () => {
378
+ function createNode(id, children) {
379
+ return {
380
+ id,
381
+ children,
382
+ };
383
+ }
384
+
385
+ it("returns a direct child match from root children", () => {
386
+ const tree = new Tree(treeLoaded);
387
+ const direct = createNode("direct-node");
388
+
389
+ tree.root.children = [direct];
390
+
391
+ expect(tree.findInTree("direct-node")).toEqual(direct);
392
+ });
393
+
394
+ it("returns a nested descendant match", () => {
395
+ const tree = new Tree(treeLoaded);
396
+ const nested = createNode("nested-node");
397
+ const intermediate = createNode("intermediate-node", [nested]);
398
+ const rootNode = createNode("root-node", [intermediate]);
399
+
400
+ tree.root.children = [rootNode];
401
+
402
+ expect(tree.findInTree("nested-node")).toEqual(nested);
403
+ });
404
+
405
+ it("returns null when node id does not exist", () => {
406
+ const tree = new Tree(treeLoaded);
407
+ const leaf = createNode("leaf-node");
408
+ const rootNode = createNode("root-node", [leaf]);
409
+
410
+ tree.root.children = [rootNode];
411
+
412
+ expect(tree.findInTree("missing-node")).toEqual(null);
413
+ });
414
+
415
+ it("returns null when tree has no children", () => {
416
+ const tree = new Tree(treeLoaded);
417
+ tree.root.children = null;
418
+
419
+ expect(tree.findInTree("any-node")).toEqual(null);
420
+ });
421
+ });
@@ -205,31 +205,31 @@ export class Tree {
205
205
  * @returns founded node or null
206
206
  */
207
207
  findInTree(id) {
208
- const retVal = null;
209
-
210
- return this.findInArray(id, this.root.children, retVal);
208
+ return this.findInArray(id, this.root.children);
211
209
  }
212
210
 
213
- findInArray(id, children, retVal) {
214
- if (!retVal && children) {
215
- retVal = children.find((obj) => obj.id === id);
211
+ findInArray(id, children) {
212
+ if (!children) {
213
+ return null;
214
+ }
216
215
 
217
- if (!retVal) {
218
- children.forEach((child) => {
219
- if (child.children) {
220
- retVal = this.findInArray(id, child.children, retVal);
216
+ const directMatch = children.find((obj) => obj.id === id);
221
217
 
222
- if (retVal) {
223
- return retVal;
224
- }
225
- }
226
- });
227
- } else {
228
- return retVal;
218
+ if (directMatch) {
219
+ return directMatch;
220
+ }
221
+
222
+ for (const child of children) {
223
+ if (child.children) {
224
+ const nestedMatch = this.findInArray(id, child.children);
225
+
226
+ if (nestedMatch) {
227
+ return nestedMatch;
228
+ }
229
229
  }
230
230
  }
231
231
 
232
- return retVal;
232
+ return null;
233
233
  }
234
234
 
235
235
  /**
@@ -9,9 +9,9 @@ const isNavBar = (node) => startsWith(QUICK_BRICK_NAVBAR, node?.id);
9
9
  const isContent = (node) => startsWith(QUICK_BRICK_CONTENT, node?.id);
10
10
  const isRoot = (node) => node?.id === "root";
11
11
 
12
- export const isPartOfTabsScreen = (
12
+ export const isPartOfTabsScreenContent = (
13
13
  focusableTree,
14
- tabsScreenContainerId,
14
+ screenPickerContentContainerId,
15
15
  id
16
16
  ) => {
17
17
  const node = focusableTree.findInTree(id);
@@ -32,13 +32,13 @@ export const isPartOfTabsScreen = (
32
32
  return false;
33
33
  }
34
34
 
35
- if (node?.id === tabsScreenContainerId) {
35
+ if (node?.id === screenPickerContentContainerId) {
36
36
  return true;
37
37
  }
38
38
 
39
- return isPartOfTabsScreen(
39
+ return isPartOfTabsScreenContent(
40
40
  focusableTree,
41
- tabsScreenContainerId,
41
+ screenPickerContentContainerId,
42
42
  node.parent?.id
43
43
  );
44
44
  };
@@ -13,7 +13,7 @@ import {
13
13
 
14
14
  import {
15
15
  getFocusableId,
16
- SCREEN_PICKER_CONTAINER,
16
+ isTabsScreenContentContainerId,
17
17
  } from "@applicaster/zapp-react-native-utils/screenPickerUtils";
18
18
 
19
19
  // run check each 300 ms
@@ -24,8 +24,6 @@ const isTopMenu = (node) => startsWith(QUICK_BRICK_NAVBAR, node?.id);
24
24
  const isContent = (node) => startsWith(QUICK_BRICK_CONTENT, node?.id);
25
25
  const isRoot = (node) => node?.id === "root";
26
26
 
27
- const isScrenPicker = (node) => startsWith(SCREEN_PICKER_CONTAINER, node?.id);
28
-
29
27
  type Props = {
30
28
  maxTimeout: number;
31
29
  conditionFn: () => boolean;
@@ -136,7 +134,7 @@ export const isTabsScreenOnContentFocused = (node) => {
136
134
  return false;
137
135
  }
138
136
 
139
- if (isScrenPicker(node)) {
137
+ if (isTabsScreenContentContainerId(node?.id)) {
140
138
  return true;
141
139
  }
142
140
 
@@ -106,9 +106,8 @@ const focusableNativeViewRegistration = ({ focusableView, focusableGroup }) => {
106
106
  );
107
107
  };
108
108
 
109
- export const firstFocusableViewRegistrationFactory = () =>
109
+ export const firstFocusableViewInContentRegistrationFactory = () =>
110
110
  focusableViewRegistrationSubject$.pipe(
111
- take(1), // we care about only first FocusableView registration
112
111
  switchMap((focusableView) =>
113
112
  // start waiting registration of its parent FocusableGroup
114
113
  focusableGroupRegistrationSubject$.pipe(
@@ -126,7 +125,11 @@ export const firstFocusableViewRegistrationFactory = () =>
126
125
  focusableView,
127
126
  focusableGroup,
128
127
  })
129
- )
128
+ ),
129
+ filter(({ focusableView }) =>
130
+ isPartOfContent(focusManager.focusableTree, focusableView.id)
131
+ ),
132
+ take(1) // we care about only first FocusableView registration
130
133
  );
131
134
 
132
135
  // registration on RN level(into RN focusManager)
@@ -178,34 +181,27 @@ export const emitNativeRegistered = ({
178
181
  }
179
182
  };
180
183
 
181
- // Focusable has been focused
182
- const willFocusedSubject$ = new Subject<FocusableID>();
183
- const didFocusedSubject$ = new Subject<FocusableID>();
184
+ // /////
184
185
 
185
- export const willFocused$ = willFocusedSubject$.asObservable();
186
+ const focusedSubject$ = new Subject<FocusableID>();
186
187
 
187
- export const didFocused$ = didFocusedSubject$.asObservable();
188
+ const focused$ = focusedSubject$.asObservable();
188
189
 
189
- export const emitWillFocused = (id: FocusableID): void => {
190
- willFocusedSubject$.next(id);
190
+ export const emitFocused = (id: FocusableID): void => {
191
+ focusedSubject$.next(id);
191
192
  };
192
193
 
193
- export const emitDidFocused = (id: FocusableID): void => {
194
- didFocusedSubject$.next(id);
195
- };
196
-
197
- export const topMenuItemDidFocused$ = didFocused$.pipe(
194
+ export const topMenuItemFocused$ = focused$.pipe(
198
195
  filter((id) => id && isPartOfMenu(focusManager.focusableTree, id))
199
196
  );
200
197
 
201
- export const contentDidFocused$ = didFocused$.pipe(
198
+ export const contentFocused$ = focused$.pipe(
202
199
  filter((id) => {
203
200
  const isContent = isPartOfContent(focusManager.focusableTree, id);
204
201
 
205
202
  return id && isContent;
206
203
  })
207
204
  );
208
- // Focusable has been focused
209
205
 
210
206
  const createFocusableRegistry = () => {
211
207
  const subject$ = new ReplaySubject<FocusableID | undefined>(1);
@@ -226,17 +222,13 @@ const createFocusableRegistry = () => {
226
222
  /// HOME_TOP_MENU_ITEM
227
223
  export const HomeTopMenuItemRegistry = createFocusableRegistry();
228
224
 
229
- export const homeTopMenuItemDidFocused$ = topMenuItemDidFocused$.pipe(
225
+ export const homeTopMenuItemFocused$ = topMenuItemFocused$.pipe(
230
226
  withLatestFrom(HomeTopMenuItemRegistry.observable$),
231
227
  filter(([id, homeId]) => id === homeId)
232
228
  );
233
229
 
234
- /// TABS SCREEN
235
- export const TabsScreenContentContainerRegistry = createFocusableRegistry();
236
-
237
- export const TabsScreenScreenSelectorContainerRegistry =
238
- createFocusableRegistry();
239
- /// TABS SCREEN
230
+ /// SCREEN_PICKER
231
+ export const ScreenPickerContentContainerRegistry = createFocusableRegistry();
240
232
 
241
233
  /// SEARCH_INPUT
242
234
  export const SearchInputRegistry = createFocusableRegistry();
@@ -85,6 +85,10 @@ export const toDayJSLocaleMap = (code) => {
85
85
  tt: null,
86
86
  "es-LA": "es",
87
87
  "en-UK": "en-gb",
88
+ "en-ZA": null,
89
+ "en-NG": null,
90
+ "en-ZW": null,
91
+ "en-ZM": null,
88
92
  };
89
93
 
90
94
  if (map[code] === null) {
@@ -33,6 +33,7 @@ function deprecationWarning(method) {
33
33
  export interface PlayerLifecycleListener {
34
34
  onRegistered?: (player: Player) => void;
35
35
  onUnRegistered?: (player: Player) => void;
36
+ onCastingChanged?: (isCasting: boolean) => void;
36
37
  }
37
38
 
38
39
  type PlayersMap = {
@@ -253,10 +254,18 @@ export class PlayerManager {
253
254
 
254
255
  public registerCastingReceiver(receiver: Player) {
255
256
  this.castingReceiver = receiver;
257
+
258
+ this.lifecycleListeners.forEach((listener) => {
259
+ listener.onCastingChanged?.(true);
260
+ });
256
261
  }
257
262
 
258
263
  public unregisterCastingReceiver() {
259
264
  this.castingReceiver = null;
265
+
266
+ this.lifecycleListeners.forEach((listener) => {
267
+ listener.onCastingChanged?.(false);
268
+ });
260
269
  }
261
270
 
262
271
  /**
@@ -258,7 +258,7 @@ export class Player {
258
258
  };
259
259
 
260
260
  isAd = () => {
261
- return !!this.playerState.adState || this.playerState.isInAdBreak;
261
+ return !!this.playerState.adState || !!this.playerState.isInAdBreak;
262
262
  };
263
263
 
264
264
  isSeeking = () => {
@@ -229,8 +229,9 @@ export class PlayerNative extends Player {
229
229
  };
230
230
 
231
231
  closeNativePlayer = () => {
232
- // TODO: Delete does not work
232
+ // TODO: Delete, does not work (component is null)
233
233
  this.currentPlayerComponent()?.closeNativePlayer?.();
234
+ this.getPlayerModule()?.stopBackgroundPlayback?.();
234
235
  };
235
236
 
236
237
  togglePlayPause = () => {
@@ -22,7 +22,6 @@ export const usePlayer = (playerId?: string): Player => {
22
22
 
23
23
  const isCasting = playerManager.isCasting();
24
24
 
25
- // TODO: We need to prerender when we start/stop casting, fix this
26
25
  const getPlayer = (playerId, isCasting) =>
27
26
  getControlledPlayer(playerId, isCasting);
28
27
 
@@ -46,7 +45,7 @@ export const usePlayer = (playerId?: string): Player => {
46
45
  return playerManager.addLifecycleListener({
47
46
  onRegistered: (player) => {
48
47
  if (playerIdToUse === player.playerId) {
49
- setPlayer(getPlayer(playerIdToUse, isCasting));
48
+ setPlayer(getPlayer(playerIdToUse, playerManager.isCasting()));
50
49
  }
51
50
  },
52
51
  onUnRegistered: (player) => {
@@ -54,8 +53,11 @@ export const usePlayer = (playerId?: string): Player => {
54
53
  setPlayer(null);
55
54
  }
56
55
  },
56
+ onCastingChanged: () => {
57
+ setPlayer(getPlayer(playerIdToUse, playerManager.isCasting()));
58
+ },
57
59
  } as PlayerLifecycleListener);
58
- }, [playerIdToUse, isCasting]);
60
+ }, [playerIdToUse]);
59
61
 
60
62
  return player;
61
63
  };