@applicaster/zapp-react-native-utils 13.0.0-rc.104 → 13.0.0-rc.105
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.
|
@@ -61,6 +61,7 @@ exports[`focusManagerIOS should be defined 1`] = `
|
|
|
61
61
|
"getCurrentGroup": [Function],
|
|
62
62
|
"getGroupById": [Function],
|
|
63
63
|
"getGroupRootById": [Function],
|
|
64
|
+
"getPreferredFocusChild": [Function],
|
|
64
65
|
"invokeHandler": [Function],
|
|
65
66
|
"isGroupItemFocused": [Function],
|
|
66
67
|
"moveFocus": [Function],
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { NativeModules } from "react-native";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
+
|
|
3
4
|
import { Tree } from "./treeDataStructure/Tree";
|
|
4
5
|
import { findFocusableNode } from "./treeDataStructure/Utils";
|
|
5
6
|
import { subscriber } from "../../functionUtils";
|
|
7
|
+
import { findChild } from "./utils";
|
|
6
8
|
|
|
7
9
|
const { FocusableManagerModule } = NativeModules;
|
|
8
10
|
|
|
@@ -52,10 +54,7 @@ export const focusManager = (function () {
|
|
|
52
54
|
const node = focusableTree.findInTree(groupId);
|
|
53
55
|
|
|
54
56
|
if (node?.children?.length > 0) {
|
|
55
|
-
const preferredFocus =
|
|
56
|
-
R.find(R.pathEq(["component", "props", "preferredFocus"], true)),
|
|
57
|
-
R.prop("children")
|
|
58
|
-
)(node);
|
|
57
|
+
const preferredFocus = findChild(true, node);
|
|
59
58
|
|
|
60
59
|
if (preferredFocus?.component?.isGroup) {
|
|
61
60
|
return getPreferredFocusInGroup({ groupId: preferredFocus?.id });
|
|
@@ -382,6 +381,16 @@ export const focusManager = (function () {
|
|
|
382
381
|
forceFocusOnItem({ focusableItem, callback });
|
|
383
382
|
}
|
|
384
383
|
|
|
384
|
+
function getPreferredFocusChild(id) {
|
|
385
|
+
const node = focusableTree.findInTree(id);
|
|
386
|
+
|
|
387
|
+
if (node?.children?.length > 0) {
|
|
388
|
+
return findChild(true, node) || findChild(false, node);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return node;
|
|
392
|
+
}
|
|
393
|
+
|
|
385
394
|
return {
|
|
386
395
|
on,
|
|
387
396
|
invokeHandler,
|
|
@@ -402,5 +411,6 @@ export const focusManager = (function () {
|
|
|
402
411
|
getCurrentGroup,
|
|
403
412
|
getGroupRootById,
|
|
404
413
|
isGroupItemFocused,
|
|
414
|
+
getPreferredFocusChild,
|
|
405
415
|
};
|
|
406
416
|
})();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { findChild } from "../index";
|
|
2
|
+
|
|
3
|
+
describe("findChild", () => {
|
|
4
|
+
const makeNode = (children = []) => ({ children });
|
|
5
|
+
|
|
6
|
+
const child = (preferredFocus: boolean) => ({
|
|
7
|
+
component: { props: { preferredFocus } },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("returns the child with preferredFocus=true", () => {
|
|
11
|
+
const node = makeNode([child(false), child(true), child(false)]);
|
|
12
|
+
expect(findChild(true, node)).toBe(node.children[1]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("returns the child with preferredFocus=false", () => {
|
|
16
|
+
const node = makeNode([child(false), child(true), child(false)]);
|
|
17
|
+
expect(findChild(false, node)).toBe(node.children[0]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("returns undefined if no child matches preferredFocus", () => {
|
|
21
|
+
const node = makeNode([child(false), child(false)]);
|
|
22
|
+
expect(findChild(true, node)).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("returns undefined if node has no children", () => {
|
|
26
|
+
const node = makeNode();
|
|
27
|
+
expect(findChild(true, node)).toBeUndefined();
|
|
28
|
+
expect(findChild(false, node)).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("returns undefined if children is not an array", () => {
|
|
32
|
+
const node = { children: null };
|
|
33
|
+
expect(findChild(true, node)).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -98,3 +98,8 @@ export const waitForContent = (focusableTree) => {
|
|
|
98
98
|
conditionFn: contentHasAnyChildren,
|
|
99
99
|
});
|
|
100
100
|
};
|
|
101
|
+
|
|
102
|
+
export const findChild = (preferredFocus: boolean, node) =>
|
|
103
|
+
(node?.children || []).find(
|
|
104
|
+
(child) => child?.component?.props?.preferredFocus === preferredFocus
|
|
105
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-rc.
|
|
3
|
+
"version": "13.0.0-rc.105",
|
|
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": "13.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "13.0.0-rc.105",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|