@applicaster/zapp-react-native-utils 16.0.0-rc.127 → 16.0.0-rc.129

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.
@@ -36,6 +36,39 @@ describe("focusManager", () => {
36
36
  expect(mockSetFocus).toBeCalledWith(null, undefined);
37
37
  });
38
38
 
39
+ it("restores focus when the previously focused item re-registers", () => {
40
+ const id = "player-controls-toggle-play-pause";
41
+
42
+ const makeComponent = (setFocus) => ({
43
+ setFocus,
44
+ setBlur: function () {},
45
+ blur: function () {},
46
+ willReceiveFocus: function () {},
47
+ willLoseFocus: function () {},
48
+ hasLostFocus: function () {},
49
+ isMounted: function () {
50
+ return true;
51
+ },
52
+ props: { id },
53
+ });
54
+
55
+ focusManager.register({ id, component: makeComponent(jest.fn()) });
56
+ focusManager.setFocus(id);
57
+ expect(focusManager.getCurrentFocus()?.props?.id).toBe(id);
58
+
59
+ // transport controls auto-hide: the focused button unmounts
60
+ focusManager.unregister(id);
61
+ expect(focusManager.getCurrentFocus()).toBeNull();
62
+
63
+ // user presses a key, controls become visible again and the button remounts
64
+ const remountedSetFocus = jest.fn();
65
+
66
+ focusManager.register({ id, component: makeComponent(remountedSetFocus) });
67
+
68
+ expect(focusManager.getCurrentFocus()?.props?.id).toBe(id);
69
+ expect(remountedSetFocus).toBeCalledTimes(1);
70
+ });
71
+
39
72
  describe("register", () => {});
40
73
  describe("unregister", () => {});
41
74
  describe("find", () => {});
