@applicaster/zapp-react-native-utils 16.0.0-rc.99 → 17.0.0-rc.2

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 (149) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +2 -2
  3. package/actionsExecutor/ActionExecutorContext.tsx +2 -2
  4. package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
  5. package/actionsExecutor/__tests__/feedDecorator.test.ts +30 -0
  6. package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
  7. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +186 -5
  8. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +72 -0
  10. package/actionsExecutor/actions/appRestart.ts +2 -2
  11. package/actionsExecutor/actions/confirmDialog.ts +2 -2
  12. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -2
  13. package/actionsExecutor/actions/goBack.ts +2 -2
  14. package/actionsExecutor/actions/goHome.ts +2 -2
  15. package/actionsExecutor/actions/navigateToScreen.ts +35 -45
  16. package/actionsExecutor/actions/openBottomSheet.ts +4 -2
  17. package/actionsExecutor/actions/presentScreen.ts +2 -2
  18. package/actionsExecutor/actions/refreshComponent.ts +2 -2
  19. package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
  20. package/actionsExecutor/actions/sendCloudEvent.ts +2 -2
  21. package/actionsExecutor/actions/showAlert.ts +2 -2
  22. package/actionsExecutor/actions/switchLayout.ts +2 -2
  23. package/actionsExecutor/feedDecorator.ts +8 -2
  24. package/actionsExecutor/types.ts +7 -0
  25. package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
  26. package/analyticsUtils/logger.ts +9 -4
  27. package/analyticsUtils/playerAnalyticsTracker.ts +1 -0
  28. package/appUtils/HooksManager/logger.ts +5 -2
  29. package/appUtils/accessibilityManager/logger.ts +2 -4
  30. package/appUtils/accessibilityManager/utils.ts +1 -1
  31. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
  32. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  33. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  34. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
  35. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  36. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  37. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  38. package/appUtils/contextKeysManager/index.ts +30 -131
  39. package/appUtils/focusManager/__tests__/focusToolbox.test.ts +357 -0
  40. package/appUtils/focusManager/focusToolbox.ts +223 -0
  41. package/appUtils/focusManager/index.ios.ts +7 -1
  42. package/appUtils/focusManager/index.ts +2 -2
  43. package/appUtils/focusManager/logger.ts +2 -2
  44. package/appUtils/focusManagerAux/index.ts +2 -2
  45. package/appUtils/orientationHelper.ts +2 -2
  46. package/appUtils/platform/platformUtils.ts +2 -2
  47. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +1 -1
  48. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  49. package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
  50. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  51. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  52. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  53. package/appUtils/playerManager/const.ts +13 -0
  54. package/appUtils/playerManager/index.ts +9 -2
  55. package/appUtils/playerManager/player.ts +26 -1
  56. package/appUtils/playerManager/playerNative.ts +23 -1
  57. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  58. package/appUtils/playerManager/playerToolbox.ts +196 -0
  59. package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
  60. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  61. package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
  62. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  63. package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
  64. package/arrayUtils/index.ts +26 -43
  65. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  66. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  67. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  68. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  69. package/cellUtils/index.ts +40 -0
  70. package/cellUtils/logger.ts +2 -2
  71. package/configurationUtils/__tests__/modalBlocksParser.test.ts +134 -0
  72. package/configurationUtils/modalBlocksParser.ts +38 -0
  73. package/domUtils/logger.ts +2 -2
  74. package/entryActions/aliasPresentation.ts +1 -0
  75. package/entryActions/buildEntryActions.ts +1 -1
  76. package/focusManager/FocusManager.ts +26 -0
  77. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  78. package/focusManager/logger.ts +2 -6
  79. package/headersUtils/index.ts +2 -2
  80. package/localizationUtils/index.ts +12 -6
  81. package/logger/__tests__/subsystems.test.ts +148 -0
  82. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  83. package/logger/index.ts +48 -9
  84. package/logger/subsystems.ts +112 -0
  85. package/logger/xrayToolbox.ts +69 -0
  86. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  87. package/manifestUtils/keys.js +7 -2
  88. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  89. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  90. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  91. package/modalState/EditableCollectionRegistry.ts +1 -1
  92. package/modalState/ModalOrchestrator.ts +1 -0
  93. package/modalState/RemoteEditableCollection.ts +1 -1
  94. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +23 -0
  95. package/modalState/index.ts +2 -0
  96. package/modalState/types.ts +11 -0
  97. package/navigationUtils/index.ts +5 -2
  98. package/navigationUtils/xrayNavigator.ts +12 -0
  99. package/numberUtils/index.ts +2 -2
  100. package/package.json +3 -2
  101. package/playerUtils/PlayerTTS/PlayerTTS.ts +1 -1
  102. package/playerUtils/imaScriptDom.ts +1 -1
  103. package/playerUtils/useValidatePlayerConfig.tsx +1 -1
  104. package/pluginUtils/logger.ts +2 -2
  105. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  106. package/quickBrickAssets/index.ts +35 -0
  107. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  108. package/reactHooks/actions/index.ts +29 -23
  109. package/reactHooks/cell-click/__tests__/index.test.js +67 -1
  110. package/reactHooks/cell-click/index.ts +10 -2
  111. package/reactHooks/connection/index.tsx +8 -5
  112. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  113. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  114. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  115. package/reactHooks/feed/useBuildPipesUrl.ts +5 -2
  116. package/reactHooks/feed/useFeedLoader.tsx +30 -3
  117. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  118. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  119. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
  120. package/reactHooks/logger.ts +5 -2
  121. package/reactHooks/navigation/usePresentScreen.ts +2 -2
  122. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +2 -2
  123. package/reactHooks/screen/useScreenData.ts +2 -2
  124. package/reactHooks/usePluginConfiguration.ts +84 -46
  125. package/reactHooks/videoModal/hooks/useChangeOrientation.ts +2 -7
  126. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +1 -1
  127. package/reactUtils/createContext/helpers.ts +2 -2
  128. package/reactUtils/logger.ts +2 -2
  129. package/riverComponetsMeasurementProvider/index.tsx +5 -5
  130. package/storage/ScreenSingleValueProvider.ts +1 -1
  131. package/storage/ScreenStateMultiSelectProvider.ts +1 -1
  132. package/storage/StorageMultiSelectProvider.ts +1 -1
  133. package/storage/StorageSingleSelectProvider.ts +1 -1
  134. package/stylesUtils/logger.ts +2 -2
  135. package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
  136. package/uiActionsRegistrator/registry.ts +17 -1
  137. package/uiActionsRegistrator/resolveActionIdentifiers.ts +1 -1
  138. package/uiActionsRegistrator/usableActionItems.ts +1 -1
  139. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +2 -1
  140. package/zappFrameworkUtils/loginPluginUtils.ts +2 -1
  141. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -1
  142. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  143. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  144. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  145. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  146. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  147. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  148. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  149. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
