@applicaster/zapp-react-native-utils 13.0.0-alpha.1360301199 → 13.0.0-alpha.1400045041

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 (57) hide show
  1. package/README.md +0 -10
  2. package/analyticsUtils/currentScreenProperities.ts +6 -4
  3. package/appUtils/HooksManager/Hook.ts +2 -2
  4. package/appUtils/HooksManager/types.ts +2 -2
  5. package/appUtils/contextKeysManager/contextResolver.ts +6 -2
  6. package/appUtils/contextKeysManager/index.ts +2 -2
  7. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  8. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -0
  9. package/appUtils/focusManager/__tests__/focusManager.test.js +82 -0
  10. package/appUtils/focusManager/__tests__/index.test.ts +1 -0
  11. package/appUtils/focusManager/index.ts +25 -5
  12. package/appUtils/focusManager/utils/index.ts +14 -0
  13. package/appUtils/focusManagerAux/index.ts +2 -2
  14. package/appUtils/platform/platformUtils.ts +30 -3
  15. package/appUtils/playerManager/player.ts +2 -2
  16. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  17. package/equalUtils/index.ts +49 -30
  18. package/focusManager/FocusManager.ts +11 -1
  19. package/focusManager/index.ts +41 -4
  20. package/manifestUtils/__tests__/createConfig.test.js +0 -2
  21. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  22. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  23. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  24. package/navigationUtils/index.ts +3 -3
  25. package/package.json +4 -6
  26. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  27. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  28. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  29. package/reactHooks/navigation/index.ts +7 -19
  30. package/reactHooks/navigation/useGetTabBarHeight.ts +1 -3
  31. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  32. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  33. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  34. package/reactHooks/usePluginConfiguration.ts +1 -1
  35. package/reactHooks/useSubscriberFor.ts +4 -3
  36. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  37. package/reactUtils/__tests__/reactUtils.test.js +1 -19
  38. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  39. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +6 -72
  40. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  41. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  42. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  43. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  44. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  45. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  46. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  47. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  48. package/reactUtils/createContext/helpers.ts +6 -1
  49. package/reactUtils/createContext/index.ts +11 -25
  50. package/reactUtils/index.ts +0 -11
  51. package/screenState/index.ts +24 -10
  52. package/testUtils/index.tsx +0 -10
  53. package/theme/index.ts +1 -1
  54. package/time/Timer.ts +4 -1
  55. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  56. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  57. /package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +0 -0
package/README.md CHANGED
@@ -376,16 +376,6 @@ useEffect(() => {
376
376
  }, []);