@@ -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
+ }
@@ -472,7 +472,7 @@ export const focusManager = (function () {
472
472
  focusableTree.addNode({ id, component });
473
473
 
474
474
  if (!currentFocusNode && id === lastFocusedId && !id.includes("menu")) {
475
- setFocus(focusableTree.findInTree(id));
475
+ setFocus(id);
476
476
  }
477
477
 
478
478
  return component;
@@ -18,6 +18,7 @@ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
18
18
 
19
19
  const logger = createLogger({
20
20
  category: "zapp-react-native-utils:aliasPresentation",
21
+ subsystem: "core/actions",
21
22
  });
22
23
 
23
24
  const PLACEHOLDER_RED_BOX =
@@ -222,30 +222,37 @@ class FocusManager {
222
222
  return () => this.unregisterFocusable(focusableId);
223
223
  }
224
224
 
225
- unregisterFocusable(focusableId: string) {
225
+ unregisterFocusable(component: string | FocusManager.TouchableReactRef) {
226
+ const focusableId = isString(component)
227
+ ? component
228
+ : getFocusableId(component);
229
+
226
230
  const node = this.tree.find(focusableId);
227
231
  const parentNode = this.tree.findParent(focusableId);
228
232
 
233
+ const removesFocusedSubtree =
234
+ this._focusedId === focusableId ||
235
+ !!(this._focusedId && node?.findNode(this._focusedId));
236
+
229
237
  this.focusableComponents = this.focusableComponents.filter(
230
- (c) => c !== node?.component
238
+ (c) => c !== node?.component && getFocusableId(c) !== focusableId
231
239
  );
232
240
 
233
241
  this.tree.remove(focusableId);
234
242
 
235
- if (this._focusedId === focusableId) {
243
+ if (removesFocusedSubtree) {
236
244
  this._focusedId = null;
237
245
  this.retainFocus(parentNode);
238
246
  }
239
247
  }
240
248
 
241
- // Empty groups drop their focusable list after the feed fails, which is
242
- // after Layout's one-shot focus pass. Land on the nearest ancestor that is
243
- // still mounted so key handlers keep a target.
249
+ // Recover before parent-first unmounts discard the focused child's ancestry.
250
+ // Land on a mounted ancestor so key handlers keep a target.
244
251
  private retainFocus(node: TreeNode | null) {
245
252
  let current = node;
246
253
 
247
254
  while (current) {
248
- const ref = current.component;
255
+ const ref = FocusManager.findFocusable(current.id);
249
256
 
250
257
  if (ref?.current?.props?.id) {
251
258
  this.setFocusLocal(ref);
@@ -1,4 +1,7 @@
1
1
  import { focusManager } from "../FocusManager";
2
+ import { Touchable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable/Touchable";
3
+ import { Tree } from "../Tree";
4
+ import { TreeNode } from "../TreeNode";
2
5
 
3
6
  const isFocusableCell = true;
4
7
  const parentFocusableId = "parentFocusableId";
@@ -266,3 +269,112 @@ describe("FocusManager", () => {
266
269
  expect(focusManager.focusedId).toBe("child2");
267
270
  });
268
271
  });
272
+
273
+ describe("FocusManager subtree replacement", () => {
274
+ const createFocusable = (id: string) => ({
275
+ current: new Touchable({ id, children: null, onFocus: jest.fn() }),
276
+ });
277
+
278
+ let root: FocusManager.TouchableReactRef;
279
+ let rail: FocusManager.TouchableReactRef;
280
+ let cell: FocusManager.TouchableReactRef;
281
+ let sibling: FocusManager.TouchableReactRef;
282
+
283
+ const register = (
284
+ touchableRef: FocusManager.TouchableReactRef,
285
+ parentFocusableRef: FocusManager.TouchableReactRef
286
+ ) =>
287
+ focusManager.registerFocusable({
288
+ touchableRef,
289
+ parentFocusableRef,
290
+ isFocusableCell: true,
291
+ parentFocusableId: "",
292
+ });
293
+
294
+ beforeEach(() => {
295
+ root = createFocusable("replacement-root");
296
+ rail = createFocusable("replacement-rail");
297
+ cell = createFocusable("replacement-cell");
298
+ sibling = createFocusable("replacement-sibling");
299
+ register(root, { current: null });
300
+ register(rail, root);
301
+ register(cell, rail);
302
+ register(sibling, root);
303
+ focusManager.setFocus("replacement-cell");
304
+ });
305
+
306
+ afterEach(() => {
307
+ [
308
+ "replacement-cell",
309
+ "replacement-rail",
310
+ "replacement-sibling",
311
+ "replacement-root",
312
+ ].forEach((id) => focusManager.unregisterFocusable(id));
313
+
314
+ focusManager.resetFocus();
315
+ });
316
+
317
+ it("retains focus before a parent-first unmount removes the focused descendant's ancestry", () => {
318
+ focusManager.unregisterFocusable("replacement-rail");
319
+
320
+ expect(focusManager.focusedId).toBe("replacement-root");
321
+ expect(focusManager.focused).toBe(root.current);
322
+
323
+ focusManager.unregisterFocusable("replacement-cell");
324
+
325
+ expect(focusManager.focused).toBe(root.current);
326
+ });
327
+
328
+ it("removes descendant registrations even after their parent removed the tree nodes", () => {
329
+ focusManager.unregisterFocusable("replacement-rail");
330
+ focusManager.unregisterFocusable("replacement-cell");
331
+
332
+ expect(focusManager.focusableComponents).not.toContain(cell);
333
+ expect(focusManager.focusableComponents).not.toContain(rail);
334
+
335
+ const replacementRail = createFocusable("replacement-rail");
336
+ const replacementCell = createFocusable("replacement-cell");
337
+ register(replacementRail, root);
338
+ register(replacementCell, replacementRail);
339
+ focusManager.setFocus("replacement-cell");
340
+
341
+ expect(focusManager.focused).toBe(replacementCell.current);
342
+ expect(focusManager.isFocusableChildOf(replacementCell, root)).toBe(true);
343
+ });
344
+
345
+ it("does not move focus when an unrelated subtree unregisters", () => {
346
+ focusManager.setFocus("replacement-sibling");
347
+ focusManager.unregisterFocusable("replacement-rail");
348
+ focusManager.unregisterFocusable("replacement-cell");
349
+
350
+ expect(focusManager.focused).toBe(sibling.current);
351
+ });
352
+
353
+ it("resolves a placeholder ancestor through its mounted registration", () => {
354
+ const findParent = jest
355
+ .spyOn(Tree.prototype, "findParent")
356
+ .mockReturnValueOnce(new TreeNode(null, "replacement-root", "", false));
357
+
358
+ focusManager.unregisterFocusable("replacement-rail");
359
+ findParent.mockRestore();
360
+
361
+ expect(focusManager.focused).toBe(root.current);
362
+ });
363
+
364
+ it("retains focus through child-first cleanup", () => {
365
+ focusManager.unregisterFocusable("replacement-cell");
366
+ expect(focusManager.focused).toBe(rail.current);
367
+
368
+ focusManager.unregisterFocusable("replacement-rail");
369
+ expect(focusManager.focused).toBe(root.current);
370
+ });
371
+
372
+ it("clears focus when the entire root containing the focused cell unregisters", () => {
373
+ focusManager.unregisterFocusable("replacement-root");
374
+ focusManager.unregisterFocusable("replacement-rail");
375
+ focusManager.unregisterFocusable("replacement-cell");
376
+
377
+ expect(focusManager.focusedId).toBeNull();
378
+ expect(focusManager.focused).toBeNull();
379
+ });
380
+ });
@@ -0,0 +1,208 @@
1
+ import { registerXrayToolbox, XrayToolSpec } from "../logger/xrayToolbox";
2
+
3
+ import { focusManager } from "./FocusManager";
4
+ import { TreeNode } from "./TreeNode";
5
+ import { Tree } from "./Tree";
6
+
7
+ import type { Touchable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable/Touchable";
8
+
9
+ /**
10
+ * X-Ray `focus.*` toolbox for Android TV: lets an agent read and move focus by focusable id,
11
+ * without a remote and without depending on screen size or layout. It is built on the
12
+ * class-based FocusManager that Android uses (unlike tvOS, which uses the IIFE focus manager
13
+ * with its own native focus module).
14
+ *
15
+ * The manager's `focusedId` follows the native Android focus engine (the app's own code moves
16
+ * focus through the manager, and native focus events report back into it), and `setFocus`
17
+ * moves focus the same way the app's own code does. Registered by the android focus manager
18
+ * module; skipped when the X-Ray plugin has no React toolbox API (release builds).
19
+ */
20
+
21
+ type FocusManagerApi = {
22
+ focusedId: string | null;
23
+ isFocused: (id: string | number) => boolean;
24
+ setFocus: (newFocus: string, options?: unknown, context?: unknown) => void;
25
+ focused: Touchable | null | undefined;
26
+ };
27
+
28
+ /** `Tree` keeps its roots in a private field; this is the only access point to it. */
29
+ const internalTree = (manager: FocusManagerApi): Tree | undefined => {
30
+ const holder = manager as FocusManagerApi & { tree?: Tree };
31
+
32
+ return holder.tree;
33
+ };
34
+
35
+ /** The tree's roots, through the private field. */
36
+ const treeRoots = (tree: Tree): TreeNode[] =>
37
+ (tree as unknown as { tree: TreeNode[] }).tree;
38
+
39
+ const nodeProps = (node: TreeNode | null): { testID?: unknown } =>
40
+ (node?.component?.current?.props ?? {}) as { testID?: unknown };
41
+
42
+ /**
43
+ * The focused item. On Android the manager's `focusedId` is the focused focusable itself and
44
+ * follows the native engine, so no tree walk is needed (unlike tvOS, where it only tracks
45
+ * focus across groups).
46
+ */
47
+ const describeFocused = (manager: FocusManagerApi) => {
48
+ const itemId = manager.focusedId;
49
+
50
+ if (!itemId) return null;
51
+
52
+ const tree = internalTree(manager);
53
+ const node = tree?.find(itemId) ?? null;
54
+ const groups: string[] = [];
55
+
56
+ let parent = node?.parentId ? tree?.findParent(node.parentId) : null;
57
+
58
+ while (parent?.id && groups.length < 32) {
59
+ groups.push(parent.id);
60
+ parent = parent.parentId ? tree?.findParent(parent.parentId) : null;
61
+ }
62
+
63
+ const testID = nodeProps(node).testID;
64
+
65
+ return {
66
+ itemId,
67
+ groupId: node?.parentId ?? null,
68
+ testID: typeof testID === "string" ? testID : null,
69
+ groups,
70
+ };
71
+ };
72
+
73
+ type TreeView = {
74
+ id: string;
75
+ group?: true;
76
+ focused?: true;
77
+ testID?: string;
78
+ children?: TreeView[];
79
+ };
80
+
81
+ /** A node as the agent sees it: keys only when they say something, to keep large screens short. */
82
+ const toTreeView = (manager: FocusManagerApi, node: TreeNode): TreeView => {
83
+ const testID = nodeProps(node).testID;
84
+
85
+ const children = (node.children ?? []).map((child) =>
86
+ toTreeView(manager, child)
87
+ );
88
+
89
+ return {
90
+ id: node.id,
91
+ ...(node.isFocusableCell ? {} : { group: true as const }),
92
+ ...(manager.isFocused(node.id) ? { focused: true as const } : {}),
93
+ ...(typeof testID === "string" ? { testID } : {}),
94
+ ...(children.length ? { children } : {}),
95
+ };
96
+ };
97
+
98
+ const tools = (manager: FocusManagerApi): XrayToolSpec[] => [
99
+ {
100
+ name: "current",
101
+ description:
102
+ "The focused item: itemId, groupId, testID and the ids of its enclosing groups. null when nothing is.",
103
+ handler: () => describeFocused(manager),
104
+ },
105
+ {
106
+ name: "tree",
107
+ description:
108
+ "The focus manager's tree of registered Focusables: id, group: true for groups, focused: true on " +
109
+ "the focused item, testID, children. Only rendered Focusables are registered. A screen can hold " +
110
+ "hundreds; pass groupId for one group's subtree. Item ids are what set takes.",
111
+ parameters: [
112
+ {
113
+ name: "groupId",
114
+ type: "string",
115
+ description:
116
+ "Return only this group's subtree. Default: the whole tree.",
117
+ required: false,
118
+ },
119
+ ],
120
+ handler: ({ groupId }) => {
121
+ const tree = internalTree(manager);
122
+
123
+ if (!tree) throw new Error("Focus manager tree is not available");
124
+
125
+ if (groupId === undefined || groupId === null || groupId === "") {
126
+ return treeRoots(tree).map((root) => toTreeView(manager, root));
127
+ }
128
+
129
+ const node = tree.find(String(groupId));
130
+
131
+ if (!node) throw new Error(`No Focusable group "${groupId}"`);
132
+
133
+ return toTreeView(manager, node);
134
+ },
135
+ },
136
+ {
137
+ name: "set",
138
+ description:
139
+ "Focus an item through the focus manager (setFocus), as the app's own code does. " +
140
+ "focused: false when it did not land within 3 s (unknown ids, or the item is not rendered, e.g. " +
141
+ "scrolled out of a virtualised list). It replaces a focus the app is still setting, so call it " +
142
+ "once the screen is idle (ui.waitFor idle).",
143
+ parameters: [
144
+ {
145
+ name: "itemId",
146
+ type: "string",
147
+ description: "Focusable item id (from tree).",
148
+ },
149
+ ],
150
+ handler: ({ itemId }) =>
151
+ new Promise((resolve) => {
152
+ let done = false;
153
+
154
+ const finish = (result: { focused: boolean; timedOut?: boolean }) => {
155
+ if (done) return;
156
+
157
+ done = true;
158
+ resolve({ ...result, current: describeFocused(manager) });
159
+ };
160
+
161
+ const timer = setTimeout(
162
+ () => finish({ focused: false, timedOut: true }),
163
+ 3000
164
+ );
165
+
166
+ const poll = () => {
167
+ if (done) return;
168
+
169
+ if (manager.isFocused(String(itemId))) {
170
+ clearTimeout(timer);
171
+ finish({ focused: true });
172
+ } else {
173
+ setTimeout(poll, 50);
174
+ }
175
+ };
176
+
177
+ manager.setFocus(String(itemId));
178
+ setTimeout(poll, 50);
179
+ }),
180
+ },
181
+ {
182
+ name: "select",
183
+ description:
184
+ "Press select on the focused item, as the remote's click does.",
185
+ handler: () => {
186
+ const ref = manager.focused;
187
+
188
+ if (!ref?.onPress) {
189
+ throw new Error("Nothing selectable is focused");
190
+ }
191
+
192
+ // The app's focus callbacks pass the Touchable instance (ref.props.id), so onPress gets the instance too.
193
+ ref.onPress(ref);
194
+
195
+ return { selected: describeFocused(manager) };
196
+ },
197
+ },
198
+ ];
199
+
200
+ export const registerAndroidFocusToolbox = (
201
+ manager: FocusManagerApi = focusManager
202
+ ) =>
203
+ registerXrayToolbox({
204
+ name: "focus",
205
+ description:
206
+ "Android TV focus: current item, Focusable tree, focus by id, select.",
207
+ tools: tools(manager),
208
+ });
@@ -7,6 +7,7 @@ import { toBooleanWithDefaultTrue } from "../booleanUtils";
7
7
  import { isNilOrEmpty } from "../reactUtils/helpers";
8
8
  import { isAndroidTVPlatform } from "../reactUtils";
9
9
  import { noop } from "../functionUtils";
10
+ import { registerAndroidFocusToolbox } from "./focusToolbox";
10
11
 
11
12
  export function useFocusManager() {
12
13
  return focusManager;
@@ -132,3 +133,9 @@ export const useIsFocusable = (props: Props): void => {
132
133
  hasDataError,
133
134
  ]);
134
135
  };
136
+
137
+ // The Android focus manager registers the X-Ray focus toolbox itself (mirrors the tvOS focus
138
+ // manager); it is a no-op in builds without the X-Ray React toolbox bridge.
139
+ if (isAndroidTVPlatform()) {
140
+ registerAndroidFocusToolbox(focusManager);
141
+ }
@@ -1,4 +1,3 @@
1
- import { getXray } from "@applicaster/zapp-react-native-utils/logger";
2
- const { Logger } = getXray();
1
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
3
2
 
4
- export const logger = new Logger("FocusManager", "ui/focus");
3
+ export const logger = subsystemLogger("ui/focus", "FocusManager");
@@ -1,7 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
 
4
- import { XRAY_SUBSYSTEMS } from "../subsystems";
4
+ import { PLUGIN_KINDS, XRAY_SUBSYSTEMS } from "../subsystems";
5
5
 
6
6
  const REPO_ROOT = path.resolve(__dirname, "../../../..");
7
7
  const SOURCE_DIRS = ["packages", "plugins"];
@@ -16,15 +16,35 @@ const SKIP_DIRS = new Set([
16
16
  "ios",
17
17
  ]);
18
18
 
19
- // `subsystem: "x"`, `Subsystem = "x"`, `subsystemLogger("x"` and `new Logger("Category", "x"`
19
+ const SHARED_LOGGER_DIR = "packages/zapp-react-native-utils/logger/";
20
+
21
+ // `subsystem: "x"`, `anySubsystem = "x"`, `subsystemLogger("x"` and `new Logger("Category", "x"`
20
22
  const SUBSYSTEM_LITERALS = [
21
23
  /\bsubsystem:\s*"([^"]+)"/g,
22
- /\b(?:Subsystem|SUBSYSTEM|BaseSubsystem)\s*=\s*"([^"]+)"/g,
24
+ /\b\w*(?:Subsystem|SUBSYSTEM)\s*=\s*"([^"]+)"/g,
23
25
  /\bsubsystemLogger\(\s*"([^"]+)"/g,
