@applicaster/zapp-react-native-utils 12.0.0-alpha.3631152042 → 12.0.0-alpha.4433422595

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,6 +224,12 @@ export const focusManager = (function () {
224
224
  lastAddedParentNode?.children || focusableTree.root.children
225
225
  );
226
226
 
227
+ // console.log("debug_2", "FM setInitialFocus", {
228
+ // preferredFocus,
229
+ // lastAddedParentNode,
230
+ // focusableTree,
231
+ // });
232
+
227
233
  logger.log({ message: "setInitialFocus", data: { preferredFocus } });
228
234
 
229
235
  if (preferredFocus && preferredFocus.length > 0) {
@@ -323,6 +329,8 @@ export const focusManager = (function () {
323
329
  * @returns {React.Component} the registered component
324
330
  */
325
331
  function registerGroup(id, component) {
332
+ // console.log("debug_2", "FM registerGroup", { id, component });
333
+
326
334
  focusableTree.addNode({ id, component });
327
335
 
328
336
  return component;
@@ -338,6 +346,8 @@ export const focusManager = (function () {
338
346
  * @returns {React.Component} the registered component
339
347
  */
340
348
  function registerItem(id, component) {
349
+ // console.log("debug_2", "FM registerItem", { id, component });
350
+
341
351
  focusableTree.addNode({ id, component });
342
352
 
343
353
  if (!currentFocusNode && id === lastFocusedId && !id.includes("menu")) {
@@ -354,6 +364,8 @@ export const focusManager = (function () {
354
364
  * @param {String} id of the group to unregister
355
365
  */
356
366
  function unregisterGroup(id) {
367
+ // console.log("debug_2", "FM unregisterGroup", { id });
368
+
357
369
  focusableTree.findAndRemoveNode(id);
358
370
  }
359
371
 
@@ -365,6 +377,8 @@ export const focusManager = (function () {
365
377
  * @param {String} id of the Focusable to unregister
366
378
  */
367
379
  function unregisterItem(id) {
380
+ // console.log("debug_2", "FM unregisterItem", { id });
381
+
368
382
  focusableTree.findAndRemoveNode(id);
369
383
 
370
384
  if (currentFocusNode && currentFocusNode.id === id) {
@@ -422,6 +436,13 @@ export const focusManager = (function () {
422
436
  currentFocusNode.component.willLoseFocus(currentFocusNode, direction);
423
437
  const nextFocusable = findFocusableNode(direction, currentFocusNode);
424
438
 
439
+ // console.log("debug_2", "FM moveFocus", {
440
+ // direction: direction?.value,
441
+ // currentFocusNode,
442
+ // focusableTree,
443
+ // nextFocusable,
444
+ // });
445
+
425
446
  if (nextFocusable?.component?.isMounted?.()) {
426
447
  const nextRect = nextFocusable.component.getRect();
427
448
 
@@ -1,4 +1,4 @@
1
- import * as R from "ramda";
1
+ import { allPass, pathOr, startsWith } from "ramda";
2
2
  import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
3
3
 
4
4
  import { rejectItemByPath } from "../../../../objectUtils";
@@ -143,7 +143,47 @@ const hasChildren = (target) =>
143
143
 
144
144
  const hasComponent = (target) => !!target?.component;
145
145
 
146
- const hasComponentAndChildren = R.allPass([hasComponent, hasChildren]);
146
+ const hasComponentAndChildren = allPass([hasComponent, hasChildren]);
147
+
148
+ const positiveOrZero = (value) => value >= 0;
149
+
150
+ const excludeFromFocusSearching = pathOr(false, [
151
+ "component",
152
+ "props",
153
+ "excludeFromFocusSearching",
154
+ ]);
155
+
156
+ const isNavBar = (target) => startsWith("navbar", target?.id);
157
+
158
+ const ignoreMenuIfMultipleTargets = (nodes) => {
159
+ if (nodes.length > 1 && nodes.map((n) => n?.target?.id).includes("navbar")) {
160
+ return nodes.filter((n) => !isNavBar(n?.target));
161
+ }
162
+
163
+ return nodes;
164
+ };
165
+
166
+ const toDistance = ({ target, direction, comparisonRect }) => {
167
+ const componentRect = target.component?.getRect();
168
+
169
+ const orientationDistance = measureDistance(
170
+ direction,
171
+ comparisonRect,
172
+ componentRect
173
+ );
174
+
175
+ if (orientationDistance === -1) {
176
+ // ignores offscreen targets when moving up/down
177
+ return null;
178
+ }
179
+
180
+ const euclidDistance = measureEuclidianDistanceToCenter(
181
+ comparisonRect,
182
+ componentRect
183
+ );
184
+
185
+ return orientationDistance > 0 ? euclidDistance : orientationDistance;
186
+ };
147
187
 
148
188
  /**
149
189
  * Get target in shortest distance in specified direction
@@ -173,52 +213,28 @@ export function getTargetInDirection(
173
213
 
174
214
  const distances = targets
175
215
  .filter(hasComponentAndChildren)
176
- .map((target) => {
177
- const componentRect = target.component?.getRect();
178
-
179
- const distance = measureDistance(
180
- direction,
181
- comparisonRect,
182
- componentRect
183
- );
184
-
185
- if (distance === -1) {
186
- // ignores offscreen targets when moving up/down
187
- return null;
188
- }
189
-
190
- const orientationDistance = measureDistance(
191
- direction,
192
- comparisonRect,
193
- componentRect
194
- );
195
-
196
- const euclidDistance = measureEuclidianDistanceToCenter(
197
- comparisonRect,
198
- componentRect
199
- );
200
-
201
- return {
202
- distance:
203
- orientationDistance > 0 ? euclidDistance : orientationDistance,
204
- target,
205
- };
206
- })
207
- .filter((obj) => obj && obj.distance >= 0);
216
+ .filter((target) => !excludeFromFocusSearching(target))
217
+ .map((target) => ({
218
+ distance: toDistance({ target, direction, comparisonRect }),
219
+ target,
220
+ }))
221
+ .filter(({ distance }) => positiveOrZero(distance));
208
222
 
209
223
  const match = distances
210
224
  .sort((a, b) => a.distance - b.distance) // sorts the distances
211
225
  .filter(ignoreMenuIfMultipleTargets)[0]; // filters out multiple targets if necessary // gets the first element
212
226
 
213
- return distances && distances.length > 0 ? match.target : null;
214
- }
215
-
216
- function ignoreMenuIfMultipleTargets(nodes) {
217
- if (nodes.length > 1 && nodes.map((n) => n?.target?.id).includes("navbar")) {
218
- return nodes.filter((n) => n?.target?.id !== "navbar");
219
- }
220
-
221
- return nodes;
227
+ // console.log("debug_2", "FM getTargetInDirection", {
228
+ // direction: direction?.value,
229
+ // currentNode,
230
+ // targetNodes,
231
+ // targets,
232
+ // comparisonRect,
233
+ // distances,
234
+ // match,
235
+ // });
236
+
237
+ return match.target;
222
238
  }
223
239
 
224
240
  /**
@@ -460,7 +460,9 @@ export const getColorFromData = ({
460
460
  }: GetColorFromData): string => {
461
461
  const value = getValue(key);
462
462
 
463
- if (validateColor(value)) {
463
+ // Temporary hack to fix color validation when alpha is floating point number
464
+ // https://github.com/dreamyguy/validate-color/issues/44
465
+ if (validateColor(value.replace(".00", ""))) {
464
466
  return value;
465
467
  }
466
468
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.3631152042",
3
+ "version": "12.0.0-alpha.4433422595",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "12.0.0-alpha.3631152042",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.4433422595",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -491,3 +491,18 @@ export const useIsScreenActive = () => {
491
491
 
492
492
  return pathname === currentRoute;
493
493
  };
494
+
495
+ type Return = (prefix: string) => string;
496
+
497
+ export const useUniqueRouteSuffix = (): Return => {
498
+ const pathname = usePathname();
499
+ const { currentRoute } = useNavigation();
500
+
501
+ const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
502
+
503
+ const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
504
+ return `${prefix}___${suffix}`;
505
+ }, []);
506
+
507
+ return withUniqueRouteSuffix;
508
+ };