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

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 (164) 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 +46 -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/index.ts +10 -2
  29. package/appUtils/HooksManager/logger.ts +5 -2
  30. package/appUtils/accessibilityManager/logger.ts +2 -4
  31. package/appUtils/accessibilityManager/utils.ts +1 -1
  32. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
  33. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  34. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  35. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
  36. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  37. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  38. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  39. package/appUtils/contextKeysManager/index.ts +30 -131
  40. package/appUtils/focusManager/__tests__/focusManager.test.js +33 -0
  41. package/appUtils/focusManager/__tests__/focusToolbox.test.ts +357 -0
  42. package/appUtils/focusManager/focusToolbox.ts +223 -0
  43. package/appUtils/focusManager/index.ios.ts +7 -1
  44. package/appUtils/focusManager/index.ts +3 -3
  45. package/appUtils/focusManager/logger.ts +2 -2
  46. package/appUtils/focusManagerAux/index.ts +2 -2
  47. package/appUtils/orientationHelper.ts +2 -2
  48. package/appUtils/platform/platformUtils.ts +6 -22
  49. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +1 -1
  50. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  51. package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
  52. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  53. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  54. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  55. package/appUtils/playerManager/const.ts +13 -0
  56. package/appUtils/playerManager/index.ts +9 -2
  57. package/appUtils/playerManager/player.ts +28 -1
  58. package/appUtils/playerManager/playerNative.ts +23 -1
  59. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  60. package/appUtils/playerManager/playerToolbox.ts +196 -0
  61. package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
  62. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  63. package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
  64. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  65. package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
  66. package/arrayUtils/index.ts +26 -43
  67. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  68. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  69. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  70. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  71. package/cellUtils/index.ts +40 -0
  72. package/cellUtils/logger.ts +2 -2
  73. package/configurationUtils/__tests__/modalBlocksParser.test.ts +134 -0
  74. package/configurationUtils/modalBlocksParser.ts +38 -0
  75. package/debugging/DebugFeatues.tsx +2 -25
  76. package/debugging/DebugFeatures.ts +495 -0
  77. package/debugging/__tests__/DebugFeatures.test.ts +313 -0
  78. package/debugging/index.ts +3 -0
  79. package/domUtils/logger.ts +2 -2
  80. package/entryActions/aliasPresentation.ts +1 -0
  81. package/entryActions/buildEntryActions.ts +1 -1
  82. package/errorUtils/index.ts +2 -0
  83. package/focusManager/FocusManager.ts +43 -6
  84. package/focusManager/__tests__/FocusManager.test.ts +124 -3
  85. package/focusManager/focusToolbox.ts +208 -0
  86. package/focusManager/index.ts +7 -0
  87. package/focusManager/logger.ts +2 -6
  88. package/headersUtils/index.ts +2 -2
  89. package/localizationUtils/index.ts +12 -6
  90. package/logger/__tests__/subsystems.test.ts +148 -0
  91. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  92. package/logger/index.ts +48 -9
  93. package/logger/subsystems.ts +112 -0
  94. package/logger/xrayToolbox.ts +69 -0
  95. package/manifestUtils/__tests__/createConfig.test.js +17 -7
  96. package/manifestUtils/_internals/getDefaultConfiguration.js +9 -11
  97. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  98. package/manifestUtils/keys.js +7 -2
  99. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  100. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  101. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  102. package/modalState/EditableCollectionRegistry.ts +1 -1
  103. package/modalState/ModalOrchestrator.ts +1 -0
  104. package/modalState/RemoteEditableCollection.ts +1 -1
  105. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +23 -0
  106. package/modalState/index.ts +2 -0
  107. package/modalState/types.ts +11 -0
  108. package/navigationUtils/index.ts +5 -2
  109. package/navigationUtils/xrayNavigator.ts +12 -0
  110. package/numberUtils/index.ts +2 -2
  111. package/package.json +3 -2
  112. package/playerUtils/PlayerTTS/PlayerTTS.ts +1 -1
  113. package/playerUtils/imaScriptDom.ts +1 -1
  114. package/playerUtils/useValidatePlayerConfig.tsx +1 -1
  115. package/pluginUtils/logger.ts +2 -2
  116. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  117. package/quickBrickAssets/index.ts +35 -0
  118. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  119. package/reactHooks/actions/index.ts +29 -23
  120. package/reactHooks/cell-click/__tests__/index.test.js +67 -1
  121. package/reactHooks/cell-click/helpers.ts +3 -1
  122. package/reactHooks/cell-click/index.ts +10 -2
  123. package/reactHooks/connection/index.tsx +8 -5
  124. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  125. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  126. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  127. package/reactHooks/feed/useBuildPipesUrl.ts +5 -2
  128. package/reactHooks/feed/useFeedLoader.tsx +30 -3
  129. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  130. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  131. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
  132. package/reactHooks/logger.ts +5 -2
  133. package/reactHooks/navigation/usePresentScreen.ts +19 -6
  134. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +2 -2
  135. package/reactHooks/resolvers/useComponentResolver.ts +10 -0
  136. package/reactHooks/screen/useScreenData.ts +2 -2
  137. package/reactHooks/usePluginConfiguration.ts +84 -46
  138. package/reactHooks/videoModal/hooks/useChangeOrientation.ts +2 -7
  139. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +1 -1
  140. package/reactUtils/__tests__/deviceTargetGuards.test.js +73 -0
  141. package/reactUtils/createContext/helpers.ts +2 -2
  142. package/reactUtils/index.ts +28 -0
  143. package/reactUtils/logger.ts +2 -2
  144. package/riverComponetsMeasurementProvider/index.tsx +5 -5
  145. package/storage/ScreenSingleValueProvider.ts +1 -1
  146. package/storage/ScreenStateMultiSelectProvider.ts +1 -1
  147. package/storage/StorageMultiSelectProvider.ts +1 -1
  148. package/storage/StorageSingleSelectProvider.ts +1 -1
  149. package/stylesUtils/logger.ts +2 -2
  150. package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
  151. package/uiActionsRegistrator/registry.ts +17 -1
  152. package/uiActionsRegistrator/resolveActionIdentifiers.ts +6 -2
  153. package/uiActionsRegistrator/usableActionItems.ts +1 -1
  154. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +2 -1
  155. package/zappFrameworkUtils/loginPluginUtils.ts +2 -1
  156. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -1
  157. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  158. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  159. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  160. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  161. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  162. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  163. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  164. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
