@applicaster/zapp-react-native-utils 13.0.0-alpha.7120331332 → 13.0.0-alpha.7138263059

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 (93) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +59 -8
  4. package/alertUtils/alert.ts +148 -0
  5. package/alertUtils/index.ts +1 -148
  6. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  7. package/analyticsUtils/currentScreenProperities.ts +6 -4
  8. package/appUtils/HooksManager/Hook.ts +2 -2
  9. package/appUtils/HooksManager/index.ts +1 -1
  10. package/appUtils/HooksManager/types.ts +5 -2
  11. package/appUtils/accessibilityManager/index.ts +42 -1
  12. package/appUtils/contextKeysManager/contextResolver.ts +77 -0
  13. package/appUtils/contextKeysManager/index.ts +2 -2
  14. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  15. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
  16. package/appUtils/focusManager/index.ts +100 -65
  17. package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
  18. package/appUtils/focusManager/utils/enums.ts +4 -0
  19. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  20. package/appUtils/keyCodes/index.ts +11 -7
  21. package/appUtils/keyCodes/keys/keysByPlatform.ts +4 -0
  22. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  23. package/appUtils/platform/const.ts +14 -0
  24. package/appUtils/platform/platformUtils.ts +47 -4
  25. package/appUtils/playerManager/index.ts +1 -1
  26. package/appUtils/playerManager/player.ts +19 -7
  27. package/appUtils/playerManager/playerNative.ts +2 -1
  28. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  29. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  30. package/equalUtils/index.ts +49 -30
  31. package/focusManager/FocusManager.ts +11 -1
  32. package/focusManager/index.ts +41 -4
  33. package/functionUtils/index.ts +21 -8
  34. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  35. package/idleUtils/index.ts +1 -1
  36. package/idleUtils/withTimeout.ts +15 -2
  37. package/logger/const.ts +9 -67
  38. package/manifestUtils/__tests__/createConfig.test.js +0 -2
  39. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  40. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  41. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  42. package/navigationUtils/index.ts +3 -3
  43. package/numberUtils/index.ts +7 -5
  44. package/package.json +5 -6
  45. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
  46. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  47. package/reactHooks/cell-click/__tests__/index.test.js +5 -0
  48. package/reactHooks/cell-click/index.ts +7 -1
  49. package/reactHooks/feed/useFeedLoader.tsx +1 -1
  50. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  51. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  52. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  53. package/reactHooks/navigation/index.ts +7 -19
  54. package/reactHooks/navigation/useGetTabBarHeight.ts +1 -3
  55. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  56. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  57. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  58. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  59. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  60. package/reactHooks/player/const.ts +0 -4
  61. package/reactHooks/player/index.ts +0 -6
  62. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  63. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  64. package/reactHooks/usePluginConfiguration.ts +1 -1
  65. package/reactHooks/useSubscriberFor.ts +4 -3
  66. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  67. package/reactUtils/__tests__/reactUtils.test.js +1 -19
  68. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  69. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +6 -72
  70. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  71. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  72. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  73. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  74. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  75. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  76. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  77. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  78. package/reactUtils/createContext/helpers.ts +6 -1
  79. package/reactUtils/createContext/index.ts +11 -25
  80. package/reactUtils/index.ts +0 -11
  81. package/screenState/index.ts +24 -10
  82. package/testUtils/index.tsx +0 -10
  83. package/theme/index.ts +1 -1
  84. package/time/Timer.ts +5 -2
  85. package/types.ts +1 -0
  86. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  87. package/reactHooks/player/useAutoSeek.tsx +0 -87
  88. package/reactHooks/player/useSeek.tsx +0 -66
  89. package/reactHooks/player/useTapSeek.tsx +0 -58
  90. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  91. /package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +0 -0
  92. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
  93. /package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +0 -0