@@ -0,0 +1,357 @@
1
+ const mockRegister = jest.fn();
2
+ const mockForceFocusOnFocusable = jest.fn();
3
+ let mockXray: Record<string, unknown> | null = {};
4
+
5
+ jest.mock("../../../logger", () => ({
6
+ getXray: () => mockXray,
7
+ }));
8
+
9
+ const loadToolbox = () => {
10
+ let module;
11
+
12
+ jest.isolateModules(() => {
13
+ module = require("../focusToolbox");
14
+ });
15
+
16
+ return module as typeof import("../focusToolbox");
17
+ };
18
+
19
+ const managerFor = (tree) => ({
20
+ focusableTree: { root: tree.root },
21
+ forceFocusOnFocusable: mockForceFocusOnFocusable,
22
+ });
23
+
24
+ const item = (id: string, groupId: string, extra = {}) => ({
25
+ id: `node-${id}`,
26
+ component: {
27
+ props: { id, groupId, testID: `test-${id}` },
28
+ state: { focused: false },
29
+ onPress: jest.fn(),
30
+ ...extra,
31
+ },
32
+ });
33
+
34
+ /** root > home-river > rail-1 > [cell-a, cell-b] */
35
+ const makeTree = () => {
36
+ const cellA = item("cell-a", "rail-1");
37
+ const cellB = item("cell-b", "rail-1");
38
+
39
+ const root = {
40
+ id: "root",
41
+ children: [
42
+ {
43
+ id: "home-river",
44
+ children: [{ id: "rail-1", children: [cellA, cellB] }],
45
+ },
46
+ ],
47
+ };
48
+
49
+ return { root, cellA, cellB };
50
+ };
51
+
52
+ const focus = (node, focused = true) => {
53
+ node.component.state.focused = focused;
54
+ };
55
+
56
+ const registeredTools = async (tree) => {
57
+ mockRegister.mockResolvedValue(undefined);
58
+ mockXray = { registerReactToolbox: mockRegister };
59
+ await loadToolbox().registerFocusToolbox(managerFor(tree));
60
+
61
+ const { tools } = mockRegister.mock.lastCall[0];
62
+
63
+ return Object.fromEntries(tools.map((tool) => [tool.name, tool.handler]));
64
+ };
65
+
66
+ describe("focusToolbox", () => {
67
+ beforeEach(() => {
68
+ mockRegister.mockReset();
69
+ mockForceFocusOnFocusable.mockReset();
70
+ });
71
+
72
+ afterEach(() => {
73
+ jest.useRealTimers();
74
+ });
75
+
76
+ it("does nothing when X-Ray has no React toolbox API", async () => {
77
+ mockXray = {};
78
+
79
+ await expect(
80
+ loadToolbox().registerFocusToolbox(managerFor(makeTree()))
81
+ ).resolves.toBe(false);
82
+ });
83
+
84
+ it("does nothing when getXray returns null", async () => {
85
+ mockXray = null;
86
+
87
+ await expect(
88
+ loadToolbox().registerFocusToolbox(managerFor(makeTree()))
89
+ ).resolves.toBe(false);
90
+ });
91
+
92
+ it("registers the focus toolbox", async () => {
93
+ await registeredTools(makeTree());
94
+
95
+ const toolbox = mockRegister.mock.lastCall[0];
96
+
97
+ expect(toolbox.name).toBe("focus");
98
+
99
+ expect(toolbox.tools.map((tool) => tool.name)).toEqual([
100
+ "current",
101
+ "tree",
102
+ "set",
103
+ "select",
104
+ ]);
105
+ });
106
+
107
+ describe("current", () => {
108
+ it("is null when nothing is focused", async () => {
109
+ const tools = await registeredTools(makeTree());
110
+
111
+ expect(tools.current({})).toBeNull();
112
+ });
113
+
114
+ it("describes the focused item and its enclosing groups", async () => {
115
+ const tree = makeTree();
116
+ const tools = await registeredTools(tree);
117
+
118
+ focus(tree.cellB);
119
+
120
+ expect(tools.current({})).toEqual({
121
+ itemId: "cell-b",
122
+ groupId: "rail-1",
123
+ testID: "test-cell-b",
124
+ groups: ["home-river", "rail-1"],
125
+ });
126
+ });
127
+
128
+ it("falls back to the node id when the Focusable has no id prop", async () => {
129
+ const tree = makeTree();
130
+ const tools = await registeredTools(tree);
131
+
132
+ tree.cellA.component.props = {} as any;
133
+ focus(tree.cellA);
134
+
135
+ expect(tools.current({})).toMatchObject({
136
+ itemId: "node-cell-a",
137
+ groupId: null,
138
+ testID: null,
139
+ });
140
+ });
141
+
142
+ it("skips focused groups, as the layout's root group before the river", async () => {
143
+ const tree = makeTree();
144
+
145
+ const layoutGroup = {
146
+ id: "RootWrapperComponent-Navigation",
147
+ component: { isGroup: true, props: {}, state: { focused: true } },
148
+ children: [],
149
+ };
150
+
151
+ tree.root.children.unshift(layoutGroup as any);
152
+ const tools = await registeredTools(tree);
153
+
154
+ focus(tree.cellA);
155
+
156
+ expect(tools.current({})).toMatchObject({
157
+ itemId: "cell-a",
158
+ groups: ["home-river", "rail-1"],
159
+ });
160
+ });
161
+ });
162
+
163
+ describe("tree", () => {
164
+ const railGroup = (tree) => {
165
+ const rail = tree.root.children[0].children[0];
166
+
167
+ rail.component = { isGroup: true, props: {}, state: { focused: true } };
168
+
169
+ return rail;
170
+ };
171
+
172
+ it("lists the registered Focusables from the root", async () => {
173
+ const tree = makeTree();
174
+ const tools = await registeredTools(tree);
175
+
176
+ railGroup(tree);
177
+ focus(tree.cellB);
178
+
179
+ expect(tools.tree({})).toEqual({
180
+ id: "root",
181
+ children: [
182
+ {
183
+ id: "home-river",
184
+ children: [
185
+ {
186
+ id: "rail-1",
187
+ group: true,
188
+ children: [
189
+ { id: "node-cell-a", testID: "test-cell-a" },
190
+ { id: "node-cell-b", focused: true, testID: "test-cell-b" },
191
+ ],
192
+ },
193
+ ],
194
+ },
195
+ ],
196
+ });
197
+ });
198
+
199
+ it("returns one group's subtree", async () => {
200
+ const tree = makeTree();
201
+ const tools = await registeredTools(tree);
202
+
203
+ railGroup(tree);
204
+
205
+ expect(tools.tree({ groupId: "rail-1" })).toMatchObject({
206
+ id: "rail-1",
207
+ group: true,
208
+ children: [{ id: "node-cell-a" }, { id: "node-cell-b" }],
209
+ });
210
+ });
211
+
212
+ it("throws for an unknown group", async () => {
213
+ const tools = await registeredTools(makeTree());
214
+
215
+ expect(() => tools.tree({ groupId: "nope" })).toThrow(
216
+ 'No Focusable group "nope"'
217
+ );
218
+ });
219
+ });
220
+
221
+ describe("set", () => {
222
+ const setFocus = (tools, itemId = "cell-b") =>
223
+ tools.set({ groupId: "rail-1", itemId });
224
+
225
+ it("moves focus through the focus manager", async () => {
226
+ const tree = makeTree();
227
+ const tools = await registeredTools(tree);
228
+
229
+ mockForceFocusOnFocusable.mockImplementation(({ callback }) => {
230
+ focus(tree.cellB);
231
+ callback();
232
+ });
233
+
234
+ await setFocus(tools);
235
+
236
+ expect(mockForceFocusOnFocusable).toHaveBeenCalledWith({
237
+ itemId: "cell-b",
238
+ callback: expect.any(Function),
239
+ });
240
+ });
241
+
242
+ it("is focused once the item shows focused", async () => {
243
+ const tree = makeTree();
244
+ const tools = await registeredTools(tree);
245
+
246
+ mockForceFocusOnFocusable.mockImplementation(({ callback }) => {
247
+ focus(tree.cellB);
248
+ callback();
249
+ });
250
+
251
+ await expect(setFocus(tools)).resolves.toEqual({
252
+ focused: true,
253
+ current: expect.objectContaining({ itemId: "cell-b" }),
254
+ });
255
+ });
256
+
257
+ it("is focused when the Focusable's id prop is a number", async () => {
258
+ const tree = makeTree();
259
+ const tools = await registeredTools(tree);
260
+
261
+ tree.cellB.component.props.id = 7 as any;
262
+
263
+ mockForceFocusOnFocusable.mockImplementation(({ callback }) => {
264
+ focus(tree.cellB);
265
+ callback();
266
+ });
267
+
268
+ await expect(setFocus(tools, "7")).resolves.toMatchObject({
269
+ focused: true,
270
+ });
271
+ });
272
+
273
+ it("waits for state.focused when it follows the callback", async () => {
274
+ jest.useFakeTimers();
275
+
276
+ const tree = makeTree();
277
+ const tools = await registeredTools(tree);
278
+
279
+ mockForceFocusOnFocusable.mockImplementation(({ callback }) =>
280
+ callback()
281
+ );
282
+
283
+ const result = setFocus(tools);
284
+
285
+ jest.advanceTimersByTime(200);
286
+ focus(tree.cellB);
287
+ jest.advanceTimersByTime(50);
288
+
289
+ await expect(result).resolves.toMatchObject({ focused: true });
290
+ });
291
+
292
+ it("times out when the focus manager has no such item and never calls back", async () => {
293
+ jest.useFakeTimers();
294
+
295
+ const tools = await registeredTools(makeTree());
296
+
297
+ const result = setFocus(tools);
298
+
299
+ jest.advanceTimersByTime(3000);
300
+
301
+ await expect(result).resolves.toEqual({
302
+ focused: false,
303
+ timedOut: true,
304
+ current: null,
305
+ });
306
+ });
307
+
308
+ it("times out when focus stays on another item", async () => {
309
+ jest.useFakeTimers();
310
+
311
+ const tree = makeTree();
312
+ const tools = await registeredTools(tree);
313
+
314
+ focus(tree.cellA);
315
+
316
+ mockForceFocusOnFocusable.mockImplementation(({ callback }) =>
317
+ callback()
318
+ );
319
+
320
+ const result = setFocus(tools);
321
+
322
+ jest.advanceTimersByTime(3000);
323
+
324
+ await expect(result).resolves.toMatchObject({
325
+ focused: false,
326
+ timedOut: true,
327
+ });
328
+
329
+ expect(jest.getTimerCount()).toBe(0);
330
+ });
331
+ });
332
+
333
+ describe("select", () => {
334
+ it("throws when nothing is focused", async () => {
335
+ const tools = await registeredTools(makeTree());
336
+
337
+ expect(() => tools.select({})).toThrow("Nothing selectable is focused");
338
+ });
339
+
340
+ it("presses the focused item as the remote does", async () => {
341
+ const tree = makeTree();
342
+ const tools = await registeredTools(tree);
343
+
344
+ focus(tree.cellB);
345
+
346
+ expect(tools.select({})).toEqual({
347
+ selected: expect.objectContaining({ itemId: "cell-b" }),
348
+ });
349
+
350
+ expect(tree.cellB.component.onPress).toHaveBeenCalledWith({
351
+ nativeEvent: { itemID: "cell-b", groupId: "rail-1" },
352
+ });
353
+
354
+ expect(tree.cellA.component.onPress).not.toHaveBeenCalled();
355
+ });
356
+ });
357
+ });
@@ -0,0 +1,223 @@
1
+ import { registerXrayToolbox, XrayToolSpec } from "../../logger/xrayToolbox";
2
+
3
+ /**
4
+ * X-Ray `focus.*` toolbox for tvOS: lets an agent read and move focus without a remote. The
5
+ * native `ui.pressKey` in quick-brick-xray turns remote keys into these calls, since no public
6
+ * API moves the UIKit focus engine in a direction. Focus moves through the focus manager, as the
7
+ * app's own code moves it, never the native module directly. Registered by the tvOS focus manager
8
+ * itself; skipped when the X-Ray plugin has no React toolbox API.
9
+ */
10
+
11
+ type FocusNode = {
12
+ id: string;
13
+ component?: {
14
+ props?: Record<string, any>;
15
+ state?: { focused?: boolean };
16
+ isGroup?: boolean;
17
+ };
18
+ children?: FocusNode[];
19
+ };
20
+
21
+ type FocusManagerApi = {
22
+ focusableTree: { root: FocusNode };
23
+ forceFocusOnFocusable: (args: {
24
+ itemId: string;
25
+ callback?: () => void;
26
+ }) => void;
27
+ };
28
+
29
+ const FOCUS_TIMEOUT_MS = 3000;
30
+ const FOCUS_POLL_MS = 50;
31
+
32
+ /**
33
+ * The focused Focusable. Not getCurrentFocus(): on tvOS it only follows focus across groups,
34
+ * while each Focusable's own state.focused follows the native engine. Groups are skipped: a group
35
+ * is focused while focus is anywhere inside it, and the layout's root group is not the tree parent
36
+ * of the screen's groups, so it would hide the item.
37
+ */
38
+ const findFocused = (node: FocusNode, path: string[] = []) => {
39
+ for (const child of node.children ?? []) {
40
+ if (child.component?.state?.focused && !child.component.isGroup) {
41
+ return { node: child, path };
42
+ }
43
+
44
+ const found = findFocused(child, [...path, child.id]);
45
+
46
+ if (found) return found;
47
+ }
48
+
49
+ return null;
50
+ };
51
+
52
+ const findNode = (node: FocusNode, id: string): FocusNode | null => {
53
+ if (String(node.id) === id) return node;
54
+
55
+ for (const child of node.children ?? []) {
56
+ const found = findNode(child, id);
57
+
58
+ if (found) return found;
59
+ }
60
+
61
+ return null;
62
+ };
63
+
64
+ type TreeView = {
65
+ id: string;
66
+ group?: true;
67
+ focused?: true;
68
+ testID?: string;
69
+ children?: TreeView[];
70
+ };
71
+
72
+ /** A node as the agent sees it: keys only when they say something, to keep large screens short. */
73
+ const toTreeView = (node: FocusNode): TreeView => {
74
+ const { component } = node;
75
+ const testID = component?.props?.testID;
76
+ const children = node.children ?? [];
77
+
78
+ return {
79
+ id: node.id,
80
+ ...(component?.isGroup ? { group: true as const } : {}),
81
+ ...(component?.state?.focused && !component.isGroup
82
+ ? { focused: true as const }
83
+ : {}),
84
+ ...(testID ? { testID } : {}),
85
+ ...(children.length ? { children: children.map(toTreeView) } : {}),
86
+ };
87
+ };
88
+
89
+ const tools = (manager: FocusManagerApi): XrayToolSpec[] => {
90
+ const tree = manager.focusableTree;
91
+
92
+ const describeFocused = () => {
93
+ const found = findFocused(tree.root);
94
+
95
+ if (!found) return null;
96
+
97
+ const props = found.node.component?.props ?? {};
98
+
99
+ return {
100
+ itemId: props.id ?? found.node.id,
101
+ groupId: props.groupId ?? null,
102
+ testID: props.testID ?? null,
103
+ groups: found.path,
104
+ };
105
+ };
106
+
107
+ return [
108
+ {
109
+ name: "current",
110
+ description:
111
+ "The focused item: itemId, groupId, testID and the ids of its enclosing groups. null when nothing is.",
112
+ handler: () => describeFocused(),
113
+ },
114
+ {
115
+ name: "tree",
116
+ description:
117
+ "The focus manager's tree of registered Focusables: id, group: true for groups, focused: true on " +
118
+ "the focused item, testID, children. Only rendered Focusables are registered. A screen can hold " +
119
+ "hundreds; pass groupId for one group's subtree. Item ids are what set takes.",
120
+ parameters: [
121
+ {
122
+ name: "groupId",
123
+ type: "string",
124
+ description:
125
+ "Return only this group's subtree. Default: the whole tree.",
126
+ required: false,
127
+ },
128
+ ],
129
+ handler: ({ groupId }) => {
130
+ const start =
131
+ groupId === undefined || groupId === null || groupId === ""
132
+ ? tree.root
133
+ : findNode(tree.root, String(groupId));
134
+
135
+ if (!start) throw new Error(`No Focusable group "${groupId}"`);
136
+
137
+ return toTreeView(start);
138
+ },
139
+ },
140
+ {
141
+ name: "set",
142
+ description:
143
+ "Focus an item through the focus manager (forceFocusOnFocusable), as the app's own code does. " +
144
+ "A cell's itemId is <componentId>-<entryId>-<index> and its groupId the component id. " +
145
+ "focused: false when it did not land within 3 s (unknown ids, or the item is not rendered, e.g. " +
146
+ "scrolled out of a virtualised list). It replaces a focus the app is still setting, so call it " +
147
+ "once the screen is idle (ui.waitFor idle).",
148
+ parameters: [
149
+ {
150
+ name: "groupId",
151
+ type: "string",
152
+ description: "Focusable group id; the item is found by itemId.",
153
+ required: false,
154
+ },
155
+ { name: "itemId", type: "string", description: "Focusable item id." },
156
+ ],
157
+ handler: ({ itemId }) =>
158
+ new Promise((resolve) => {
159
+ let done = false;
160
+
161
+ const finish = (result: { focused: boolean; timedOut?: boolean }) => {
162
+ if (done) return;
163
+
164
+ done = true;
165
+ resolve({ ...result, current: describeFocused() });
166
+ };
167
+
168
+ const timer = setTimeout(
169
+ () => finish({ focused: false, timedOut: true }),
170
+ FOCUS_TIMEOUT_MS
171
+ );
172
+
173
+ // The callback says the move ended, not that it landed (the focus manager drops the
174
+ // native result), and state.focused follows a separate onViewFocus event, so wait for
175
+ // the item itself.
176
+ const waitForItem = () => {
177
+ if (done) return;
178
+
179
+ const current = describeFocused();
180
+
181
+ // A Focusable's id prop can be a number; the ids arrive as strings.
182
+ if (current && String(current.itemId) === String(itemId)) {
183
+ clearTimeout(timer);
184
+ finish({ focused: true });
185
+ } else {
186
+ setTimeout(waitForItem, FOCUS_POLL_MS);
187
+ }
188
+ };
189
+
190
+ manager.forceFocusOnFocusable({
191
+ itemId: String(itemId),
192
+ callback: waitForItem,
193
+ });
194
+ }),
195
+ },
196
+ {
197
+ name: "select",
198
+ description:
199
+ "Press select on the focused item, as the remote's click does.",
200
+ handler: () => {
201
+ const component = findFocused(tree.root)?.node.component as any;
202
+
203
+ if (!component?.onPress) {
204
+ throw new Error("Nothing selectable is focused");
205
+ }
206
+
207
+ const { id, groupId } = component.props ?? {};
208
+
209
+ component.onPress({ nativeEvent: { itemID: id, groupId } });
210
+
211
+ return { selected: describeFocused() };
212
+ },
213
+ },
214
+ ];
215
+ };
216
+
217
+ export const registerFocusToolbox = (manager: FocusManagerApi) =>
218
+ registerXrayToolbox({
219
+ name: "focus",
220
+ description:
221
+ "tvOS focus: current item, Focusable tree, focus by id, select.",
222
+ tools: tools(manager),
223
+ });
@@ -1,4 +1,4 @@
1
- import { NativeModules } from "react-native";
1
+ import { NativeModules, Platform } from "react-native";
2
2
  import * as R from "ramda";
