@applicaster/zapp-react-native-utils 17.0.0-rc.6 → 17.0.0-rc.7
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.
- package/actionsExecutor/actions/navigateToScreen.ts +3 -11
- package/appUtils/focusManager/__tests__/focusLogs.test.ts +137 -0
- package/appUtils/focusManager/focusLogsFlag.ts +48 -0
- package/appUtils/focusManager/index.ts +117 -10
- package/navigationUtils/index.ts +25 -0
- package/package.json +2 -2
- package/reactHooks/navigation/usePresentScreen.ts +4 -11
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +22 -0
- package/reactHooks/resolvers/useCellResolver.ts +4 -1
|
@@ -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,14 +97,14 @@ export function createNavigateToScreenAction(
|
|
|
96
97
|
const screenId = contentTypes?.[screenType]?.screen_id || null;
|
|
97
98
|
const river = rivers?.[screenId];
|
|
98
99
|
|
|
99
|
-
if (!
|
|
100
|
+
if (!river) {
|
|
100
101
|
log_error(
|
|
101
102
|
`navigateToScreen: can not resolve screen type mapping: ${screenType}`,
|
|
102
103
|
{
|
|
103
104
|
// For X-Ray diagnostics: keep when the message is reworded.
|
|
104
105
|
diagnostic: {
|
|
105
106
|
code: "action-type-mapping",
|
|
106
|
-
case:
|
|
107
|
+
case: getTypeMappingCase(screenType, rivers, contentTypes),
|
|
107
108
|
},
|
|
108
109
|
type_mapping: screenType,
|
|
109
110
|
}
|
|
@@ -112,15 +113,6 @@ export function createNavigateToScreenAction(
|
|
|
112
113
|
return ActionResult.Error;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
if (!river) {
|
|
116
|
-
log_error("navigateToScreen: can not resolve river", {
|
|
117
|
-
diagnostic: { code: "action-type-mapping", case: "screen_deleted" },
|
|
118
|
-
type_mapping: screenType,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
return ActionResult.Error;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
116
|
navigatingEntry = river;
|
|
125
117
|
}
|
|
126
118
|
|
|
@@ -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)
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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)
|
|
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
|
|
package/navigationUtils/index.ts
CHANGED
|
@@ -384,6 +384,31 @@ export const usesVideoModal = (
|
|
|
384
384
|
return targetScreenConfiguration?.styles?.use_video_modal;
|
|
385
385
|
};
|
|
386
386
|
|
|
387
|
+
/**
|
|
388
|
+
* The X-Ray type-mapping case for a type that leads to no screen. Read from the layout's own
|
|
389
|
+
* content types: mapContentTypesToRivers (useContentTypes) drops a type with no screen or with a
|
|
390
|
+
* screen that is not in the layout, so it cannot tell these apart from a missing type.
|
|
391
|
+
*/
|
|
392
|
+
export const getTypeMappingCase = (
|
|
393
|
+
type: string,
|
|
394
|
+
rivers: Record<string, ZappRiver> | undefined,
|
|
395
|
+
contentTypes?: ZappContentTypes | null
|
|
396
|
+
): "missing" | "no_screen" | "screen_deleted" => {
|
|
397
|
+
let layoutContentTypes = contentTypes;
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
layoutContentTypes = appStore.get("contentTypes") ?? contentTypes;
|
|
401
|
+
} catch {
|
|
402
|
+
// No store yet (unit tests): the content types passed in are all there is.
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const screenId = layoutContentTypes?.[type]?.screen_id;
|
|
406
|
+
|
|
407
|
+
if (!layoutContentTypes?.[type]) return "missing";
|
|
408
|
+
|
|
409
|
+
return screenId && !rivers?.[screenId] ? "screen_deleted" : "no_screen";
|
|
410
|
+
};
|
|
411
|
+
|
|
387
412
|
export const mapContentTypesToRivers = (
|
|
388
413
|
state: Partial<RootState>
|
|
389
414
|
): ZappContentTypesMapped | null => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "17.0.0-rc.
|
|
3
|
+
"version": "17.0.0-rc.7",
|
|
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": "17.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "17.0.0-rc.7",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -6,6 +6,7 @@ import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
|
6
6
|
import { modalStore } from "../../modalState";
|
|
7
7
|
import { isWeb } from "../../reactUtils";
|
|
8
8
|
import { createLogger } from "../../logger";
|
|
9
|
+
import { getTypeMappingCase } from "../../navigationUtils";
|
|
9
10
|
import { useRivers } from "../state";
|
|
10
11
|
|
|
11
12
|
const { log_error, log_info } = createLogger({
|
|
@@ -78,27 +79,19 @@ export const presentScreen = ({
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
const screenId = contentTypes?.[typeMapping]?.screen_id;
|
|
82
|
+
const river = screenId ? rivers?.[screenId] : undefined;
|
|
81
83
|
|
|
82
|
-
if (!
|
|
84
|
+
if (!river) {
|
|
83
85
|
return failure(`can not resolve screen type mapping: ${typeMapping}`, {
|
|
84
86
|
// For X-Ray diagnostics: keep when the message is reworded.
|
|
85
87
|
diagnostic: {
|
|
86
88
|
code: "action-type-mapping",
|
|
87
|
-
case:
|
|
89
|
+
case: getTypeMappingCase(typeMapping, rivers, contentTypes),
|
|
88
90
|
},
|
|
89
91
|
type_mapping: typeMapping,
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
const river = rivers?.[screenId];
|
|
94
|
-
|
|
95
|
-
if (!river) {
|
|
96
|
-
return failure(`can not resolve river for screen id: ${screenId}`, {
|
|
97
|
-
diagnostic: { code: "action-type-mapping", case: "screen_deleted" },
|
|
98
|
-
type_mapping: typeMapping,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
95
|
return new Promise<PresentScreenResult>((resolve) => {
|
|
103
96
|
let settled = false;
|
|
104
97
|
let unsubscribe: () => void = () => {};
|
|
@@ -66,4 +66,26 @@ describe("cellResolver", () => {
|
|
|
66
66
|
|
|
67
67
|
expect(testCellModule).toBeCalled();
|
|
68
68
|
});
|
|
69
|
+
|
|
70
|
+
it("does not share a renderer between components with the same styles", () => {
|
|
71
|
+
testCellModule.mockClear();
|
|
72
|
+
|
|
73
|
+
renderHook(
|
|
74
|
+
() => useCellResolver({ component: { ...component, id: "a" } }),
|
|
75
|
+
{
|
|
76
|
+
wrapper,
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
renderHook(
|
|
81
|
+
() => useCellResolver({ component: { ...component, id: "b" } }),
|
|
82
|
+
{
|
|
83
|
+
wrapper,
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(testCellModule).toHaveBeenCalledTimes(2);
|
|
88
|
+
|
|
89
|
+
expect(testCellModule.mock.calls[1][0].component.id).toBe("b");
|
|
90
|
+
});
|
|
69
91
|
});
|
|
@@ -36,7 +36,7 @@ type Props = {
|
|
|
36
36
|
const cellWidthLens = R.lensPath(["styles", "cell_width"]);
|
|
37
37
|
const viewAtCellWidth = R.view(cellWidthLens);
|
|
38
38
|
const setCellWidth = R.set(cellWidthLens);
|
|
39
|
-
const MEMOIZED_LENGTH =
|
|
39
|
+
const MEMOIZED_LENGTH = 10;
|
|
40
40
|
|
|
41
41
|
const cellRenderer = (...args) => CellRendererResolver(args[MEMOIZED_LENGTH]); // pick 6th argument with data
|
|
42
42
|
|
|
@@ -79,6 +79,9 @@ export function useCellResolver({
|
|
|
79
79
|
|
|
80
80
|
return memoCellRenderer(
|
|
81
81
|
/* memoizee check prop list */
|
|
82
|
+
// The renderer is built from the component (its type, styles and X-Ray diagnostics), so two
|
|
83
|
+
// components without a cell style must not share one.
|
|
84
|
+
_component?.id,
|
|
82
85
|
cell_plugin_configuration_id,
|
|
83
86
|
width,
|
|
84
87
|
height,
|