@@ -0,0 +1,313 @@
1
+ import { localStorage as NativeLocalStorageMock } from "../../../zapp-react-native-bridge/ZappStorage/__mocks__/android";
2
+
3
+ const STATE_KEY = "__applicasterDebugFeatures";
4
+
5
+ type LoadedModule = {
6
+ DebugFeaturesModule: typeof import("../DebugFeatures");
7
+ LegacyModule: typeof import("../DebugFeatues");
8
+ ReactNative: typeof import("react-native");
9
+ };
10
+
11
+ const loadModules = (
12
+ nativeDebugBridge?: Record<string, jest.Mock>
13
+ ): LoadedModule => {
14
+ delete (globalThis as any)[STATE_KEY];
15
+ NativeLocalStorageMock.__clear();
16
+
17
+ let DebugFeaturesModule: typeof import("../DebugFeatures");
18
+ let LegacyModule: typeof import("../DebugFeatues");
19
+ let ReactNative: typeof import("react-native");
20
+
21
+ jest.isolateModules(() => {
22
+ ReactNative = require("react-native");
23
+ ReactNative.NativeModules.LocalStorage = NativeLocalStorageMock;
24
+
25
+ if (nativeDebugBridge) {
26
+ ReactNative.NativeModules.DebugFeaturesBridge = nativeDebugBridge;
27
+ } else {
28
+ delete ReactNative.NativeModules.DebugFeaturesBridge;
29
+ }
30
+
31
+ DebugFeaturesModule = require("../DebugFeatures");
32
+ LegacyModule = require("../DebugFeatues");
33
+ });
34
+
35
+ return {
36
+ DebugFeaturesModule,
37
+ LegacyModule,
38
+ ReactNative,
39
+ };
40
+ };
41
+
42
+ describe("DebugFeatures", () => {
43
+ afterEach(() => {
44
+ delete (globalThis as any)[STATE_KEY];
45
+ const ReactNative = require("react-native");
46
+ delete ReactNative.NativeModules.DebugFeaturesBridge;
47
+ jest.restoreAllMocks();
48
+ });
49
+
50
+ describe("when native DebugFeaturesBridge is available", () => {
51
+ it("delegates registration, reading, writing, and receives native change events", async () => {
52
+ const nativeBridge = {
53
+ registerFeatureFlag: jest.fn().mockResolvedValue(true),
54
+ getFeatures: jest.fn().mockResolvedValue([
55
+ {
56
+ id: "plugin.flag",
57
+ group: "Plugin",
58
+ description: "Test flag",
59
+ initialState: true,
60
+ enabled: true,
61
+ value: "true",
62
+ },
63
+ ]),
64
+ isFeatureFlagEnabled: jest.fn().mockResolvedValue(true),
65
+ toggleFeatureFlag: jest.fn().mockResolvedValue(false),
66
+ getStringValue: jest.fn().mockResolvedValue("123"),
67
+ setStringValue: jest.fn().mockResolvedValue("abc"),
68
+ };
69
+
70
+ const { DebugFeaturesModule, ReactNative } = loadModules(nativeBridge);
71
+ const { default: DebugFeatures, subscribe } = DebugFeaturesModule;
72
+ const instance = DebugFeatures.getInstance();
73
+
74
+ await expect(
75
+ instance.registerFeatureFlag({
76
+ id: "plugin.flag",
77
+ group: "Plugin",
78
+ description: "Test flag",
79
+ initialState: true,
80
+ })
81
+ ).resolves.toBe(true);
82
+
83
+ expect(nativeBridge.registerFeatureFlag).toHaveBeenCalledWith({
84
+ id: "plugin.flag",
85
+ group: "Plugin",
86
+ description: "Test flag",
87
+ initialState: true,
88
+ });
89
+
90
+ await expect(instance.getFeatures()).resolves.toEqual([
91
+ {
92
+ id: "plugin.flag",
93
+ group: "Plugin",
94
+ description: "Test flag",
95
+ initialState: true,
96
+ enabled: true,
97
+ value: "true",
98
+ },
99
+ ]);
100
+
101
+ await expect(instance.isFeatureFlagEnabled("plugin.flag")).resolves.toBe(
102
+ true
103
+ );
104
+
105
+ await expect(
106
+ instance.toggleFeatureFlag("plugin.flag", false)
107
+ ).resolves.toBe(false);
108
+
109
+ await expect(instance.getStringValue("plugin.str")).resolves.toBe("123");
110
+
111
+ await expect(instance.setStringValue("plugin.str", "abc")).resolves.toBe(
112
+ "abc"
113
+ );
114
+
115
+ const globalEvents = [];
116
+ const keyEvents = [];
117
+ const unsubGlobal = subscribe((event) => globalEvents.push(event));
118
+
119
+ const unsubKey = subscribe(
120
+ (event) => keyEvents.push(event),
121
+ "plugin.flag"
122
+ );
123
+
124
+ ReactNative.DeviceEventEmitter.emit("DebugFeatures.changed", {
125
+ id: "plugin.flag",
126
+ value: "true",
127
+ enabled: true,
128
+ });
129
+
130
+ ReactNative.DeviceEventEmitter.emit("DebugFeatures.changed", {
131
+ id: "other.flag",
132
+ value: "hello",
133
+ enabled: false,
134
+ });
135
+
136
+ expect(globalEvents).toEqual([
137
+ { id: "plugin.flag", value: "true", enabled: true },
138
+ { id: "other.flag", value: "hello", enabled: false },
139
+ ]);
140
+
141
+ expect(keyEvents).toEqual([
142
+ { id: "plugin.flag", value: "true", enabled: true },
143
+ ]);
144
+
145
+ unsubGlobal();
146
+ unsubKey();
147
+
148
+ ReactNative.DeviceEventEmitter.emit("DebugFeatures.changed", {
149
+ id: "plugin.flag",
150
+ value: "false",
151
+ enabled: false,
152
+ });
153
+
154
+ expect(globalEvents).toHaveLength(2);
155
+ expect(keyEvents).toHaveLength(1);
156
+ });
157
+ });
158
+
159
+ describe("when native DebugFeaturesBridge is missing", () => {
160
+ it("falls back to LocalStorage and in-JS registry and notifies subscribers", async () => {
161
+ const { DebugFeaturesModule, LegacyModule } = loadModules();
162
+
163
+ const {
164
+ default: DebugFeatures,
165
+ registerFeatureFlag,
166
+ getFeatures,
167
+ isFeatureFlagEnabled,
168
+ toggleFeatureFlag,
169
+ getStringValue,
170
+ setStringValue,
171
+ subscribe,
172
+ } = DebugFeaturesModule;
173
+
174
+ const globalListener = jest.fn();
175
+ const keyListener = jest.fn();
176
+ const unsubGlobal = subscribe(globalListener);
177
+ const unsubKey = subscribe(keyListener, "flag.initial_true");
178
+
179
+ await expect(
180
+ registerFeatureFlag({
181
+ id: "flag.initial_true",
182
+ group: "Debug",
183
+ description: "Starts enabled",
184
+ initialState: true,
185
+ })
186
+ ).resolves.toBe(true);
187
+
188
+ await expect(
189
+ registerFeatureFlag({
190
+ id: "flag.default_off",
191
+ group: "Debug",
192
+ description: "Starts disabled",
193
+ })
194
+ ).resolves.toBe(false);
195
+
196
+ expect(globalListener).toHaveBeenCalledWith({
197
+ id: "flag.initial_true",
198
+ value: "true",
199
+ enabled: true,
200
+ });
201
+
202
+ expect(keyListener).toHaveBeenCalledWith({
203
+ id: "flag.initial_true",
204
+ value: "true",
205
+ enabled: true,
206
+ });
207
+
208
+ // Re-registering initialState: true does not overwrite an explicit false
209
+ await expect(toggleFeatureFlag("flag.initial_true", false)).resolves.toBe(
210
+ false
211
+ );
212
+
213
+ await expect(
214
+ registerFeatureFlag({
215
+ id: "flag.initial_true",
216
+ group: "Debug",
217
+ description: "Starts enabled",
218
+ initialState: true,
219
+ })
220
+ ).resolves.toBe(false);
221
+
222
+ await expect(isFeatureFlagEnabled("flag.initial_true")).resolves.toBe(
223
+ false
224
+ );
225
+
226
+ await expect(
227
+ LegacyModule.default
228
+ .getInstance()
229
+ .isFeatureFlagEnabled("flag.initial_true")
230
+ ).resolves.toBe(false);
231
+
232
+ await expect(
233
+ DebugFeatures.getInstance().isFeatureFlagEnabled("flag.default_off")
234
+ ).resolves.toBe(false);
235
+
236
+ await expect(setStringValue("flag.str", "123")).resolves.toBe("123");
237
+ await expect(getStringValue("flag.str")).resolves.toBe("123");
238
+ await expect(setStringValue("flag.str", "")).resolves.toBeNull();
239
+ await expect(getStringValue("flag.str")).resolves.toBeNull();
240
+
241
+ await expect(getFeatures()).resolves.toEqual([
242
+ {
243
+ id: "flag.default_off",
244
+ group: "Debug",
245
+ description: "Starts disabled",
246
+ initialState: false,
247
+ enabled: false,
248
+ value: null,
249
+ },
250
+ {
251
+ id: "flag.initial_true",
252
+ group: "Debug",
253
+ description: "Starts enabled",
254
+ initialState: true,
255
+ enabled: false,
256
+ value: "false",
257
+ },
258
+ ]);
259
+
260
+ expect(globalListener).toHaveBeenLastCalledWith({
261
+ id: "flag.str",
262
+ value: null,
263
+ enabled: false,
264
+ });
265
+
266
+ unsubGlobal();
267
+ unsubKey();
268
+ });
269
+
270
+ it("logs an error via X-Ray logger when native module is present but a method is missing", async () => {
271
+ const logErrorMock = jest.fn();
272
+
273
+ jest.doMock("../../logger", () => ({
274
+ ...jest.requireActual("../../logger"),
275
+ createLogger: () => ({
276
+ log_verbose: jest.fn(),
277
+ log_debug: jest.fn(),
278
+ log_info: jest.fn(),
279
+ log_warning: jest.fn(),
280
+ log_error: logErrorMock,
281
+ }),
282
+ }));
283
+
284
+ const partialBridge = {
285
+ registerFeatureFlag: jest.fn().mockResolvedValue(true),
286
+ };
287
+
288
+ const { DebugFeaturesModule } = loadModules(partialBridge);
289
+
290
+ const { registerFeatureFlag, isFeatureFlagEnabled, getStringValue } =
291
+ DebugFeaturesModule;
292
+
293
+ try {
294
+ await expect(
295
+ registerFeatureFlag({ id: "flag.partial", initialState: true })
296
+ ).resolves.toBe(true);
297
+
298
+ await expect(isFeatureFlagEnabled("flag.partial")).resolves.toBe(false);
299
+ await expect(getStringValue("flag.partial")).resolves.toBeNull();
300
+
301
+ expect(logErrorMock).toHaveBeenCalledWith(
302
+ "DebugFeaturesBridge.isFeatureFlagEnabled is missing on native module"
303
+ );
304
+
305
+ expect(logErrorMock).toHaveBeenCalledWith(
306
+ "DebugFeaturesBridge.getStringValue is missing on native module"
307
+ );
308
+ } finally {
309
+ jest.dontMock("../../logger");
310
+ }
311
+ });
312
+ });
313
+ });
@@ -0,0 +1,3 @@
1
+ export * from "./DebugFeatures";
2
+
3
+ export { default } from "./DebugFeatures";
@@ -1,3 +1,3 @@
1
- import { utilsLogger } from "../logger";
1
+ import { subsystemLogger } from "../logger";
2
2
 