3
3
 
4
4
  import {
@@ -13,6 +13,7 @@ import { Tree } from "./treeDataStructure/Tree";
13
13
  import { findFocusableNode } from "./treeDataStructure/Utils";
14
14
  import { subscriber } from "../../functionUtils";
15
15
  import { findChild } from "./utils";
16
+ import { registerFocusToolbox } from "./focusToolbox";
16
17
 
17
18
  import {
18
19
  emitRegistered,
@@ -480,3 +481,8 @@ export const focusManager = (function () {
480
481
  isChildOf,
481
482
  };
482
483
  })();
484
+
485
+ // iOS shares this file; only the TV has a focus engine to drive.
486
+ if (Platform.isTV) {
487
+ registerFocusToolbox(focusManager);
488
+ }
@@ -12,7 +12,7 @@ import {
12
12
  haveSameParentBeforeRoot,
13
13
  } from "./treeDataStructure/Utils";
14
14
  import { subscriber } from "../../functionUtils";
15
- import { coreLogger } from "../../logger";
15
+ import { subsystemLogger } from "../../logger";
16
16
  import { ACTION } from "./utils/enums";
17
17
 
18
18
  import {
@@ -22,7 +22,7 @@ import {
22
22
  isCurrentFocusOn,
23
23
  } from "../focusManagerAux/utils";
24
24
 
25
- const logger = coreLogger.addSubsystem("focusManager");
25
+ const logger = subsystemLogger("ui/focus", "FocusManager");
26
26
 
27
27
  const isFocusEnabled = (focusableItem): boolean => {
28
28
  const isFocusable = R.path(["props", "isFocusable"], focusableItem);
@@ -1,3 +1,3 @@
1
- import { utilsLogger } from "../../logger";
1
+ import { subsystemLogger } from "../../logger";
2
2
 
3
- export const focusManagerLogger = utilsLogger.addSubsystem("focusManager");
3
+ export const focusManagerLogger = subsystemLogger("ui/focus", "FocusManager");
@@ -8,9 +8,9 @@ import {
8
8
  getNavbarNode,
9
9
  } from "./utils";
10
10
 
11
- import { coreLogger } from "../../logger";
11
+ import { subsystemLogger } from "../../logger";
12
12
 
13
- const logger = coreLogger.addSubsystem("focusManagerAux");
13
+ const logger = subsystemLogger("ui/focus", "FocusManagerAux");
14
14
 
15
15
  export async function setFocusOnMenu(currentRoute: string) {
16
16
  const { setFocus, focusableTree } = focusManager;
@@ -9,7 +9,7 @@ import {
9
9
  QuickBrickEvent,
10
10
  sendQuickBrickEvent,
11
11
  } from "@applicaster/zapp-react-native-bridge/QuickBrick";
12
- import { utilsLogger } from "../logger";
12
+ import { subsystemLogger } from "../logger";
13
13
 
14
14
  const { DeviceEventEmitter, NativeModules, NativeEventEmitter } = ReactNative;
15
15
 
@@ -23,7 +23,7 @@ const EventEmitter = platformSelect({
23
23
  default: DeviceEventEmitter,
24
24
  });
25
25
 
26
- const logger = utilsLogger.addSubsystem("orientationHelper");
26
+ const logger = subsystemLogger("ui/orientation", "OrientationHelper");
27
27
 
28
28
  /**
29
29
  * @enum {Orientations}
@@ -18,8 +18,8 @@ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
18
18
  import { calculateReadingTime } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/utils";
19
19
 
20
20
  const { log_debug } = createLogger({
21
- category: "General",
22
- subsystem: "PlatformUtils",
21
+ category: "PlatformUtils",
22
+ subsystem: "core/platform",
23
23
  parent: utilsLogger,
24
24
  });
25
25
 
@@ -14,7 +14,7 @@ import {
14
14
 
15
15
  export const { log_verbose, log_debug, log_info, log_error } = createLogger({
16
16
  category: "ChapterMarkers",
17
- subsystem: "General",
17
+ subsystem: "player/overlay",
18
18
  parent: utilsLogger,
19
19
  });
20
20