377
377
  ```
378
378
 
379
- ### testUtils
380
-
381
- `@applicaster/zapp-react-native-utils/testUtils`
382
-
383
- - `testIDEquals: (testId: any) => boolean | { width: number, height: number }` - Function to be used in tandem with enzyme findWhere
384
-
385
- ```javascript
386
- wrapper.findWhere(testIDEquals("text"));
387
- ```
388
-
389
379
  ### appUtils - contextKeysManager
390
380
 
391
381
  `@applicaster/zapp-react-native-utils/appUtils/contextKeyManager`
@@ -72,12 +72,14 @@ const mappedScreenPropertiesScreen = (
72
72
  screenData
73
73
  ): AnalyticsScreenProperties => {
74
74
  return {
75
- screen_name: screenData?.targetScreen?.name,
75
+ screen_name: screenData?.targetScreen?.name || screenData?.name,
76
76
  screen_entry_title: screenData?.title,
77
77
  screen_entry_id: R.isNil(screenData?.type) ? null : screenData?.id,
78
- screen_layout_id: screenData?.targetScreen?.id,
79
- screen_type: screenData?.targetScreen?.type,
80
- home_screen: screenData?.targetScreen?.home,
78
+ screen_layout_id: screenData?.targetScreen?.id || screenData?.id,
79
+ screen_type: screenData?.targetScreen?.type || screenData?.type,
80
+ home_screen: !R.isNil(screenData?.targetScreen?.home)
81
+ ? screenData?.targetScreen?.home
82
+ : screenData?.home,
81
83
  };
82
84
  };
83
85
 
@@ -16,7 +16,7 @@ const BASE_HOOK_PROPERTIES = ["screen_id", "identifier", "weight"];
16
16
  * @returns {number} index
17
17
  */
18
18
  const hookState: (
19
- arg0: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS]
19
+ arg0: (typeof HOOKS_EVENTS)[keyof typeof HOOKS_EVENTS]
20
20
  ) => number = R.indexOf(R.__, R.values(HOOKS_EVENTS));
21
21
 
22
22
  /**
@@ -62,7 +62,7 @@ export class Hook implements HookInterface {
62
62
  * @param {Array<Any>} args variadic arguments to invoke the handler with
63
63
  */
64
64
  setStateAndNotify(
65
- event: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS],
65
+ event: (typeof HOOKS_EVENTS)[keyof typeof HOOKS_EVENTS],
66
66
  ...args
67
67
  ) {
68
68
  this.state = hookState(event);
@@ -103,7 +103,7 @@ export interface Hook<T extends HookModule = HookModule> {
103
103
  identifier: string;
104
104
  configuration: T["configuration"];
105
105
  setStateAndNotify(
106
- event: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS],
106
+ event: (typeof HOOKS_EVENTS)[keyof typeof HOOKS_EVENTS],
107
107
  opts: {
108
108
  error?: typeof Error;
109
109
  route?: string;
@@ -112,7 +112,7 @@ export interface Hook<T extends HookModule = HookModule> {
112
112
  }
113
113
  );
114
114
  general?: {
115
- transition_type: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS];
115
+ transition_type: (typeof HOOKS_EVENTS)[keyof typeof HOOKS_EVENTS];
116
116
  allow_screen_plugin_presentation: boolean;
117
117
  is_flow_blocker: boolean;
118
118
  };
@@ -42,12 +42,16 @@ export const resolveObjectValues = async (
42
42
 
43
43
  const resolvedEntries = await Promise.all(
44
44
  entries.map(async ([key, value]) => {
45
- const regex = /@{([^/]+)\/([^}]*)}/;
46
-
47
45
  if (typeof value !== "string") {
48
46
  return [key, value];
49
47
  }
50
48
 
49
+ if (!value.startsWith("@")) {
50
+ return [key, value];
51
+ }
52
+
53
+ const regex = /@{([^/]+)\/([^}]*)}/;
54
+
51
55
  const match = (value as string).match(regex);
52
56
 
53
57
  if (match) {
@@ -16,12 +16,12 @@ import {
16
16
 
17
17
  export { StorageLevel };
18
18
 
19
- type KeyNameObj = {
19
+ export type KeyNameObj = {
20
20
  namespace: string;
21
21
  key: string;
22
22
  };
23
23
 
24
- type KeyName = string | KeyNameObj;
24
+ export type KeyName = string | KeyNameObj;
25
25
 
26
26
  type ParsedKeyAndNamespace = {
27
27
  namespace?: string;
@@ -1,10 +1,11 @@
1
1
  import * as R from "ramda";
2
2
  import { DEFAULT_NAMESPACE } from "../consts";
3
+ import { KeyName, KeyNameObj } from "../index";
3
4
 
4
5
  const lastDotRegex = /\.([^.]+)$/;
5
6
  const splitByLastDot = R.compose(R.init, R.split(lastDotRegex));
6
7
 
7
- export function getNamespaceAndKey(namespacedKey) {
8
+ export function getNamespaceAndKey(namespacedKey: KeyName): KeyNameObj {
8
9
  if (typeof namespacedKey !== "string") return namespacedKey;
9
10
 
10
11
  const namespacedKeyProps = namespacedKey.includes(".")
@@ -28,10 +28,12 @@ exports[`focusManager should be defined 1`] = `
28
28
  "moveFocus": [Function],
29
29
  "on": [Function],
30
30
  "press": [Function],
31
+ "pressIn": [Function],
31
32
  "pressOut": [Function],
32
33
  "recoverFocus": [Function],
33
34
  "register": [Function],
34
35
  "removeHandler": [Function],
36
+ "resetFocus": [Function],
35
37
  "setFocus": [Function],
36
38
  "setInitialFocus": [Function],
37
39
  "unregister": [Function],
@@ -1,5 +1,6 @@
1
1
  import { focusManager } from "../index.ts";
2
2
  import { focusManager as focusManagerIOS } from "../index.ios.ts";
3
+ import { findFirstFocusableItem } from "../utils";
3
4
 
