@applicaster/zapp-react-native-utils 17.0.0-alpha.2451166845 → 17.0.0-alpha.3111286799

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.
@@ -2,6 +2,7 @@
2
2
  import { ActionResult } from "../ActionExecutor";
3
3
  import { ActionHandler, ActionExecutionContext } from "../types";
4
4
  import { createLogger } from "../../logger";
5
+ import { getTypeMappingCase } from "../../navigationUtils";
5
6
 
6
7
  const { log_info, log_error } = createLogger({
7
8
  subsystem: "core/actions",
@@ -96,20 +97,22 @@ export function createNavigateToScreenAction(
96
97
  const screenId = contentTypes?.[screenType]?.screen_id || null;
97
98
  const river = rivers?.[screenId];
98
99
 
99
- if (!screenId) {
100
+ if (!river) {
100
101
  log_error(
101
- `navigateToScreen: can not resolve screen type mapping: ${screenType}`
102
+ `navigateToScreen: can not resolve screen type mapping: ${screenType}`,
103
+ {
104
+ // For X-Ray diagnostics: keep when the message is reworded.
105
+ diagnostic: {
106
+ code: "action-type-mapping",
107
+ case: getTypeMappingCase(screenType, rivers, contentTypes),
108
+ },
109
+ type_mapping: screenType,
110
+ }
102
111
  );
103
112
 
104
113
  return ActionResult.Error;
105
114
  }
106
115
 
107
- if (!river) {
108
- log_error("navigateToScreen: can not resolve river");
109
-
110
- return ActionResult.Error;
111
- }
112
-
113
116
  navigatingEntry = river;
114
117
  }
115
118
 
@@ -121,8 +121,16 @@ export function HooksManager({
121
121
  `Could not find hook plugin ${identifier} - skipping execution`;
122
122
 
123
123
  return function () {
124
- logHookEvent(hooksManagerLogger.warn, hookMessage(hook.identifier), {
125
- hook,
124
+ // Not through logHookEvent: it drops data outside __DEV__, and the code and the identifier
125
+ // are what the X-Ray diagnostics read on QA builds.
126
+ hooksManagerLogger.warn({
127
+ message: hookMessage(hook.identifier),
128
+ data: {
129
+ diagnostic: { code: "hook-plugin-missing" },
130
+ identifier: hook.identifier,
131
+ screen_id: targetScreen.id,
132
+ ...(__DEV__ ? { hook } : {}),
133
+ },
126
134
  });
127
135
 
128
136
  return null;
@@ -0,0 +1,137 @@
1
+ const mockLogger = {
2
+ debug: jest.fn(),
3
+ info: jest.fn(),
4
+ warning: jest.fn(),
5
+ error: jest.fn(),
6
+ log: jest.fn(),
7
+ };
8
+
9
+ jest.mock("../../../logger", () => ({
10
+ ...jest.requireActual("../../../logger"),
11
+ subsystemLogger: () => mockLogger,
12
+ }));
13
+
14
+ const FLAG = "enable_focus_manager_logs";
15
+ const storageKey = `debug_tools_::_${FLAG}`;
16
+
17
+ describe("web focus diagnostics", () => {
18
+ let manager: typeof import("../index").focusManager;
19
+ let features: typeof import("../../../debugging/DebugFeatures");
20
+ let values: Record<string, string>;
21
+
22
+ beforeEach(() => {
23
+ jest.resetModules();
24
+ jest.clearAllMocks();
25
+ delete (globalThis as any).__applicasterDebugFeatures;
26
+ values = {};
27
+
28
+ (globalThis as any).window = {
29
+ localStorage: {
30
+ getItem: (key: string) => values[key] ?? null,
31
+ setItem: (key: string, value: string) => {
32
+ values[key] = value;
33
+ },
34
+ removeItem: (key: string) => {
35
+ delete values[key];
36
+ },
37
+ },
38
+ };
39
+
40
+ const reactNative = require("react-native");
41
+ delete reactNative.NativeModules.DebugFeaturesBridge;
42
+
43
+ reactNative.NativeModules.LocalStorage =
44
+ require("../../../../zapp-react-dom-app/Polyfills/Storage").getStorageModule(
45
+ "localStorage"
46
+ );
47
+
48
+ jest.spyOn(require("../../../reactUtils"), "isWeb").mockReturnValue(true);
49
+ features = require("../../../debugging/DebugFeatures");
50
+ });
51
+
52
+ afterEach(() => {
53
+ delete (globalThis as any).__applicasterDebugFeatures;
54
+ jest.restoreAllMocks();
55
+ });
56
+
57
+ const component = (id: string) => ({
58
+ props: { id },
59
+ isMounted: () => true,
60
+ setFocus: jest.fn(),
61
+ setBlur: jest.fn(),
62
+ blur: jest.fn(),
63
+ hasLostFocus: jest.fn(),
64
+ willLoseFocus: jest.fn(),
65
+ failedLostFocus: jest.fn(),
66
+ getRect: () => ({ x: 0, y: 0, width: 10, height: 10 }),
67
+ });
68
+
69
+ it("traces only while enabled and always warns for an unknown target", async () => {
70
+ manager = require("../index.ts").focusManager;
71
+ await features.getFeatures();
72
+ manager.register({ id: "a", component: component("a") });
73
+ manager.setFocus("a");
74
+ expect(mockLogger.debug).not.toHaveBeenCalled();
75
+
76
+ await features.toggleFeatureFlag(FLAG, true);
77
+ expect(values[storageKey]).toBe("true");
78
+ manager.register({ id: "b", component: component("b") });
79
+ manager.setFocus("b");
80
+
81
+ expect(mockLogger.debug).toHaveBeenCalledWith(
82
+ expect.objectContaining({ message: expect.stringContaining("to=b") })
83
+ );
84
+
85
+ await features.toggleFeatureFlag(FLAG, false);
86
+ mockLogger.debug.mockClear();
87
+ manager.setFocus("missing");
88
+ expect(mockLogger.debug).not.toHaveBeenCalled();
89
+
90
+ expect(mockLogger.warning).toHaveBeenCalledWith(
91
+ expect.objectContaining({
92
+ message: "focus lost, target not found, id=missing",
93
+ })
94
+ );
95
+ });
96
+
97
+ it("restores the web storage flag on startup", async () => {
98
+ values[storageKey] = "true";
99
+ manager = require("../index.ts").focusManager;
100
+ await new Promise((resolve) => setTimeout(resolve, 0));
101
+ manager.register({ id: "a", component: component("a") });
102
+
103
+ expect(mockLogger.debug).toHaveBeenCalledWith(
104
+ expect.objectContaining({
105
+ message: expect.stringContaining("registered, id=a"),
106
+ })
107
+ );
108
+ });
109
+
110
+ it("warns when a directional move has no target with tracing off", () => {
111
+ manager = require("../index.ts").focusManager;
112
+ manager.register({ id: "a", component: component("a") });
113
+ manager.setFocus("a");
114
+
115
+ manager.moveFocus({
116
+ value: "right",
117
+ axis: "x",
118
+ isHorizontal: true,
119
+ isVertical: false,
120
+ });
121
+
122
+ expect(mockLogger.warning).toHaveBeenCalledWith(
123
+ expect.objectContaining({
124
+ message:
125
+ "focus move failed, from=a, direction=right, reason=no_candidate",
126
+ })
127
+ );
128
+ });
129
+
130
+ it("does not register the flag on native platforms", async () => {
131
+ jest.spyOn(require("../../../reactUtils"), "isWeb").mockReturnValue(false);
132
+ manager = require("../index.ts").focusManager;
133
+ expect(await features.getFeatures()).toEqual([]);
134
+ manager.register({ id: "native", component: component("native") });
135
+ expect(mockLogger.debug).not.toHaveBeenCalled();
136
+ });
137
+ });
@@ -0,0 +1,48 @@
1
+ import { subsystemLogger } from "../../logger";
2
+
3
+ const logger = subsystemLogger("ui/focus", "FocusManager");
4
+
5
+ export const FOCUS_LOGS_FLAG = "enable_focus_manager_logs";
6
+
7
+ let enabled = false;
8
+
9
+ export const isFocusLogEnabled = () => enabled;
10
+
11
+ export const registerFocusLogsFlag = async () => {
12
+ let changed = false;
13
+
14
+ const setEnabled = (next: boolean, source: string) => {
15
+ if (enabled === next) return;
16
+
17
+ enabled = next;
18
+
19
+ logger.info({
20
+ message: `focus trace ${next ? "enabled" : "disabled"}, flag=${FOCUS_LOGS_FLAG}, source=${source}`,
21
+ data: { enabled: next, source },
22
+ });
23
+ };
24
+
25
+ try {
26
+ const { registerFeatureFlag, subscribe } =
27
+ require("../../debugging/DebugFeatures") as typeof import("../../debugging/DebugFeatures");
28
+
29
+ subscribe((event) => {
30
+ changed = true;
31
+ setEnabled(event.enabled, "toggle");
32
+ }, FOCUS_LOGS_FLAG);
33
+
34
+ const initial = await registerFeatureFlag({
35
+ id: FOCUS_LOGS_FLAG,
36
+ group: "FocusManager",
37
+ description: "Log web TV focus registration and movement",
38
+ initialState: false,
39
+ });
40
+
41
+ if (!changed) setEnabled(initial, "stored");
42
+ } catch (error) {
43
+ logger.warning({
44
+ message: `focus trace flag registration failed, flag=${FOCUS_LOGS_FLAG}, error=${String(error)}`,
45
+ data: { error: String(error) },
46
+ });
47
+ }
48
+ };
@@ -13,7 +13,9 @@ import {
13
13
  } from "./treeDataStructure/Utils";
14
14
  import { subscriber } from "../../functionUtils";
15
15
  import { subsystemLogger } from "../../logger";
16
+ import { isWeb } from "../../reactUtils";
16
17
  import { ACTION } from "./utils/enums";
18
+ import { isFocusLogEnabled, registerFocusLogsFlag } from "./focusLogsFlag";
17
19
 
18
20
  import {
19
21
  isTabsScreenOnContentFocused,
@@ -23,6 +25,17 @@ import {
23
25
  } from "../focusManagerAux/utils";
24
26
 
25
27
  const logger = subsystemLogger("ui/focus", "FocusManager");
28
+ const webFocusDiagnostics = isWeb();
29
+
30
+ if (webFocusDiagnostics) {
31
+ registerFocusLogsFlag();
32
+ }
33
+
34
+ const trace = (message: string, data?: Record<string, unknown>) => {
35
+ if (webFocusDiagnostics && isFocusLogEnabled()) {
36
+ logger.debug({ message, data });
37
+ }
38
+ };
26
39
 
27
40
  const isFocusEnabled = (focusableItem): boolean => {
28
41
  const isFocusable = R.path(["props", "isFocusable"], focusableItem);
@@ -268,7 +281,16 @@ export const focusManager = (function () {
268
281
  direction?: FocusManager.Web.Direction,
269
282
  context?: FocusManager.FocusContext
270
283
  ) {
271
- if (focusDisabled) return false;
284
+ if (focusDisabled) {
285
+ trace(`focus blocked, id=${id}, reason=disabled`, { focusable_id: id });
286
+
287
+ return false;
288
+ }
289
+
290
+ trace(`focus requested, from=${currentFocusNode?.id ?? null}, to=${id}`, {
291
+ direction: direction?.value ?? null,
292
+ source: context?.source ?? null,
293
+ });
272
294
 
273
295
  // due to optimisiation it's recommanded to set currentFocusNode before setFocus
274
296
  // is called, so there will be no delays on tree search.
@@ -284,6 +306,13 @@ export const focusManager = (function () {
284
306
  updateNodeFocus(previousNodeParentsIDs, ACTION.BLUR, context);
285
307
 
286
308
  currentFocusNode = focusableTree.findInTree(id);
309
+
310
+ if (!currentFocusNode && webFocusDiagnostics) {
311
+ logger.warning({
312
+ message: `focus lost, target not found, id=${id}`,
313
+ data: { focusable_id: id },
314
+ });
315
+ }
287
316
  }
288
317
 
289
318
  setLastFocusOnParentNode(currentFocusNode);
@@ -309,7 +338,14 @@ export const focusManager = (function () {
309
338
  preserveScroll: true,
310
339
  };
311
340
 
312
- logger.log({ message: "landFocusTo", data: { id } });
341
+ if (webFocusDiagnostics) {
342
+ logger.debug({
343
+ message: `focus restored, id=${id}`,
344
+ data: { focusable_id: id },
345
+ });
346
+ } else {
347
+ logger.log({ message: "landFocusTo", data: { id } });
348
+ }
313
349
 
314
350
  blur(direction);
315
351
  setFocus(id, direction, context);
@@ -346,9 +382,13 @@ export const focusManager = (function () {
346
382
  lastAddedParentNode?.children || focusableTree.root.children
347
383
  );
348
384
 
349
- logger.log({ message: "setInitialFocus", data: { preferredFocus } });
385
+ if (!webFocusDiagnostics) {
386
+ logger.log({ message: "setInitialFocus", data: { preferredFocus } });
387
+ }
350
388
 
351
389
  if (isNilOrEmpty(preferredFocus)) {
390
+ trace("initial focus unavailable, reason=no_candidate");
391
+
352
392
  return { success: false };
353
393
  }
354
394
 
@@ -368,6 +408,10 @@ export const focusManager = (function () {
368
408
  }
369
409
 
370
410
  if (focusableItem?.isGroup) {
411
+ trace(
412
+ `initial focus unavailable, id=${focusCandidate.id}, reason=empty_group`
413
+ );
414
+
371
415
  // focusCandidate is a FocusableGroup, we are not able to land focus on group(only on Focusable)
372
416
  return { success: false };
373
417
  }
@@ -380,18 +424,27 @@ export const focusManager = (function () {
380
424
  // TODO: Move this to setFocus method
381
425
  blur();
382
426
 
383
- logger.log({
384
- message: "setInitialFocus – currentFocusNode",
385
- data: {
386
- focusableItem,
387
- },
388
- });
427
+ if (webFocusDiagnostics) {
428
+ logger.debug({
429
+ message: `initial focus selected, id=${focusCandidate.id}`,
430
+ data: { focusable_id: focusCandidate.id },
431
+ });
432
+ } else {
433
+ logger.log({
434
+ message: "setInitialFocus – currentFocusNode",
435
+ data: { focusableItem },
436
+ });
437
+ }
389
438
 
390
439
  focusableItem && setFocus(focusCandidate.id, null, context);
391
440
 
392
441
  return { success: true };
393
442
  }
394
443
 
444
+ trace(
445
+ `initial focus unavailable, id=${focusCandidate.id}, reason=not_focusable`
446
+ );
447
+
395
448
  return { success: false };
396
449
  }
397
450
 
@@ -499,6 +552,13 @@ export const focusManager = (function () {
499
552
  focusableTree.findAndRemoveNode(id);
500
553
 
501
554
  if (currentFocusNode && currentFocusNode.id === id) {
555
+ if (webFocusDiagnostics) {
556
+ logger.debug({
557
+ message: `focused item unmounted, id=${id}, awaiting recovery`,
558
+ data: { focusable_id: id },
559
+ });
560
+ }
561
+
502
562
  currentFocusNode = null;
503
563
  lastFocusedId = id;
504
564
  }
@@ -517,6 +577,10 @@ export const focusManager = (function () {
517
577
  function register({ id, component }) {
518
578
  const { isGroup = false } = component;
519
579
 
580
+ trace(`registered, id=${id}, group=${isGroup}`, {
581
+ parent_id: component.props?.groupId ?? null,
582
+ });
583
+
520
584
  return isGroup ? registerGroup(id, component) : registerItem(id, component);
521
585
  }
522
586
 
@@ -530,6 +594,10 @@ export const focusManager = (function () {
530
594
  * unregister is a group. defaults to false.
531
595
  */
532
596
  function unregister(id, { group = false } = {}) {
597
+ trace(`unregistered, id=${id}, group=${group}`, {
598
+ focused: currentFocusNode?.id === id,
599
+ });
600
+
533
601
  group ? unregisterGroup(id) : unregisterItem(id);
534
602
  }
535
603
 
@@ -546,6 +614,12 @@ export const focusManager = (function () {
546
614
 
547
615
  function recoverFocus() {
548
616
  if (!isCurrentFocusOnTheTopScreen()) {
617
+ if (webFocusDiagnostics) {
618
+ logger.debug({
619
+ message: `focus recovery requested, focused_id=${currentFocusNode?.id ?? null}`,
620
+ });
621
+ }
622
+
549
623
  // We've failed to set focused node on the new screen => run focus recovery
550
624
  setInitialFocus();
551
625
  }
@@ -558,11 +632,21 @@ export const focusManager = (function () {
558
632
  */
559
633
  function moveFocus(direction) {
560
634
  if (!isCurrentFocusOnTheTopScreen()) {
635
+ trace(
636
+ `focus move blocked, focused_id=${currentFocusNode?.id ?? null}, reason=${currentFocusNode ? "screen_transition" : "no_current_focus"}, direction=${direction?.value ?? null}`
637
+ );
638
+
561
639
  // We are opening new screen. We need to ignore movement of focus.
562
640
  return false;
563
641
  }
564
642
 
565
- if (focusDisabled) return false;
643
+ if (focusDisabled) {
644
+ trace(
645
+ `focus move blocked, reason=disabled, direction=${direction?.value ?? null}`
646
+ );
647
+
648
+ return false;
649
+ }
566
650
 
567
651
  if (currentFocusNode) {
568
652
  currentFocusNode.component.willLoseFocus(currentFocusNode, direction);
@@ -572,14 +656,37 @@ export const focusManager = (function () {
572
656
  const nextRect = nextFocusable.component.getRect();
573
657
 
574
658
  if (nextRect && nextRect.width > 0) {
659
+ trace(
660
+ `focus moving, from=${currentFocusNode.id}, to=${nextFocusable.id}, direction=${direction?.value ?? null}`
661
+ );
662
+
575
663
  // TODO: Move this to setFocus method
576
664
  blur(direction);
577
665
 
578
666
  setFocus(nextFocusable.id, direction);
667
+ } else if (webFocusDiagnostics) {
668
+ logger.warning({
669
+ message: `focus move dropped, id=${nextFocusable.id}, reason=invalid_rect`,
670
+ data: {
671
+ direction: direction?.value ?? null,
672
+ width: nextRect?.width ?? null,
673
+ },
674
+ });
579
675
  }
580
676
  } else {
677
+ if (webFocusDiagnostics) {
678
+ logger.warning({
679
+ message: `focus move failed, from=${currentFocusNode.id}, direction=${direction?.value ?? null}, reason=${nextFocusable ? "not_mounted" : "no_candidate"}`,
680
+ data: { target_id: nextFocusable?.id ?? null },
681
+ });
682
+ }
683
+
581
684
  currentFocusNode.component.failedLostFocus(currentFocusNode, direction);
582
685
  }
686
+ } else if (webFocusDiagnostics) {
687
+ logger.warning({
688
+ message: `focus move failed, direction=${direction?.value ?? null}, reason=no_current_focus`,
689
+ });
583
690
  }
584
691
  }
585
692
 
@@ -11,9 +11,9 @@ import {
11
11
  isSamsungPlatform,
12
12
  } from "@applicaster/zapp-react-dom-app/App/Loader/utils/platform";
13
13
 
14
- import { PLATFORM_KEYS, PLATFORMS, ZappPlatform } from "./const";
14
+ import { PLATFORM_KEYS, ZappPlatform } from "./const";
15
15
  import { createLogger, utilsLogger } from "../../logger";
16
- import { getPlatform } from "../../reactUtils";
16
+ import { getPlatform, isVizioPlatform } from "../../reactUtils";
17
17
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
18
18
  import { calculateReadingTime } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/utils";
19
19
 
@@ -47,24 +47,8 @@ export const getUserAgent = () => window?.navigator?.userAgent;
47
47
 
48
48
  /** VIZIO UTILS */
49
49
 
50
- /**
51
- * Checks if we are on the Vizio platform by using the userAgent string
52
- *
53
- * Use this method when you need to identify the platform on runtime
54
- * before the VIZIO Companion Library has loaded
55
- */
56
- export const isVizioPlatform = () => {
57
- const userAgent = getUserAgent();
58
-
59
- if (!userAgent) return false;
60
-
61
- const isVizioAgent =
62
- userAgent.includes(PLATFORMS.vizio) ||
63
- userAgent.includes(PLATFORMS.smartcast) ||
64
- userAgent.includes(PLATFORMS.conjure);
65
-
66
- return isVizioAgent;
67
- };
50
+ // One implementation, so its build-time device target guard applies here too.
51
+ export { isVizioPlatform };
68
52
 
69
53
  /**
70
54
  * Checks if we are on the Vizio platform by checking for the global VIZIO object
@@ -82,6 +82,8 @@ export class Player {
82
82
  public playNextHandler: (() => void) | null = null;
83
83
  // The web engine the default player picked (hls.js, dash.js, shaka, video.js); null elsewhere.
84
84
  public engine: string | null = null;
85
+ // False when the engine reports no DVR window for live (dash.js, hls.js), so controls must not offer live seek.
86
+ public supportsLiveSeek = true;
85
87
 
86
88
  protected listeners: {
87
89
  [key: string]: QuickBrickPlayer.SharedPlayerCallBacks;
@@ -1,26 +1,3 @@
1
- import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
- import { getBoolFromConfigValue } from "@applicaster/zapp-react-native-utils/configurationUtils";
1
+ export * from "./DebugFeatures";
3
2
 
4
- class DebugFeatures {
5
- debugToolsNamespace = "debug_tools";
6
-
7
- private static instance: DebugFeatures;
8
- public static getInstance() {
9
- if (!DebugFeatures.instance) {
10
- DebugFeatures.instance = new DebugFeatures();
11
- }
12
-
13
- return DebugFeatures.instance;
14
- }
15
-
16
- public isFeatureFlagEnabled = async (featureId: string): Promise<boolean> => {
17
- const result = await localStorage.getItem(
18
- featureId,
19
- this.debugToolsNamespace
20
- );
21
-
22
- return result && getBoolFromConfigValue(result);
23
- };
24
- }
25
-
26
- export default DebugFeatures;
3
+ export { default } from "./DebugFeatures";