@applicaster/zapp-react-native-utils 15.0.0-alpha.2004137882 → 15.0.0-alpha.2120060090

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 (103) hide show
  1. package/README.md +0 -6
  2. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  3. package/analyticsUtils/analyticsMapper.ts +10 -2
  4. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  5. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  6. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  7. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  8. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  9. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  10. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  11. package/appUtils/contextKeysManager/index.ts +65 -10
  12. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
  13. package/appUtils/focusManager/index.ios.ts +35 -2
  14. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  15. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  16. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  17. package/appUtils/focusManagerAux/utils/index.ts +2 -4
  18. package/appUtils/focusManagerAux/utils/utils.ios.ts +61 -4
  19. package/appUtils/playerManager/playerNative.ts +2 -1
  20. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  21. package/cloudEventsUtils/index.ts +65 -1
  22. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  23. package/configurationUtils/index.ts +17 -11
  24. package/dateUtils/__tests__/dayjs.test.ts +330 -0
  25. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  26. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  27. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  28. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  29. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  30. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  31. package/errorUtils/__tests__/invariant.test.ts +112 -0
  32. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  33. package/headersUtils/index.ts +2 -1
  34. package/manifestUtils/defaultManifestConfigurations/player.js +34 -10
  35. package/manifestUtils/platformIsTV.js +13 -0
  36. package/navigationUtils/index.ts +15 -5
  37. package/numberUtils/__tests__/toPositiveNumber.test.ts +160 -0
  38. package/numberUtils/index.ts +19 -1
  39. package/package.json +4 -4
  40. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  41. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  42. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  43. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  44. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  45. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  46. package/reactHooks/connection/__tests__/index.test.js +1 -1
  47. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  48. package/reactHooks/device/useIsTablet.tsx +14 -19
  49. package/reactHooks/events/index.ts +20 -0
  50. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  51. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  52. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +1 -1
  53. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  54. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +1 -1
  55. package/reactHooks/feed/index.ts +0 -2
  56. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  57. package/reactHooks/index.ts +2 -0
  58. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  59. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  60. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  61. package/reactHooks/navigation/index.ts +19 -4
  62. package/reactHooks/navigation/useRoute.ts +3 -1
  63. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  64. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  65. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  66. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  67. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  68. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  69. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  70. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +2 -2
  71. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  72. package/reactHooks/state/index.ts +2 -0
  73. package/reactHooks/state/useComponentScreenState.ts +45 -0
  74. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  75. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  76. package/reactHooks/utils/__tests__/index.test.js +1 -1
  77. package/rectUtils/__tests__/index.test.ts +549 -0
  78. package/rectUtils/index.ts +2 -2
  79. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +161 -0
  80. package/refreshUtils/RefreshCoordinator/index.ts +216 -0
  81. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  82. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  83. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  84. package/screenPickerUtils/index.ts +5 -0
  85. package/screenState/__tests__/index.test.ts +1 -1
  86. package/searchUtils/const.ts +7 -0
  87. package/searchUtils/index.ts +3 -0
  88. package/services/storageServiceSync.web.ts +1 -1
  89. package/stringUtils/index.ts +1 -1
  90. package/testUtils/index.tsx +1 -1
  91. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  92. package/time/__tests__/Timer.test.ts +236 -0
  93. package/typeGuards/__tests__/isString.test.ts +21 -0
  94. package/typeGuards/index.ts +4 -0
  95. package/utils/__tests__/clone.test.ts +158 -0
  96. package/utils/__tests__/mergeRight.test.ts +48 -0
  97. package/utils/__tests__/path.test.ts +7 -0
  98. package/utils/clone.ts +7 -0
  99. package/utils/index.ts +5 -1
  100. package/utils/mergeRight.ts +5 -0
  101. package/reactHooks/componentsMap/index.ts +0 -55
  102. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  103. 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
  /**
@@ -0,0 +1,122 @@
1
+ import { isNil, startsWith } from "@applicaster/zapp-react-native-utils/utils";
2
+
3
+ import {
4
+ QUICK_BRICK_CONTENT,
5
+ QUICK_BRICK_NAVBAR,
6
+ } from "@applicaster/quick-brick-core/const";
7
+
8
+ const isNavBar = (node) => startsWith(QUICK_BRICK_NAVBAR, node?.id);
9
+ const isContent = (node) => startsWith(QUICK_BRICK_CONTENT, node?.id);
10
+ const isRoot = (node) => node?.id === "root";
11
+
12
+ export const isPartOfTabsScreenContent = (
13
+ focusableTree,
14
+ screenPickerContentContainerId,
15
+ id
16
+ ) => {
17
+ const node = focusableTree.findInTree(id);
18
+
19
+ if (isNil(node)) {
20
+ return false;
21
+ }
22
+
23
+ if (isRoot(node)) {
24
+ return false;
25
+ }
26
+
27
+ if (isNavBar(node)) {
28
+ return false;
29
+ }
30
+
31
+ if (isContent(node)) {
32
+ return false;
33
+ }
34
+
35
+ if (node?.id === screenPickerContentContainerId) {
36
+ return true;
37
+ }
38
+
39
+ return isPartOfTabsScreenContent(
40
+ focusableTree,
41
+ screenPickerContentContainerId,
42
+ node.parent?.id
43
+ );
44
+ };
45
+
46
+ export const isPartOfMenu = (focusableTree, id): boolean => {
47
+ const node = focusableTree.findInTree(id);
48
+
49
+ if (isNil(node)) {
50
+ return false;
51
+ }
52
+
53
+ if (isRoot(node)) {
54
+ return false;
55
+ }
56
+
57
+ if (isNavBar(node)) {
58
+ return true;
59
+ }
60
+
61
+ if (isContent(node)) {
62
+ return false;
63
+ }
64
+
65
+ return isPartOfMenu(focusableTree, node.parent?.id);
66
+ };
67
+
68
+ export const isPartOfContent = (focusableTree, id) => {
69
+ const node = focusableTree.findInTree(id);
70
+
71
+ if (isNil(node)) {
72
+ return false;
73
+ }
74
+
75
+ if (isRoot(node)) {
76
+ return false;
77
+ }
78
+
79
+ if (isNavBar(node)) {
80
+ return false;
81
+ }
82
+
83
+ if (isContent(node)) {
84
+ return true;
85
+ }
86
+
87
+ return isPartOfContent(focusableTree, node.parent?.id);
88
+ };
89
+
90
+ export const isCurrentFocusOn = (id, node) => {
91
+ if (!node) {
92
+ return false;
93
+ }
94
+
95
+ if (isRoot(node)) {
96
+ return false;
97
+ }
98
+
99
+ if (node?.id === id) {
100
+ return true;
101
+ }
102
+
103
+ return isCurrentFocusOn(id, node.parent);
104
+ };
105
+
106
+ export const isChildOf = (focusableTree, childId, parentId) => {
107
+ if (isNil(childId) || isNil(parentId)) {
108
+ return false;
109
+ }
110
+
111
+ const childNode = focusableTree.findInTree(childId);
112
+
113
+ if (isNil(childNode)) {
114
+ return false;
115
+ }
116
+
117
+ if (childNode.parent?.id === parentId) {
118
+ return true;
119
+ }
120
+
121
+ return isChildOf(focusableTree, childNode.parent?.id, parentId);
122
+ };
@@ -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
 
@@ -1,7 +1,9 @@
1
1
  import { ReplaySubject, Subject } from "rxjs";
2
- import { filter, switchMap, take, map } from "rxjs/operators";
2
+ import { filter, switchMap, take, withLatestFrom, map } from "rxjs/operators";
3
+
3
4
  import { BUTTON_PREFIX } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/DefaultComponents/tv/TvActionButtons/const";
4
5
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager/index.ios";
6
+ import { isPartOfMenu, isPartOfContent } from "./index.ios";
5
7
 
6
8
  type FocusableID = string;
7
9
  type RegistrationEvent = {
@@ -104,9 +106,8 @@ const focusableNativeViewRegistration = ({ focusableView, focusableGroup }) => {
104
106
  );
105
107
  };
106
108
 
107
- export const firstFocusableViewRegistrationFactory = () =>
109
+ export const firstFocusableViewInContentRegistrationFactory = () =>
108
110
  focusableViewRegistrationSubject$.pipe(
109
- take(1), // we care about only first FocusableView registration
110
111
  switchMap((focusableView) =>
111
112
  // start waiting registration of its parent FocusableGroup
112
113
  focusableGroupRegistrationSubject$.pipe(
@@ -124,7 +125,11 @@ export const firstFocusableViewRegistrationFactory = () =>
124
125
  focusableView,
125
126
  focusableGroup,
126
127
  })
127
- )
128
+ ),
129
+ filter(({ focusableView }) =>
130
+ isPartOfContent(focusManager.focusableTree, focusableView.id)
131
+ ),
132
+ take(1) // we care about only first FocusableView registration
128
133
  );
129
134
 
130
135
  // registration on RN level(into RN focusManager)
@@ -175,3 +180,55 @@ export const emitNativeRegistered = ({
175
180
  focusableNativeGroupRegistrationSubject$.next({ id, groupId });
176
181
  }
177
182
  };
183
+
184
+ // /////
185
+
186
+ const focusedSubject$ = new Subject<FocusableID>();
187
+
188
+ const focused$ = focusedSubject$.asObservable();
189
+
190
+ export const emitFocused = (id: FocusableID): void => {
191
+ focusedSubject$.next(id);
192
+ };
193
+
194
+ export const topMenuItemFocused$ = focused$.pipe(
195
+ filter((id) => id && isPartOfMenu(focusManager.focusableTree, id))
196
+ );
197
+
198
+ export const contentFocused$ = focused$.pipe(
199
+ filter((id) => {
200
+ const isContent = isPartOfContent(focusManager.focusableTree, id);
201
+
202
+ return id && isContent;
203
+ })
204
+ );
205
+
206
+ const createFocusableRegistry = () => {
207
+ const subject$ = new ReplaySubject<FocusableID | undefined>(1);
208
+
209
+ return {
210
+ observable$: subject$.asObservable(),
211
+ register: (id: FocusableID) => {
212
+ // save focusable_id on registration
213
+ subject$.next(id);
214
+ },
215
+ unregister: () => {
216
+ // reset focusable_id on unregistration
217
+ subject$.next(undefined);
218
+ },
219
+ };
220
+ };
221
+
222
+ /// HOME_TOP_MENU_ITEM
223
+ export const HomeTopMenuItemRegistry = createFocusableRegistry();
224
+
225
+ export const homeTopMenuItemFocused$ = topMenuItemFocused$.pipe(
226
+ withLatestFrom(HomeTopMenuItemRegistry.observable$),
227
+ filter(([id, homeId]) => id === homeId)
228
+ );
229
+
230
+ /// SCREEN_PICKER
231
+ export const ScreenPickerContentContainerRegistry = createFocusableRegistry();
232
+
233
+ /// SEARCH_INPUT
234
+ export const SearchInputRegistry = createFocusableRegistry();
@@ -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 = () => {