@applicaster/zapp-react-native-utils 13.0.0-rc.55 → 13.0.0-rc.56

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.
@@ -84,7 +84,7 @@ export function HooksManager({
84
84
  plugins,
85
85
  startUpHooksData = {},
86
86
  }: HookManagerArgs): HookManager {
87
- hooksManagerLogger.addContext({ targetScreen });
87
+ hooksManagerLogger.addContext({ targetScreenId: targetScreen.id });
88
88
 
89
89
  function logHookEvent(func, message, data) {
90
90
  func({
@@ -3,7 +3,7 @@ import { logger } from "@applicaster/zapp-react-native-utils/logger";
3
3
 
4
4
  const numberUtilsLogger = logger?.addSubsystem("NumberUtils");
5
5
 
6
- export const toNumber = (value: any): number | undefined => {
6
+ export const toNumber = (value: unknown): number | undefined => {
7
7
  if (R.isNil(value) || R.isEmpty(value)) {
8
8
  return undefined;
9
9
  }
@@ -17,10 +17,12 @@ export const toNumber = (value: any): number | undefined => {
17
17
  return undefined;
18
18
  };
19
19
 
20
- export const toNumberWithDefault = (defaultValue: number, value: any): number =>
21
- toNumber(value) ?? defaultValue;
20
+ export const toNumberWithDefault = (
21
+ defaultValue: number,
22
+ value: unknown
23
+ ): number => toNumber(value) ?? defaultValue;
22
24
 
23
- export const toNumberWithDefaultZero = (value: any): number =>
25
+ export const toNumberWithDefaultZero = (value: unknown): number =>
24
26
  toNumberWithDefault(0, value);
25
27
 
26
28
  export const requireNumber = (obj, key: string) => {
@@ -39,7 +41,7 @@ export const requireNumber = (obj, key: string) => {
39
41
 
40
42
  export const toFiniteNumberWithDefault = (
41
43
  defaultValue: number,
42
- value: any
44
+ value: unknown
43
45
  ): number => {
44
46
  const possibleNumber = toNumberWithDefault(defaultValue, value);
45
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-rc.55",
3
+ "version": "13.0.0-rc.56",
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": "13.0.0-rc.55",
31
+ "@applicaster/applicaster-types": "13.0.0-rc.56",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "dayjs": "^1.11.10",
@@ -35,25 +35,23 @@ const Wrapper = ({ children }: { children: React.ReactChild }) => (
35
35
  const { useTrackedView } = require("../useTrackedView");
36
36
 
37
37
  describe("useTrackCurrentAutoScrollingElement", () => {
38
- it("should update position for selected component", async () => {
38
+ it("should update position for selected component - onViewportEnter", () => {
39
39
  const { result } = renderHook(() => useTrackedView("123"), {
40
40
  wrapper: Wrapper,
41
41
  });
42
42
 
43
- // Fast-forward until all timers have been executed
44
- jest.advanceTimersByTime(3000);
45
-
46
43
  expect(result.current.inViewPort).toBe(false);
47
44
 
48
45
  const mockRect = {
49
46
  rect: { left: 1, right: 1, top: 1, bottom: 1 },
50
47
  };
51
48
 
52
- act(() => {
53
- result.current.onPositionUpdated(mockRect);
49
+ act(async () => {
50
+ await result.current.onPositionUpdated(mockRect);
54
51
  });
55
52
 
56
- jest.advanceTimersByTime(3000);
53
+ // Fast-forward until all timers have been executed
54
+ jest.runAllTimers();
57
55
 
58
56
  expect(result.current.inViewPort).toBe(true);
59
57
 
@@ -2,6 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { useScreenTrackedViewPositionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext";
3
3
  import { useDimensions } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
4
4
  import { findTrackedView } from "./utils/findTrackedView";
5
+ import { isNil } from "ramda";
6
+ import { withTimeout } from "@applicaster/zapp-react-native-utils/idleUtils";
7
+
8
+ const TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT = 500; // ms
5
9
 
6
10
  const getNormalizedRect = (rect, componentId, screenWidth, screenHeight) => {
7
11
  if (!rect) {
@@ -37,9 +41,16 @@ export const useTrackedView = (componentId: string) => {
37
41
  );
38
42
 
39
43
  const onPositionUpdated = useCallback(
40
- ({ rect }) => {
44
+ async ({ rect }) => {
41
45
  const currentPosition = normalizedRect(componentId, rect);
42
46
 
47
+ // There is an issue on the native side where they are unable to guarantee
48
+ // that the order of onViewportLeave and onViewportEnter events is always correct.
49
+ // This workaround/hack delays the onViewportEnter event to ensure it is received last.
50
+ if (!isNil(currentPosition)) {
51
+ await withTimeout(TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT);
52
+ }
53
+
43
54
  updateComponentsPositions(componentId, currentPosition as any);
44
55
 
45
56
  setInViewPort(!!currentPosition);