@@ -0,0 +1,77 @@
1
+ import { createLogger } from "../../logger";
2
+ import { ContextKeysManager } from "./index";
3
+ import * as R from "ramda";
4
+
5
+ const { log_error } = createLogger({
6
+ subsystem: "contextResolver",
7
+ category: "General",
8
+ });
9
+
10
+ interface IResolver {
11
+ resolve: (string) => Promise<string | number | object>;
12
+ }
13
+
14
+ export class EntryResolver implements IResolver {
15
+ entry: ZappEntry;
16
+
17
+ constructor(entry: ZappEntry) {
18
+ this.entry = entry;
19
+ }
20
+
21
+ async resolve(key: string) {
22
+ if (!key || key.length === 0) {
23
+ return this.entry;
24
+ }
25
+
26
+ return R.view(R.lensPath(key.split(".")), this.entry);
27
+ }
28
+ }
29
+
30
+ export class ContextResolver implements IResolver {
31
+ resolve = async (compositeKey: string) =>
32
+ ContextKeysManager.instance.getKey(compositeKey);
33
+ }
34
+
35
+ export const resolveObjectValues = async (
36
+ data: Record<string, any>,
37
+ resolvers: Record<string, IResolver> = null
38
+ ) => {
39
+ const entries = Object.entries(data);
40
+
41
+ const exResolvers = { ctx: new ContextResolver(), ...resolvers };
42
+
43
+ const resolvedEntries = await Promise.all(
44
+ entries.map(async ([key, value]) => {
45
+ if (typeof value !== "string") {
46
+ return [key, value];
47
+ }
48
+
49
+ if (!value.startsWith("@")) {
50
+ return [key, value];
51
+ }
52
+
53
+ const regex = /@{([^/]+)\/([^}]*)}/;
54
+
55
+ const match = (value as string).match(regex);
56
+
57
+ if (match) {
58
+ const contextResolverName = match[1];
59
+ const compositeKey = match[2];
60
+
61
+ const resolver = exResolvers[contextResolverName] || exResolvers.ctx;
62
+ const resolvedValue = await resolver.resolve(compositeKey);
63
+
64
+ return [key, resolvedValue];
65
+ }
66
+
67
+ log_error("resolveObjectValues: invalid context string", {
68
+ key,
69
+ value,
70
+ });
71
+
72
+ return [key, null];
73
+ })
74
+ );
75
+
76
+ return Object.fromEntries(resolvedEntries);
77
+ };
@@ -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,6 +28,7 @@ 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],
@@ -11,8 +11,9 @@ import {
11
11
  haveSameParentBeforeRoot,
12
12
  } from "./treeDataStructure/Utils";
13
13
  import { subscriber } from "../../functionUtils";
14
- import * as FOCUS_EVENTS from "./events";
15
14
  import { coreLogger } from "../../logger";
15
+ import { ACTION } from "./utils/enums";
16
+
16
17
  const logger = coreLogger.addSubsystem("focusManager");
17
18
 
