@applicaster/zapp-react-native-utils 14.0.0-rc.46 → 14.0.0-rc.47

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.
@@ -24,6 +24,7 @@ exports[`focusManager should be defined 1`] = `
24
24
  "invokeHandler": [Function],
25
25
  "isCurrentFocusOnTheTopScreen": [Function],
26
26
  "isFocusDisabled": [Function],
27
+ "isFocusOn": [Function],
27
28
  "isGroupItemFocused": [Function],
28
29
  "longPress": [Function],
29
30
  "moveFocus": [Function],
@@ -63,6 +64,7 @@ exports[`focusManagerIOS should be defined 1`] = `
63
64
  "getGroupRootById": [Function],
64
65
  "getPreferredFocusChild": [Function],
65
66
  "invokeHandler": [Function],
67
+ "isFocusOn": [Function],
66
68
  "isGroupItemFocused": [Function],
67
69
  "moveFocus": [Function],
68
70
  "on": [Function],
@@ -1,6 +1,7 @@
1
1
  import { NativeModules } from "react-native";
2
2
  import * as R from "ramda";
3
3
 
4
+ import { isCurrentFocusOn } from "../focusManagerAux/utils";
4
5
  import { Tree } from "./treeDataStructure/Tree";
5
6
  import { findFocusableNode } from "./treeDataStructure/Utils";
6
7
  import { subscriber } from "../../functionUtils";
@@ -391,6 +392,14 @@ export const focusManager = (function () {
391
392
  return node;
392
393
  }
393
394
 
395
+ function isFocusOn(id): boolean {
396
+ const currentFocusNode = focusableTree.findInTree(
397
+ getCurrentFocus()?.props?.id
398
+ );
399
+
400
+ return id && isCurrentFocusOn(id, currentFocusNode);
401
+ }
402
+
394
403
  return {
395
404
  on,
396
405
  invokeHandler,
@@ -412,5 +421,6 @@ export const focusManager = (function () {
412
421
  getGroupRootById,
413
422
  isGroupItemFocused,
414
423
  getPreferredFocusChild,
424
+ isFocusOn,
415
425
  };
416
426
  })();
@@ -14,6 +14,8 @@ import { subscriber } from "../../functionUtils";
14
14
  import { coreLogger } from "../../logger";
15
15
  import { ACTION } from "./utils/enums";
16
16
 
17
+ import { isCurrentFocusOn } from "../focusManagerAux/utils";
18
+
17
19
  const logger = coreLogger.addSubsystem("focusManager");
18
20
 
19
21
  const isFocusEnabled = (focusableItem): boolean => {
@@ -546,6 +548,14 @@ export const focusManager = (function () {
546
548
  return preferredFocus[0];
547
549
  }
548
550
 
551
+ function isFocusOn(id): boolean {
552
+ return (
553
+ id &&
554
+ isCurrentFocusOnTheTopScreen() &&
555
+ isCurrentFocusOn(id, currentFocusNode)
556
+ );
557
+ }
558
+
549
559
  /**
550
560
  * this is the list of the functions available externally
551
561
  * when importing the focus manager
@@ -576,5 +586,6 @@ export const focusManager = (function () {
576
586
  recoverFocus,
577
587
  isCurrentFocusOnTheTopScreen,
578
588
  findPreferredFocusChild,
589
+ isFocusOn,
579
590
  };
580
591
  })();
@@ -9,6 +9,8 @@ import {
9
9
  // run this check too often could lead to performance penalty on low-end devices
10
10
  const HOW_OFTEN_TO_CHECK_CONDITION = 300; // ms
11
11
 
12
+ const isRoot = (node) => node?.id === "root";
13
+
12
14
  type Props = {
13
15
  maxTimeout: number;
14
16
  conditionFn: () => boolean;
@@ -99,3 +101,19 @@ export const waitForContent = (focusableTree) => {
99
101
  conditionFn: contentHasAnyChildren,
100
102
  });
101
103
  };
104
+
105
+ export const isCurrentFocusOn = (id, node) => {
106
+ if (!node) {
107
+ return false;
108
+ }
109
+
110
+ if (isRoot(node)) {
111
+ return false;
112
+ }
113
+
114
+ if (node?.id === id) {
115
+ return true;
116
+ }
117
+
118
+ return isCurrentFocusOn(id, node.parent);
119
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "14.0.0-rc.46",
3
+ "version": "14.0.0-rc.47",
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": "14.0.0-rc.46",
30
+ "@applicaster/applicaster-types": "14.0.0-rc.47",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",