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

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,6 @@ 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
-
233
227
  logger.log({ message: "setInitialFocus", data: { preferredFocus } });
234
228
 
235
229
  if (preferredFocus && preferredFocus.length > 0) {
@@ -329,8 +323,6 @@ export const focusManager = (function () {
329
323
  * @returns {React.Component} the registered component
330
324
  */
331
325
  function registerGroup(id, component) {
332
- // console.log("debug_2", "FM registerGroup", { id, component });
333
-
334
326
  focusableTree.addNode({ id, component });
335
327
 
336
328
  return component;
@@ -346,8 +338,6 @@ export const focusManager = (function () {
346
338
  * @returns {React.Component} the registered component
347
339
  */
348
340
  function registerItem(id, component) {
349
- // console.log("debug_2", "FM registerItem", { id, component });
350
-
351
341
  focusableTree.addNode({ id, component });
352
342
 
353
343
  if (!currentFocusNode && id === lastFocusedId && !id.includes("menu")) {
@@ -364,8 +354,6 @@ export const focusManager = (function () {
364
354
  * @param {String} id of the group to unregister
365
355
  */
366
356
  function unregisterGroup(id) {
367
- // console.log("debug_2", "FM unregisterGroup", { id });
368
-
369
357
  focusableTree.findAndRemoveNode(id);
370
358
  }
371
359
 
@@ -377,8 +365,6 @@ export const focusManager = (function () {
377
365
  * @param {String} id of the Focusable to unregister
378
366
  */
379
367
  function unregisterItem(id) {
380
- // console.log("debug_2", "FM unregisterItem", { id });
381
-
382
368
  focusableTree.findAndRemoveNode(id);
383
369
 
384
370
  if (currentFocusNode && currentFocusNode.id === id) {
@@ -436,13 +422,6 @@ export const focusManager = (function () {
436
422
  currentFocusNode.component.willLoseFocus(currentFocusNode, direction);
437
423
  const nextFocusable = findFocusableNode(direction, currentFocusNode);
438
424
 
439
- // console.log("debug_2", "FM moveFocus", {
440
- // direction: direction?.value,
441
- // currentFocusNode,
442
- // focusableTree,
443
- // nextFocusable,
444
- // });
445
-
446
425
  if (nextFocusable?.component?.isMounted?.()) {
447
426
  const nextRect = nextFocusable.component.getRect();
448
427
 
@@ -1,4 +1,4 @@
1
- import { allPass, pathOr, startsWith } from "ramda";
1
+ import * as R from "ramda";
2
2
  import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
3
3
 
4
4
  import { rejectItemByPath } from "../../../../objectUtils";
@@ -143,47 +143,7 @@ const hasChildren = (target) =>
143
143
 
144
144
  const hasComponent = (target) => !!target?.component;
145
145
 
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
- };
146
+ const hasComponentAndChildren = R.allPass([hasComponent, hasChildren]);
187
147
 
188
148
  /**
189
149
  * Get target in shortest distance in specified direction
@@ -213,28 +173,52 @@ export function getTargetInDirection(
213
173
 
214
174
  const distances = targets
215
175
  .filter(hasComponentAndChildren)
216
- .filter((target) => !excludeFromFocusSearching(target))
217
- .map((target) => ({
218
- distance: toDistance({ target, direction, comparisonRect }),
219
- target,
220
- }))
221
- .filter(({ distance }) => positiveOrZero(distance));
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);
222
208
 
223
209
  const match = distances
224
210
  .sort((a, b) => a.distance - b.distance) // sorts the distances
225
211
  .filter(ignoreMenuIfMultipleTargets)[0]; // filters out multiple targets if necessary // gets the first element
226
212
 
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;
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;
238
222
  }
239
223
 
240
224
  /**
@@ -1663,7 +1663,8 @@ function getPlayerConfiguration({ platform }) {
1663
1663
  platform.includes("lg") ||
1664
1664
  platform.includes("samsung") ||
1665
1665
  platform.includes("android_tv") ||
1666
- platform.includes("amazon")
1666
+ platform.includes("amazon") ||
1667
+ platform.includes("vizio")
1667
1668
  ) {
1668
1669
  styles.fields.push(
1669
1670
  // Captions Menu
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.4433422595",
3
+ "version": "12.0.0-alpha.4757075613",
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.4433422595",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.4757075613",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -22,6 +22,7 @@ function getDevice(platform) {
22
22
  case "android_tv_for_quickbrick":
23
23
  case "lg_tv":
24
24
  case "samsung_tv":
25
+ case "vizio":
25
26
  case "web":
26
27
  return "tv";
27
28
  }
@@ -1659,7 +1660,8 @@ function getPlayerConfiguration({ platform }) {
1659
1660
  platform.includes("lg") ||
1660
1661
  platform.includes("samsung") ||
1661
1662
  platform.includes("android_tv") ||
1662
- platform.includes("amazon")
1663
+ platform.includes("amazon") ||
1664
+ platform.includes("vizio")
1663
1665
  ) {
1664
1666
  styles.fields.push(
1665
1667
  // Captions Menu for TV
@@ -251,6 +251,11 @@ export const useRoute = (): {
251
251
  return composeRouteData(screenData);
252
252
  }
253
253
 
254
+ // case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
255
+ if (!currentStack) {
256
+ return composeRouteData(navigator.screenData);
257
+ }
258
+
254
259
  return composeRouteData(currentRouteScreenData);
255
260
  };
256
261
 
@@ -491,18 +496,3 @@ export const useIsScreenActive = () => {
491
496
 
492
497
  return pathname === currentRoute;
493
498
  };
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
- };