3
- export const domUtilsLogger = utilsLogger.addSubsystem("domUtils");
3
+ export const domUtilsLogger = subsystemLogger("core/dom", "DomUtils");
@@ -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 =
@@ -11,7 +11,7 @@ import {
11
11
  import { EntryAction, EntryActionDeps } from "./types";
12
12
 
13
13
  const { log_info, log_warning, log_error } = createLogger({
14
- subsystem: "EntryActions",
14
+ subsystem: "core/actions",
15
15
  category: "EntryAction",
16
16
  });
17
17
 
@@ -14,6 +14,8 @@ export const getParsedResponse = (err): XRayEventData => {
14
14
 
15
15
  const xRayData: XRayEventData = {
16
16
  data: {
17
+ // What X-Ray diagnostics read is top level in `data`: the error's context carries it.
18
+ diagnostic: context?.diagnostic,
17
19
  context,
18
20
  name,
19
21
  params,
@@ -222,14 +222,47 @@ 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);
231
+ const parentNode = this.tree.findParent(focusableId);
232
+
233
+ const removesFocusedSubtree =
234
+ this._focusedId === focusableId ||
235
+ !!(this._focusedId && node?.findNode(this._focusedId));
227
236
 
228
237
  this.focusableComponents = this.focusableComponents.filter(
229
- (c) => c !== node?.component
238
+ (c) => c !== node?.component && getFocusableId(c) !== focusableId
230
239
  );
231
240
 
232
241
  this.tree.remove(focusableId);
242
+
243
+ if (removesFocusedSubtree) {
244
+ this._focusedId = null;
245
+ this.retainFocus(parentNode);
246
+ }
247
+ }
248
+
249
+ // Recover before parent-first unmounts discard the focused child's ancestry.
250
+ // Land on a mounted ancestor so key handlers keep a target.
251
+ private retainFocus(node: TreeNode | null) {
252
+ let current = node;
253
+
254
+ while (current) {
255
+ const ref = FocusManager.findFocusable(current.id);
256
+
257
+ if (ref?.current?.props?.id) {
258
+ this.setFocusLocal(ref);
259
+ ref.current.onFocus?.(ref.current, {}, undefined);
260
+
261
+ return;
262
+ }
263
+
264
+ current = current.parentId ? this.tree.find(current.parentId) : null;
265
+ }
233
266
  }
234
267
 
235
268
  private setNextFocus(
@@ -418,13 +451,17 @@ class FocusManager {
418
451
  }
419
452
 
420
453
  private hasFocus = (node) => {
421
- if (node.children?.length > 0) {
422
- return node.children.some((item) => this.hasFocus(item));
423
- } else if (this.isFocused(node?.component?.current?.props.id)) {
454
+ const propsId = node?.component?.current?.props?.id;
455
+
456
+ // A focused cell keeps its buttons as children. Count that cell, not only leaves.
457
+ if (
458
+ this.isFocused(propsId) ||
459
+ (node?.id !== propsId && this.isFocused(node?.id))
460
+ ) {
424
461
  return true;
425
462
  }
426
463
 
427
- return false;
464
+ return node.children?.some((child) => this.hasFocus(child)) ?? false;
428
465
  };
429
466
 
430
467
  isAnyDescendantFocused(id: string) {
@@ -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";
@@ -120,11 +123,11 @@ describe("FocusManager", () => {
120
123
  /* check state of focus */
121
124
  expect(focusManager.isAnyDescendantFocused("group")).toBe(false);
122
125
 
123
- /* set focus on 2nd child */
126
+ /* set focus on 2nd child, which itself has children */
124
127
  focusManager.setFocus(child2.current.props.id);
125
128
 
126
- /* check state of focus */
127
- expect(focusManager.isAnyDescendantFocused("group")).toBe(false);
129
+ /* the focused node is the child, not one of its leaves */
130
+ expect(focusManager.isAnyDescendantFocused("group")).toBe(true);
128
131
  });
129
132
 
130
133
  it("focusManager isFocusableChildOf should be defined", () => {
@@ -231,6 +234,15 @@ describe("FocusManager", () => {
231
234
  ).toBeFalsy();
232
235
  });
233
236
 
237
+ it("moves focus to the mounted parent when the focused element unregisters", () => {
238
+ focusManager.setFocus("child1");
239
+
240
+ focusManager.unregisterFocusable("child1");
241
+
242
+ expect(focusManager.focusedId).toBe("group");
243
+ expect(focusManager.focused).toBe(group.current);
244
+ });
245
+
234
246
  it("focusManager registerFocusable should be defined", () => {
235
247
  expect(focusManager.registerFocusable).toBeDefined();
236
248
  });
@@ -257,3 +269,112 @@ describe("FocusManager", () => {
257
269
  expect(focusManager.focusedId).toBe("child2");
258
270
  });
259
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
+ });