4
5
  describe("focusManagerIOS", () => {
5
6
  it("should be defined", () => {
@@ -8,6 +9,67 @@ describe("focusManagerIOS", () => {
8
9
  });
9
10
  });
10
11
 
12
+ const focusableTree = {
13
+ root: {
14
+ children: [
15
+ {
16
+ children: [
17
+ {
18
+ children: [
19
+ {
20
+ children: [],
21
+ component: {
22
+ isGroup: true,
23
+ },
24
+ id: "route/1/1",
25
+ },
26
+ {
27
+ children: [],
28
+ component: {
29
+ isGroup: true,
30
+ },
31
+ id: "route/1/2",
32
+ },
33
+ ],
34
+ component: {
35
+ isGroup: true,
36
+ },
37
+ id: "route/1",
38
+ },
39
+ {
40
+ children: [
41
+ {
42
+ children: [],
43
+ component: {
44
+ isGroup: true,
45
+ },
46
+ id: "route/2/1",
47
+ },
48
+ {
49
+ children: [],
50
+ component: {
51
+ isGroup: false,
52
+ },
53
+ id: "route/2/2",
54
+ },
55
+ ],
56
+ component: {
57
+ isGroup: true,
58
+ },
59
+ id: "route/2",
60
+ },
61
+ ],
62
+ component: {
63
+ isGroup: true,
64
+ },
65
+ id: "/river/1234",
66
+ },
67
+ ],
68
+ component: null,
69
+ id: "root",
70
+ },
71
+ };
72
+
11
73
  describe("focusManager", () => {
12
74
  it("should be defined", () => {
13
75
  expect(focusManager).toBeDefined();
@@ -45,4 +107,24 @@ describe("focusManager", () => {
45
107
  it("placeholder test", () => {
46
108
  expect(true).toBe(true);
47
109
  });
110
+
111
+ it("findFirstFocusableItem returns focusableItem", () => {
112
+ const expectedItemId =
113
+ focusableTree.root.children[0].children[1].children[1].id;
114
+
115
+ const focusableItem = findFirstFocusableItem(focusableTree.root.children);
116
+
117
+ expect(
118
+ focusableItem !== undefined && expectedItemId === focusableItem.id
119
+ ).toBe(true);
120
+ });
121
+
122
+ it("findFirstFocusableItem does not return focusableItem", () => {
123
+ focusableTree.root.children[0].children[1].children[1].component.isGroup =
124
+ true;
125
+
126
+ const focusableItem = findFirstFocusableItem(focusableTree.root.children);
127
+
128
+ expect(focusableItem === undefined).toBe(true);
129
+ });
48
130
  });
@@ -30,6 +30,7 @@ describe("focusManager", () => {
30
30
  "isGroupItemFocused",
31
31
  "recoverFocus",
32
32
  "isCurrentFocusOnTheTopScreen",
33
+ "resetFocus",
33
34
  ];
34
35
 
35
36
  expectedMethods.forEach((method) => {
@@ -13,6 +13,7 @@ import {
13
13
  import { subscriber } from "../../functionUtils";
14
14
  import { coreLogger } from "../../logger";
15
15
  import { ACTION } from "./utils/enums";
16
+ import { findFirstFocusableItem } from "./utils";
16
17
 
17
18
  const logger = coreLogger.addSubsystem("focusManager");
18
19
 
@@ -326,8 +327,6 @@ export const focusManager = (function () {
326
327
  },
327
328
  });
328
329
 
329
- currentFocusNode = focusCandidate;
330
-
331
330
  focusableItem && setFocus(focusCandidate.id, null);
332
331
 
333
332
  return { success: true };
@@ -347,6 +346,14 @@ export const focusManager = (function () {
347
346
  });
348
347
  }
349
348
 
349
+ function pressIn() {
350
+ const currentFocusable = getCurrentFocus();
351
+
352
+ if (currentFocusable) {
353
+ currentFocusable.pressIn(null);
354
+ }
355
+ }
356
+
350
357
  /**
351
358
  * calls the `press` method on the current focus component
352
359
  * @public
@@ -486,20 +493,29 @@ export const focusManager = (function () {
486
493
  return haveSameParentBeforeRoot(currentFocusNode, R.last(routes));
487
494
  }
488
495
 
489
- function recoverFocus() {
496
+ function resetFocus() {
490
497
  if (!isCurrentFocusOnTheTopScreen()) {
491
- // We've failed to set focused node on the new screen => run focus recovery
498
+ // We've failed to set focused node on the new screen => run focus reset
492
499
  setInitialFocus();
493
500
  }
494
501
  }
495
502
 
503
+ /**
504
+ * sets the focus on first focusable item
505
+ * @public
506
+ */
507
+ function recoverFocus() {
508
+ const focusableItem = findFirstFocusableItem(focusableTree.root.children);
509
+ focusableItem && setFocus(focusableItem.id);
510
+ }
511
+
496
512
  /**
497
513
  * moves the focus in a provided direction
498
514
  * @public
499
515
  * @param {Object} direction of the scroll
500
516
  */
501
517
  function moveFocus(direction) {
502
- if (!isCurrentFocusOnTheTopScreen()) {
518
+ if (!isCurrentFocusOnTheTopScreen() && currentFocusNode) {
503
519
  // We are opening new screen. We need to ignore movement of focus.
504
520
  return false;
505
521
  }
@@ -522,6 +538,8 @@ export const focusManager = (function () {
522
538
  } else {
523
539
  currentFocusNode.component.failedLostFocus(currentFocusNode, direction);
524
540
  }
541
+ } else {
542
+ recoverFocus();
525
543
  }
526
544
  }
527
545
 
@@ -554,6 +572,7 @@ export const focusManager = (function () {
554
572
  invokeHandler,
555
573
  removeHandler,
556
574
  longPress,
575
+ pressIn,
557
576
  pressOut,
558
577
  enableFocus,
559
578
  setInitialFocus,
@@ -565,5 +584,6 @@ export const focusManager = (function () {
565
584
  isGroupItemFocused,
566
585
  recoverFocus,
567
586
  isCurrentFocusOnTheTopScreen,
587
+ resetFocus,
568
588
  };
569
589
  })();
@@ -98,3 +98,17 @@ export const waitForContent = (focusableTree) => {
98
98
  conditionFn: contentHasAnyChildren,
99
99
  });
100
100
  };
101
+
102
+ export const findFirstFocusableItem = (items) => {
103
+ for (const item of items) {
104
+ if (!item.component.isGroup) {
105
+ return item;
106
+ } else {
107
+ if (item.children) {
108
+ const focusableItem = findFirstFocusableItem(item.children);
109
+
110
+ if (focusableItem) return focusableItem;
111
+ }
112
+ }
113
+ }
114
+ };
@@ -54,7 +54,7 @@ export async function setFocusOnContent(currentRoute: string) {
54
54
  // For doing it we have to wait registration of first focusable node into focusableTree
55
55
  // we wait until content node starts having children
56
56
 
57
- const { setInitialFocus, focusableTree } = focusManager;
57
+ const { setInitialFocus, focusableTree, getCurrentFocus } = focusManager;
58
58
 
59
59
  try {
60
60
  await waitForActiveScreen(currentRoute, focusableTree);
@@ -71,6 +71,6 @@ export async function setFocusOnContent(currentRoute: string) {
71
71
  );
72
72
  }
73
73
  } catch (error) {
74
- setFocusOnContent(currentRoute);
74
+ !getCurrentFocus() && setFocusOnContent(currentRoute);
75
75
  }
76
76
  }
@@ -77,13 +77,22 @@ export class ClosedCaptioningManager {
77
77
 
78
78
  private constructor() {
79
79
  this.initialize();
80
+
81
+ window["vizioDebug"] = {
82
+ setCCEnabled: (isCCEnabled: boolean) => {
83
+ this.ccState$.next(isCCEnabled);
84
+ },
85
+ };
80
86
  }
81
87
 
82
88
  static getInstance(): ClosedCaptioningManager {
83
89
  if (!ClosedCaptioningManager.ccManagerInstance) {
90
+ log_debug("ClosedCaptioningManager: Creating new instance");
84
91
  ClosedCaptioningManager.ccManagerInstance = new ClosedCaptioningManager();
85
92
  }
86
93
 
94
+ log_debug("ClosedCaptioningManager: Returning existing instance");
95
+
87
96
  return ClosedCaptioningManager.ccManagerInstance;
88
97
  }
89
98
 
@@ -92,23 +101,41 @@ export class ClosedCaptioningManager {
92
101
  PLATFORM_KEYS.deviceClosedCaptioningEnabled
93
102
  );
94
103
 
95
- log_debug("Initializing closed captioning manager", { existingState });
96
-
97
104
  if (existingState !== null) {
105
+ log_debug(
106
+ `ClosedCaptioningManager: Setting initial state to ${existingState}`
107
+ );
108
+
98
109
  this.ccState$.next(existingState === "true" || existingState === true);
110
+ } else {
111
+ log_debug("ClosedCaptioningManager: No existing state found");
99
112
  }
100
113
 
101
114
  if (hasVizioAPIs()) {
115
+ log_debug("ClosedCaptioningManager: Setting closed captioning handler");
116
+
102
117
  window.VIZIO!.setClosedCaptionHandler((isCCEnabled) => {
103
- log_debug("CC state changed", { isCCEnabled });
118
+ log_debug(
119
+ "ClosedCaptioningManager: There was a change in the CC state",
120
+ { isCCEnabled }
121
+ );
104
122
 
105
123
  sessionStorage.setItem(
106
124
  PLATFORM_KEYS.deviceClosedCaptioningEnabled,
107
125
  isCCEnabled
108
126
  );
109
127
 
128
+ log_debug(
129
+ "ClosedCaptioningManager: Saved CC state to session storage",
130
+ { isCCEnabled }
131
+ );
132
+
110
133
  this.ccState$.next(isCCEnabled);
111
134
  });
135
+ } else {
136
+ log_debug(
137
+ "ClosedCaptioningManager: Vizio APIs are not available, skipping setup"
138
+ );
112
139
  }
113
140
  }
114
141
 
@@ -154,8 +154,8 @@ export class Player {
154
154
  this.isSeeking()
155
155
  ? this.playerState.seekPosition
156
156
  : this.playerState.adState
157
- ? this.playerState.adState.adPosition
158
- : this.playerState.contentPosition;
157
+ ? this.playerState.adState.adPosition
158
+ : this.playerState.contentPosition;
159
159
 
160
160
  getEntry = (): ZappEntry | null => this.entry;
161
161