@applicaster/zapp-react-native-utils 16.0.0-rc.111 → 16.0.0-rc.112

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.
@@ -224,12 +224,38 @@ class FocusManager {
224
224
 
225
225
  unregisterFocusable(focusableId: string) {
226
226
  const node = this.tree.find(focusableId);
227
+ const parentNode = this.tree.findParent(focusableId);
227
228
 
228
229
  this.focusableComponents = this.focusableComponents.filter(
229
230
  (c) => c !== node?.component
230
231
  );
231
232
 
232
233
  this.tree.remove(focusableId);
234
+
235
+ if (this._focusedId === focusableId) {
236
+ this._focusedId = null;
237
+ this.retainFocus(parentNode);
238
+ }
239
+ }
240
+
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.
244
+ private retainFocus(node: TreeNode | null) {
245
+ let current = node;
246
+
247
+ while (current) {
248
+ const ref = current.component;
249
+
250
+ if (ref?.current?.props?.id) {
251
+ this.setFocusLocal(ref);
252
+ ref.current.onFocus?.(ref.current, {}, undefined);
253
+
254
+ return;
255
+ }
256
+
257
+ current = current.parentId ? this.tree.find(current.parentId) : null;
258
+ }
233
259
  }
234
260
 
235
261
  private setNextFocus(
@@ -231,6 +231,15 @@ describe("FocusManager", () => {
231
231
  ).toBeFalsy();
232
232
  });
233
233
 
234
+ it("moves focus to the mounted parent when the focused element unregisters", () => {
235
+ focusManager.setFocus("child1");
236
+
237
+ focusManager.unregisterFocusable("child1");
238
+
239
+ expect(focusManager.focusedId).toBe("group");
240
+ expect(focusManager.focused).toBe(group.current);
241
+ });
242
+
234
243
  it("focusManager registerFocusable should be defined", () => {
235
244
  expect(focusManager.registerFocusable).toBeDefined();
236
245
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-rc.111",
3
+ "version": "16.0.0-rc.112",
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.111",
30
+ "@applicaster/applicaster-types": "16.0.0-rc.112",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",