24
26
  /\bnew Logger\(\s*"[^"]*"\s*,\s*"([^"]+)"/g,
25
27
  ];
26
28
 
27
- const PLUGIN_NODE = /^plugins\/[a-z0-9_]+\/[a-z0-9_]+(\/[a-z0-9_]+)?$/;
29
+ const PLUGIN_NODE = new RegExp(
30
+ `^plugins/(?:${PLUGIN_KINDS.join("|")})/[a-z0-9_]+(/[a-z0-9_]+)?$`
31
+ );
32
+
33
+ // A template string is built at runtime, so it cannot be checked against the tree.
34
+ const TEMPLATE_SUBSYSTEMS = [
35
+ /\bsubsystem:\s*`/,
36
+ /\b\w*(?:Subsystem|SUBSYSTEM)\s*=\s*`/,
37
+ /\bsubsystemLogger\(\s*`/,
38
+ ];
39
+
40
+ const SHARED_CREATE_LOGGER_IMPORT =
41
+ /import\s*\{[^}]*\bcreateLogger\b[^}]*\}\s*from\s*"@applicaster\/zapp-react-native-utils\/logger"/;
42
+
43
+ // Inside zapp-react-native-utils the shared logger is imported by a relative path.
44
+ const RELATIVE_CREATE_LOGGER_IMPORT =
45
+ /import\s*\{[^}]*\bcreateLogger\b[^}]*\}\s*from\s*"(?:\.\.\/)+logger"/;
46
+
47
+ const CREATE_LOGGER_CALLS = /\bcreateLogger\(\s*(\{[^}]*\})?\s*\)/g;
28
48
 
29
49
  // Native-side keys read by the X-Ray sinks, not nodes of the tree.
30
50
  const NOT_TREE_NODES = new Set(["xray", "xray/logger"]);
@@ -46,23 +66,31 @@ const sourceFiles = (dir: string): string[] =>
46
66
  : [];
47
67
  });
48
68
 
69
+ // Commented-out code does not log.
70
+ const loggingSources = () =>
71
+ SOURCE_DIRS.flatMap((dir) => sourceFiles(path.join(REPO_ROOT, dir)))
72
+ .map((file) => path.relative(REPO_ROOT, file))
73
+ .filter((file) => !LEFT_OUT.some((dir) => file.startsWith(dir)))
74
+ .map((file) => ({
75
+ file,
76
+ text: fs
77
+ .readFileSync(path.join(REPO_ROOT, file), "utf8")
78
+ .replace(/^\s*\/\/.*$/gm, ""),
79
+ }));
80
+
81
+ const usesSharedCreateLogger = (file: string, text: string) =>
82
+ SHARED_CREATE_LOGGER_IMPORT.test(text) ||
83
+ (file.startsWith("packages/zapp-react-native-utils/") &&
84
+ RELATIVE_CREATE_LOGGER_IMPORT.test(text));
85
+
49
86
  describe("X-Ray subsystems", () => {
87
+ const sources = loggingSources();
88
+
50
89
  it("only uses nodes of the subsystem tree", () => {
51
90
  const known = new Set<string>(XRAY_SUBSYSTEMS);
52
91
  const unknown: string[] = [];
53
92
 
54
- SOURCE_DIRS.flatMap((dir) =>
55
- sourceFiles(path.join(REPO_ROOT, dir))
56
- ).forEach((file) => {
57
- if (
58
- LEFT_OUT.some((dir) => path.relative(REPO_ROOT, file).startsWith(dir))
59
- ) {
60
- return;
61
- }
62
-
63
- // commented-out code does not log
64
- const text = fs.readFileSync(file, "utf8").replace(/^\s*\/\/.*$/gm, "");
65
-
93
+ sources.forEach(({ file, text }) => {
66
94
  SUBSYSTEM_LITERALS.forEach((pattern) => {
67
95
  Array.from(text.matchAll(pattern)).forEach((match) => {
68
96
  const node = match[1];
@@ -72,7 +100,7 @@ describe("X-Ray subsystems", () => {
72
100
  !PLUGIN_NODE.test(node) &&
73
101
  !NOT_TREE_NODES.has(node)
74
102
  ) {
75
- unknown.push(`${path.relative(REPO_ROOT, file)}: "${node}"`);
103
+ unknown.push(`${file}: "${node}"`);
76
104
  }
77
105
  });
78
106
  });
@@ -81,4 +109,40 @@ describe("X-Ray subsystems", () => {
81
109
  // Add the node to the tree (xray-subsystems skill in Zapp-Frameworks) and to XRAY_SUBSYSTEMS first.
82
110
  expect(unknown).toEqual([]);
83
111
  });
112
+
113
+ it("does not build a subsystem from a template string", () => {
114
+ const templates = sources
115
+ .filter(
116
+ ({ file, text }) =>
117
+ !file.startsWith(SHARED_LOGGER_DIR) &&
118
+ TEMPLATE_SUBSYSTEMS.some((pattern) => pattern.test(text))
119
+ )
120
+ .map(({ file }) => file);
121
+
122
+ expect(templates).toEqual([]);
123
+ });
124
+
125
+ it("does not call the shared createLogger without a subsystem", () => {
126
+ const missing = sources
127
+ .filter(({ file, text }) => usesSharedCreateLogger(file, text))
128
+ .flatMap(({ file, text }) =>
129
+ Array.from(text.matchAll(CREATE_LOGGER_CALLS))
130
+ .filter(([, args]) => !/\bsubsystem\b/.test(args ?? ""))
131
+ .map(([call]) => `${file}: ${call}`)
132
+ );
133
+
134
+ expect(missing).toEqual([]);
135
+ });
136
+
137
+ it("creates loggers through the shared logger module, not new Logger", () => {
138
+ const direct = sources
139
+ .filter(
140
+ ({ file, text }) =>
141
+ !file.startsWith(SHARED_LOGGER_DIR) && /\bnew Logger\(/.test(text)
142
+ )
143
+ .map(({ file }) => file);
144
+
145
+ // Use subsystemLogger(subsystem, category).
146
+ expect(direct).toEqual([]);
147
+ });
84
148
  });
package/logger/index.ts CHANGED
@@ -120,11 +120,16 @@ function useLogger(
120
120
 
121
121
  const createLogger = ({
122
122
  category = "General",
123
- subsystem = "MyPlugin",
123
+ subsystem,
124
124
  parent = null,
125
+ }: {
126
+ category?: string;
127
+ subsystem: XraySubsystem;
128
+ parent?: XRayLoggerI | null;
125
129
  }) => {
126
130
  const XRayLogger = getXray().Logger as any;
127
- const logger = new XRayLogger(category, subsystem, parent);
131
+ // The type requires a subsystem; the fallback only keeps already built plugins working.
132
+ const logger = new XRayLogger(category, subsystem ?? "MyPlugin", parent);
128
133
 
129
134
  const log_verbose = (message: string, data: any = null) => {
130
135
  logger.log({
@@ -77,7 +77,36 @@ export const XRAY_SUBSYSTEMS = [
77
77
  "ui/styles",
78
78
  ] as const;
79
79
 
80
+ /** The plugin kinds of the shared tree. A new kind goes to the tree and to this list. */
81
+ export const PLUGIN_KINDS = [
82
+ "actions",
83
+ "ads",
84
+ "analytics",
85
+ "auth",
86
+ "cmp",
87
+ "crashlogs",
88
+ "general",
89
+ "parental_control",
90
+ "player",
91
+ "player_overlay",
92
+ "purchases",
93
+ "push",
94
+ "sports",
95
+ "storage",
96
+ "ui",
97
+ "ui_component",
98
+ "universal_links",
99
+ "video_ads",
100
+ ] as const;
101
+
80
102
  /** A plugin logs to its own node: `plugins/<kind>/<name>[/<component>]`, for example `plugins/ui_component/grid`. */
81
- export type PluginSubsystem = `plugins/${string}/${string}`;
103
+ export type PluginSubsystem =
104
+ `plugins/${(typeof PLUGIN_KINDS)[number]}/${string}`;
105
+
106
+ /** Not a node of the tree: the native error collection sinks build error reports from events with this prefix. */
107
+ export type ErrorReportSubsystem = `error_report_collector/${string}`;
82
108
 
83
- export type XraySubsystem = (typeof XRAY_SUBSYSTEMS)[number] | PluginSubsystem;
109
+ export type XraySubsystem =
110
+ | (typeof XRAY_SUBSYSTEMS)[number]
111
+ | PluginSubsystem
112
+ | ErrorReportSubsystem;
@@ -8,6 +8,8 @@ export type XrayToolSpec = {
8
8
  name: string;
9
9
  type: "number" | "string";
10
10
  description: string;
11
+ /** Defaults to true on the native side. */
12
+ required?: boolean;
11
13
  }>;
12
14
  handler: (args: Record<string, unknown>) => unknown;
13
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-rc.127",
3
+ "version": "16.0.0-rc.129",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-rc.127",
30
+ "@applicaster/applicaster-types": "16.0.0-rc.129",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -9,9 +9,7 @@ import {
9
9
 
10
10
  import { skipIf, shouldHandleOrientationChange } from "../utils";
11
11
 
12
- import { getXray } from "@applicaster/zapp-react-native-utils/logger";
13
- const { Logger } = getXray();
14
-
12
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
15
13
  type Props = {
16
14
  isPortrait: boolean;
17
15
  onTransitToPortrait: () => void;
@@ -20,7 +18,7 @@ type Props = {
20
18
  docked: boolean;
21
19
  };
22
20
 
23
- export const logger = new Logger("hooks", "player/modal");
21
+ export const logger = subsystemLogger("player/modal", "hooks");
24
22
 
25
23
  export const useChangeOrientation = ({
26
24
  isPortrait,
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { NativeModules, View, StyleSheet } from "react-native";
3
- import { getXray } from "@applicaster/zapp-react-native-utils/logger";
3
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
4
4
 
5
5
  import { isApplePlatform, isWeb, isTV } from "../reactUtils";
6
6
  import { useRivers } from "../reactHooks";
@@ -41,9 +41,7 @@ type MeasurementContext = {
41
41
  onLayout: (index: number) => (event) => void;
42
42
  };
43
43
 
44
- const { Logger } = getXray();
45
-
46
- const logger = new Logger("general", "ui/river");
44
+ const logger = subsystemLogger("ui/river", "general");
47
45
 
48
46
  let notified = false;
49
47