18
19
  const isFocusEnabled = (focusableItem): boolean => {
@@ -167,13 +168,82 @@ export const focusManager = (function () {
167
168
  }
168
169
 
169
170
  /**
170
- * returns the current focusable's group
171
- * @private
172
- * @returns {React.Component} the current focus
171
+ * Computes the difference in parent groups between two nodes.
172
+ * It returns the IDs of parents that are present in the current node but not in the previous node,
173
+ * as well as the IDs of parents that are present in the previous node but not in the current node.
174
+ *
175
+ * @param {string} currentNodeID - The ID of the current node.
176
+ * @param {string} previousNodeID - The ID of the previous node.
177
+ * @returns {Object} An object containing the differences in parent IDs:
178
+ * - {Array<string>} currentNodeParentsIDs: Parent IDs present in the current node but not in the previous node.
179
+ * - {Array<string>} previousNodeParentsIDs: Parent IDs present in the previous node but not in the current node.
173
180
  */
174
- function getCurrentGroup() {
175
- return getGroupById(R.path(["props", "groupId"], getCurrentFocus()));
176
- }
181
+ const getParentDiffs = (currentNodeID, previousNodeID) => {
182
+ const currentNodeParentsIDs =
183
+ focusableTree.getParentGroupIds(currentNodeID);
184
+
185
+ const previousNodeParentsIDs =
186
+ focusableTree.getParentGroupIds(previousNodeID);
187
+
188
+ return {
189
+ currentNodeParentsIDs: R.difference(
190
+ currentNodeParentsIDs,
191
+ previousNodeParentsIDs
192
+ ),
193
+ previousNodeParentsIDs: R.difference(
194
+ previousNodeParentsIDs,
195
+ currentNodeParentsIDs
196
+ ),
197
+ };
198
+ };
199
+
200
+ /**
201
+ * Updates the focus state of nodes identified by their IDs.
202
+ * For each ID, if `setFocus` is true, the node will receive focus;
203
+ * otherwise, it will lose focus.
204
+ *
205
+ * @param {Array<string>} ids - An array of node IDs to update.
206
+ * @param {boolean} setFocus - A flag indicating whether to set focus (true) or blur (false) on the nodes.
207
+ */
208
+ const updateNodeFocus = (ids, action) => {
209
+ if (!ids || ids.length === 0) {
210
+ return; // Nothing to do
211
+ }
212
+
213
+ const startNode = focusableTree.findInTree(ids[0]);
214
+
215
+ if (!startNode) {
216
+ return; // Start node not found
217
+ }
218
+
219
+ const endNodeId = ids[ids.length - 1]; // Get the ID of the end node
220
+
221
+ let currentNode = startNode;
222
+
223
+ // Function to apply the action (focus or blur)
224
+ const applyAction = (node) => {
225
+ if (node && node.component) {
226
+ if (action === "focus") {
227
+ node.component.setFocus();
228
+ } else if (action === "blur") {
229
+ node.component.setBlur();
230
+ }
231
+ }
232
+ };
233
+
234
+ // Apply action to the starting node
235
+ applyAction(currentNode);
236
+
237
+ // Traverse upwards
238
+ while (currentNode && currentNode.id !== endNodeId) {
239
+ currentNode = currentNode.parent;
240
+
241
+ if (currentNode) {
242
+ // check if current node exists, as parent might be root
243
+ applyAction(currentNode);
244
+ }
245
+ }
246
+ };
177
247
 
178
248
  /**
179
249
  * Sets the current focus to the provided id. If there is an existing focus, it will
@@ -181,34 +251,29 @@ export const focusManager = (function () {
181
251
  * @private
182
252
  * @param {String} id of the focusable to set as currentFocus
183
253
  * @param {Object} direction of the navigation, which led to this focus change
184
- * @param {Object} options
185
- * @param {Boolean} options.groupFocusedChanged tells wether the focus has moved
186
254
  * to another group or not. defaults to false
187
255
  */
188
- function setFocus(
189
- id: string,
190
- direction?: FocusManager.Web.Direction,
191
- options?: Partial<{ groupFocusedChanged: boolean }>
192
- ) {
256
+ function setFocus(id: string, direction?: FocusManager.Web.Direction) {
193
257
  if (focusDisabled) return false;
194
258
 
195
- const { groupFocusedChanged = false } = options || {};
196
-
197
259
  // due to optimisiation it's recommanded to set currentFocusNode before setFocus
198
260
  // is called, so there will be no delays on tree search.
199
261
  // If currentFocusNode is null or undefined we still want it to findInTree
200
262
  if (currentFocusNode?.id !== id) {
263
+ const { currentNodeParentsIDs, previousNodeParentsIDs } = getParentDiffs(
264
+ id,
265
+ currentFocusNode?.id
266
+ );
267
+
268
+ // Set focus on current node parents and blur on previous node parents
269
+ updateNodeFocus(currentNodeParentsIDs, ACTION.FOCUS);
270
+ updateNodeFocus(previousNodeParentsIDs, ACTION.BLUR);
271
+
201
272
  currentFocusNode = focusableTree.findInTree(id);
202
273
  }
203
274
 
204
275
  setLastFocusOnParentNode(currentFocusNode);
205
276
 
206
- const currentGroup = getCurrentGroup();
207
-
208
- if (groupFocusedChanged && currentGroup) {
209
- currentGroup.hasLostFocus(currentGroup, direction);
210
- }
211
-
212
277
  focus(direction);
213
278
  }
214
279
 
@@ -251,6 +316,7 @@ export const focusManager = (function () {
251
316
  !focusableItem.isGroup &&
252
317
  isFocusEnabled(focusableItem)
253
318
  ) {
319
+ // TODO: Move this to setFocus method
254
320
  blur();
255
321
 
256
322
  logger.log({
@@ -260,8 +326,6 @@ export const focusManager = (function () {
260
326
  },
261
327
  });
262
328
 
263
- currentFocusNode = focusCandidate;
264
- focusableItem.willReceiveFocus(focusableItem, null);
265
329
  focusableItem && setFocus(focusCandidate.id, null);
266
330
 
267
331
  return { success: true };
@@ -281,6 +345,14 @@ export const focusManager = (function () {
281
345
  });
282
346
  }
283
347
 
348
+ function pressIn() {
349
+ const currentFocusable = getCurrentFocus();
350
+
351
+ if (currentFocusable) {
352
+ currentFocusable.pressIn(null);
353
+ }
354
+ }
355
+
284
356
  /**
285
357
  * calls the `press` method on the current focus component
286
358
  * @public
@@ -412,7 +484,7 @@ export const focusManager = (function () {
412
484
  function isCurrentFocusOnTheTopScreen() {
413
485
  const routes = R.pathOr([], ["root", "children"], focusableTree);
414
486
 
415
- if (routes.length <= 1) {
487
+ if (currentFocusNode && routes.length <= 1) {
416
488
  // there is only one or zero routes
417
489
  return true;
418
490
  }
@@ -448,20 +520,10 @@ export const focusManager = (function () {
448
520
  const nextRect = nextFocusable.component.getRect();
449
521
 
450
522
  if (nextRect && nextRect.width > 0) {
451
- nextFocusable.component.willReceiveFocus(
452
- nextFocusable.component,
453
- direction
454
- );
455
-
523
+ // TODO: Move this to setFocus method
456
524
  blur(direction);
457
525
 
458
- const groupChanged =
459
- nextFocusable.component.props.groupId !==
460
- currentFocusNode?.component?.props?.groupId;
461
-
462
- setFocus(nextFocusable.id, direction, {
463
- groupFocusedChanged: groupChanged,
464
- });
526
+ setFocus(nextFocusable.id, direction);
465
527
  }
466
528
  } else {
467
529
  currentFocusNode.component.failedLostFocus(currentFocusNode, direction);
@@ -481,34 +543,6 @@ export const focusManager = (function () {
481
543
 
482
544
  const { on, invokeHandler, removeHandler } = eventHandler;
483
545
 
484
- on(FOCUS_EVENTS.FOCUS, (focusable, direction) => {
485
- if (focusable.props.groupId) {
486
- const parent = focusableTree.findInTree(focusable.props.groupId);
487
- parent?.component?.onFocus(focusable.component, direction);
488
- }
489
- });
490
-
491
- on(FOCUS_EVENTS.BLUR, (focusable, direction) => {
492
- if (focusable.props.groupId) {
493
- const parent = focusableTree.findInTree(focusable.props.groupId);
494
- parent?.component?.onBlur(focusable.component, direction);
495
- }
496
- });
497
-
498
- on(FOCUS_EVENTS.HAS_LOST_FOCUS, (focusable, direction) => {
499
- if (focusable.props.groupId) {
500
- const parent = focusableTree.findInTree(focusable.props.groupId);
501
- parent?.component?.hasLostFocus(parent.component, direction);
502
- }
503
- });
504
-
505
- on(FOCUS_EVENTS.WILL_RECEIVE_FOCUS, (focusable, direction) => {
506
- if (focusable.props.groupId) {
507
- const parent = focusableTree.findInTree(focusable.props.groupId);
508
- parent?.component?.willReceiveFocus(focusable.component, direction);
509
- }
510
- });
511
-
512
546
  /**
513
547
  * this is the list of the functions available externally
514
548
  * when importing the focus manager
@@ -526,6 +560,7 @@ export const focusManager = (function () {
526
560
  invokeHandler,
527
561
  removeHandler,
528
562
  longPress,
563
+ pressIn,
529
564
  pressOut,
530
565
  enableFocus,
531
566
  setInitialFocus,
@@ -231,4 +231,27 @@ export class Tree {
231
231
 
232
232
  return retVal;
233
233
  }
234
+
235
+ /**
236
+ * Gets the IDs of all parent groups for a given node id.
237
+ * @public
238
+ * @param {String} nodeId - The id of the node to get parent IDs for.
239
+ * @returns {Array} An array of parent group IDs or an empty array if the node is not found.
240
+ */
241
+ getParentGroupIds(nodeId) {
242
+ const parentIds = [];
243
+ let currentNode = this.findInTree(nodeId);
244
+
245
+ if (!currentNode) {
246
+ return []; // Node not found, return an empty array
247
+ }
248
+
249
+ // Traverse up the tree, collecting parent IDs
250
+ while (currentNode.parent && currentNode.parent.id !== "root") {
251
+ parentIds.push(currentNode.parent.id);
252
+ currentNode = currentNode.parent;
253
+ }
254
+
255
+ return parentIds;
256
+ }
234
257
  }
@@ -0,0 +1,4 @@
1
+ export enum ACTION {
2
+ FOCUS = "focus",
3
+ BLUR = "blur",
4
+ }
@@ -1,8 +1,8 @@
1
1
  import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
2
- import { find, last, startsWith, pathOr } from "ramda";
2
+ import { find, last, pathOr, startsWith } from "ramda";
3
3
  import {
4
- QUICK_BRICK_NAVBAR,
5
4
  QUICK_BRICK_CONTENT,
5
+ QUICK_BRICK_NAVBAR,
6
6
  } from "@applicaster/quick-brick-core/const";
7
7
 
8
8
  // run check each 300 ms
@@ -66,7 +66,8 @@ export const getContentNode = (focusableTree) => {
66
66
  const content = find(
67
67
  (child) =>
68
68
  startsWith(QUICK_BRICK_CONTENT, child.id) ||
69
- startsWith("player", child.id),
69
+ startsWith("player", child.id) ||
70
+ startsWith("/hooks", child?.parent?.id), // For startup hooks case
70
71
  getActiveScreenChildren(focusableTree)
71
72
  );
72
73
 
@@ -1,5 +1,3 @@
1
- import * as R from "ramda";
2
-
3
1
  // more keys can be added here. Simply make sure
4
2
  // the key matches the code value
5
3
 
@@ -34,12 +32,18 @@ export function keyCode(key) {
34
32
  keyCode(keyEvent).matchesAny("Enter", "Backspace", KEYS.ArrowLeft, ...)
35
33
  */
36
34
 
37
- const matches = R.compose(
38
- R.either(R.eqProps("code", key), R.eqProps("keyCode", key)),
39
- R.when(R.is(String), R.prop(R.__, KEYS))
40
- );
35
+ const matches = (compareKey) => {
36
+ // If compareKey is a string, look it up in KEYS object
37
+ const keyToCompare =
38
+ typeof compareKey === "string" ? KEYS[compareKey] : compareKey;
39
+
40
+ // Compare either code or keyCode properties
41
+ return (
42
+ keyToCompare?.code === key.code || keyToCompare?.keyCode === key.keyCode
43
+ );
44
+ };
41
45
 
42
- const matchesAny = (...args) => R.any(matches, args);
46
+ const matchesAny = (...args) => args.some(matches);
43
47
 
44
48
  const direction = () =>
45
49
  matchesAny(...ARROW_KEYS) ? directionHelper(key) : null;
@@ -77,6 +77,10 @@ const web = {
77
77
  Exit: { code: "Exit", keyCode: null },
78
78
  Escape: { code: "Escape", keyCode: 27 },
79
79
  EscapeDevice: { code: "Escape", keyCode: 27 },
80
+ // For Debugging
81
+ Z: { code: "KeyZ", keyCode: 90 }, // Hardware Backward Button
82
+ X: { code: "KeyX", keyCode: 88 }, // Hardware Enter Button
83
+ C: { code: "KeyC", keyCode: 67 }, // Hardware Forward Button
80
84
  };
81
85
 
82
86
  const android_tv = {
@@ -0,0 +1,68 @@
1
+ export type SeekKeyHandlerListener = {
2
+ onRewindPress: () => boolean;
3
+ onForwardPress: () => boolean;
4
+ onRewindPressOut: () => void;
5
+ onForwardPressOut: () => void;
6
+ };
7
+
8
+ export class KeyInputHandler {
9
+ private static instance: KeyInputHandler;
10
+
11
+ public static getInstance() {
12
+ if (!KeyInputHandler.instance) {
13
+ KeyInputHandler.instance = new KeyInputHandler();
14
+ }
15
+
16
+ return KeyInputHandler.instance;
17
+ }
18
+
19
+ constructor() {
20
+ this.listeners = [];
21
+ }
22
+
23
+ private listeners: SeekKeyHandlerListener[] = [];
24
+
25
+ addListener = (listener: SeekKeyHandlerListener) => {
26
+ this.listeners.splice(0, 0, listener);
27
+
28
+ return () => this.removeListener(listener);
29
+ };
30
+
31
+ removeListener = (listener: SeekKeyHandlerListener) => {
32
+ this.listeners = this.listeners.filter((l) => l !== listener);
33
+ };
34
+
35
+ onRewindPress = () => {
36
+ for (const element of this.listeners) {
37
+ if (element.onRewindPress()) {
38
+ break;
39
+ }
40
+ }
41
+ };
42
+
43
+ onForwardPress = () => {
44
+ for (const element of this.listeners) {
45
+ if (element.onForwardPress()) {
46
+ break;
47
+ }
48
+ }
49
+ };
50
+
51
+ // TODO: Event should be send to listeners who handled down event
52
+ onRewindPressOut = () => {
53
+ this.listeners.forEach((listener) => listener.onRewindPressOut());
54
+ };
55
+
56
+ onForwardPressOut = () => {
57
+ this.listeners.forEach((listener) => listener.onForwardPressOut());
58
+ };
59
+
60
+ getSeekMethods = () => {
61
+ return {
62
+ onForwardPress: this.onForwardPress,
63
+ onRewindPress: this.onRewindPress,
64
+ onForwardPressOut: this.onForwardPressOut,
65
+ onRewindPressOut: this.onRewindPressOut,
66
+ };
67
+ };
68
+ }
@@ -23,3 +23,17 @@ export const PLATFORMS = {
23
23
  export const PLATFORM_KEYS = {
24
24
  deviceClosedCaptioningEnabled: "device_closed_captioning_enabled",
25
25
  };
26
+
27
+ export enum ZappPlatform {
28
+ Android = "android",
29
+ AndroidTV = "android_tv",
30
+ AmazonFireTV = "amazon",
31
+ iOS = "ios",
32
+ tvOS = "tvos",
33
+ Roku = "roku",
34
+ Tizen = "tizen",
35
+ Web = "web",
36
+ WebOS = "webos",
37
+ Vizio = "vizio",
38
+ Unknown = "unknown",
39
+ }
@@ -6,8 +6,10 @@ import {
6
6
  isSamsungPlatform,
7
7
  } from "@applicaster/zapp-react-dom-app/App/Loader/utils/platform";
8
8
 
9
- import { PLATFORM_KEYS, PLATFORMS } from "./const";
9
+ import { PLATFORM_KEYS, PLATFORMS, ZappPlatform } from "./const";
10
10
  import { createLogger, utilsLogger } from "../../logger";
11
+ import { getPlatform } from "../../reactUtils";
12
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
11
13
 
12
14
  const { log_debug } = createLogger({
13
15
  category: "General",
@@ -15,6 +17,20 @@ const { log_debug } = createLogger({
15
17
  parent: utilsLogger,
16
18
  });
17
19
 
20
+ export const getZappPlatform = (): ZappPlatform => {
21
+ const platform = appStore.get("appData")?.platform;
22
+
23
+ switch (platform) {
24
+ case "amazon_fire_tv":
25
+ return ZappPlatform.AmazonFireTV;
26
+ case ZappPlatform.Vizio:
27
+ return ZappPlatform.Vizio;
28
+ default:
29
+ // TODO: Use only ZappPlatform enum
30
+ return getPlatform() as ZappPlatform;
31
+ }
32
+ };
33
+
18
34
  export const getUserAgent = () => window?.navigator?.userAgent;
19
35
 
20
36
  /** VIZIO UTILS */
@@ -61,13 +77,22 @@ export class ClosedCaptioningManager {
61
77
 
62
78
  private constructor() {
63
79
  this.initialize();
80
+
81
+ window["vizioDebug"] = {
82
+ setCCEnabled: (isCCEnabled: boolean) => {
83
+ this.ccState$.next(isCCEnabled);
84
+ },
85
+ };
64
86
  }
65
87
 
66
88
  static getInstance(): ClosedCaptioningManager {
67
89
  if (!ClosedCaptioningManager.ccManagerInstance) {
90
+ log_debug("ClosedCaptioningManager: Creating new instance");
68
91
  ClosedCaptioningManager.ccManagerInstance = new ClosedCaptioningManager();
69
92
  }
70
93
 
94
+ log_debug("ClosedCaptioningManager: Returning existing instance");
95
+
71
96
  return ClosedCaptioningManager.ccManagerInstance;
72
97
  }
73
98
 
@@ -76,23 +101,41 @@ export class ClosedCaptioningManager {
76
101
  PLATFORM_KEYS.deviceClosedCaptioningEnabled
77
102
  );
78
103
 
79
- log_debug("Initializing closed captioning manager", { existingState });
80
-
81
104
  if (existingState !== null) {
105
+ log_debug(
106
+ `ClosedCaptioningManager: Setting initial state to ${existingState}`
107
+ );
108
+
82
109
  this.ccState$.next(existingState === "true" || existingState === true);
110
+ } else {
111
+ log_debug("ClosedCaptioningManager: No existing state found");
83
112
  }
84
113
 
85
114
  if (hasVizioAPIs()) {
115
+ log_debug("ClosedCaptioningManager: Setting closed captioning handler");
116
+
86
117
  window.VIZIO!.setClosedCaptionHandler((isCCEnabled) => {
87
- log_debug("CC state changed", { isCCEnabled });
118
+ log_debug(
119
+ "ClosedCaptioningManager: There was a change in the CC state",
120
+ { isCCEnabled }
121
+ );
88
122
 
89
123
  sessionStorage.setItem(
90
124
  PLATFORM_KEYS.deviceClosedCaptioningEnabled,
91
125
  isCCEnabled
92
126
  );
93
127
 
128
+ log_debug(
129
+ "ClosedCaptioningManager: Saved CC state to session storage",
130
+ { isCCEnabled }
131
+ );
132
+
94
133
  this.ccState$.next(isCCEnabled);
95
134
  });
135
+ } else {
136
+ log_debug(
137
+ "ClosedCaptioningManager: Vizio APIs are not available, skipping setup"
138
+ );
96
139
  }
97
140
  }
98
141
 
@@ -452,7 +452,7 @@ export class PlayerManager {
452
452
  if (this.castingReceiver) {
453
453
  this.castingReceiver.closeNativePlayer();
454
454
  } else {
455
- this.getActivePlayer().closeNativePlayer();
455
+ this.getActivePlayer()?.closeNativePlayer();
456
456
  this.invokeHandler("close");
457
457
  }
458
458
  }