@applicaster/zapp-react-native-utils 15.0.0-alpha.4435057569 → 15.0.0-alpha.4789154469

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.
Files changed (48) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +83 -6
  3. package/appUtils/HooksManager/index.ts +35 -0
  4. package/appUtils/focusManagerAux/utils/index.ts +2 -4
  5. package/appUtils/focusManagerAux/utils/utils.ios.ts +6 -3
  6. package/appUtils/localizationsHelper.ts +4 -0
  7. package/appUtils/playerManager/index.ts +9 -0
  8. package/appUtils/playerManager/player.ts +1 -1
  9. package/appUtils/playerManager/usePlayer.tsx +5 -3
  10. package/cellUtils/__tests__/cellUtils.test.ts +39 -0
  11. package/cellUtils/index.ts +11 -1
  12. package/dateUtils/__tests__/dayjs.test.ts +0 -3
  13. package/dateUtils/index.ts +2 -0
  14. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  15. package/manifestUtils/_internals/index.js +33 -0
  16. package/manifestUtils/defaultManifestConfigurations/player.js +6 -0
  17. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  18. package/manifestUtils/fieldUtils/index.js +54 -0
  19. package/manifestUtils/index.js +2 -0
  20. package/manifestUtils/keys.js +228 -0
  21. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  22. package/manifestUtils/mobileAction/button/index.js +140 -0
  23. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  24. package/manifestUtils/mobileAction/container/index.js +73 -0
  25. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  26. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  27. package/manifestUtils/mobileAction/groups/index.js +80 -0
  28. package/numberUtils/__tests__/toNumber.test.ts +27 -12
  29. package/numberUtils/__tests__/toPositiveNumber.test.ts +32 -4
  30. package/numberUtils/index.ts +5 -1
  31. package/package.json +3 -3
  32. package/pluginUtils/index.ts +4 -5
  33. package/reactHooks/cell-click/index.ts +2 -1
  34. package/reactHooks/feed/index.ts +0 -2
  35. package/reactHooks/feed/useInflatedUrl.ts +1 -1
  36. package/reactHooks/resolvers/useComponentResolver.ts +13 -3
  37. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  38. package/reactHooks/state/index.ts +2 -0
  39. package/reactHooks/state/useComponentScreenState.ts +45 -0
  40. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +161 -0
  41. package/refreshUtils/RefreshCoordinator/index.ts +216 -0
  42. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  43. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  44. package/screenPickerUtils/index.ts +5 -0
  45. package/screenUtils/index.ts +3 -0
  46. package/utils/__tests__/path.test.ts +7 -0
  47. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  48. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -0,0 +1,104 @@
1
+ import {
2
+ getDataRefreshConfig,
3
+ MINIMUM_REFRESHING_INTERVAL_IN_SECONDS,
4
+ DEFAULT_REFRESHING_INTERVAL_IN_SECONDS,
5
+ } from "..";
6
+
7
+ describe("getDataRefreshConfig", () => {
8
+ it("returns correct values when rules are defined", () => {
9
+ const component = {
10
+ rules: {
11
+ enable_data_refreshing: true,
12
+ refreshing_interval: 30,
13
+ },
14
+ } as any;
15
+
16
+ const result = getDataRefreshConfig(component);
17
+
18
+ expect(result).toEqual({
19
+ isRefreshingEnabled: true,
20
+ refreshIntervalMs: 30 * 1000,
21
+ });
22
+ });
23
+
24
+ it("returns false for isRefreshingEnabled if rules flag is false", () => {
25
+ const component = {
26
+ rules: {
27
+ enable_data_refreshing: false,
28
+ refreshing_interval: 45,
29
+ },
30
+ } as any;
31
+
32
+ const result = getDataRefreshConfig(component);
33
+
34
+ expect(result).toEqual({
35
+ isRefreshingEnabled: false,
36
+ refreshIntervalMs: 45 * 1000,
37
+ });
38
+ });
39
+
40
+ it("applies minimum interval if given interval is too low", () => {
41
+ const component = {
42
+ rules: {
43
+ enable_data_refreshing: true,
44
+ refreshing_interval: 2,
45
+ },
46
+ } as any;
47
+
48
+ const result = getDataRefreshConfig(component);
49
+
50
+ expect(result.refreshIntervalMs).toBe(
51
+ MINIMUM_REFRESHING_INTERVAL_IN_SECONDS * 1000
52
+ );
53
+ });
54
+
55
+ it("uses default interval when rules.refreshing_interval is undefined", () => {
56
+ const component = {
57
+ rules: {
58
+ enable_data_refreshing: true,
59
+ },
60
+ } as any;
61
+
62
+ const result = getDataRefreshConfig(component);
63
+
64
+ expect(result.refreshIntervalMs).toBe(
65
+ DEFAULT_REFRESHING_INTERVAL_IN_SECONDS * 1000
66
+ );
67
+ });
68
+
69
+ it("handles missing rules gracefully", () => {
70
+ const component = {} as any;
71
+
72
+ const result = getDataRefreshConfig(component);
73
+
74
+ expect(result).toEqual({
75
+ isRefreshingEnabled: false,
76
+ refreshIntervalMs: DEFAULT_REFRESHING_INTERVAL_IN_SECONDS * 1000,
77
+ });
78
+ });
79
+
80
+ it("handles null component gracefully", () => {
81
+ const result = getDataRefreshConfig(null as any);
82
+
83
+ expect(result).toEqual({
84
+ isRefreshingEnabled: false,
85
+ refreshIntervalMs: DEFAULT_REFRESHING_INTERVAL_IN_SECONDS * 1000,
86
+ });
87
+ });
88
+
89
+ it("handles string values for rules correctly", () => {
90
+ const component = {
91
+ rules: {
92
+ enable_data_refreshing: "true",
93
+ refreshing_interval: "25",
94
+ },
95
+ } as any;
96
+
97
+ const result = getDataRefreshConfig(component);
98
+
99
+ expect(result).toEqual({
100
+ isRefreshingEnabled: true,
101
+ refreshIntervalMs: 25 * 1000,
102
+ });
103
+ });
104
+ });
@@ -0,0 +1,29 @@
1
+ import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
2
+ import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
3
+
4
+ export const MINIMUM_REFRESHING_INTERVAL_IN_SECONDS = 5; // 5 seconds
5
+
6
+ export const DEFAULT_REFRESHING_INTERVAL_IN_SECONDS = 60; // 1 minute
7
+
8
+ export type RefreshConfig = {
9
+ isRefreshingEnabled: boolean;
10
+ refreshIntervalMs: number;
11
+ };
12
+
13
+ export const getDataRefreshConfig = (
14
+ component: ZappUIComponent
15
+ ): RefreshConfig => {
16
+ const isRefreshingEnabled = isTrue(component?.rules?.enable_data_refreshing);
17
+
18
+ const refreshing_interval = toNumberWithDefault(
19
+ DEFAULT_REFRESHING_INTERVAL_IN_SECONDS,
20
+ component?.rules?.refreshing_interval
21
+ );
22
+
23
+ return {
24
+ isRefreshingEnabled,
25
+ refreshIntervalMs:
26
+ Math.max(refreshing_interval, MINIMUM_REFRESHING_INTERVAL_IN_SECONDS) *
27
+ 1000,
28
+ };
29
+ };
@@ -1,3 +1,5 @@
1
+ import { endsWith } from "@applicaster/zapp-react-native-utils/utils";
2
+
1
3
  export const getFocusableId = (id) => `PickerItem.${id}`;
2
4
 
3
5
  export const getPickerSelectorId = (id) => `PickerSelector.${id}`;
@@ -11,3 +13,6 @@ export const getScreenPickerSelectorContainerId = (id) =>
11
13
 
12
14
  export const getScreenPickerContentContainerId = (id) =>
13
15
  `${getScreenPickerId(id)}-screen-container`;
16
+
17
+ export const isTabsScreenContentContainerId = (id) =>
18
+ endsWith("-screen-container", id);
@@ -0,0 +1,3 @@
1
+ export const TV_SCREEN_HEIGHT = 1080;
2
+
3
+ export const TV_SCREEN_WIDTH = 1920;
@@ -31,3 +31,10 @@ test("example 4", () => {
31
31
 
32
32
  expect(path(route, xs)).toBeUndefined();
33
33
  });
34
+
35
+ test("example 5", () => {
36
+ const route = ["a", "b", 0];
37
+ const xs = { a: { b: [1, 2, 3] } };
38
+
39
+ expect(path(route, xs)).toBe(1);
40
+ });
@@ -1,75 +0,0 @@
1
- import { renderHook } from "@testing-library/react-native";
2
-
3
- jest.useFakeTimers();
4
-
5
- jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
6
- useIsScreenActive: () => true,
7
- }));
8
-
9
- const { useFeedRefresh, feedRefreshLogger } = require("..");
10
-
11
- describe("useFeedRefresh", () => {
12
- const reloadData = jest.fn();
13
-
14
- const component = {
15
- id: "foo",
16
- rules: { enable_data_refreshing: true, refreshing_interval: 61 },
17
- };
18
-
19
- it("Calls reloadData after passed time lapses", () => {
20
- renderHook(() => useFeedRefresh({ reloadData, component }));
21
-
22
- expect(reloadData).not.toBeCalled();
23
- jest.runOnlyPendingTimers();
24
- expect(reloadData).toBeCalled();
25
- });
26
-
27
- it("Logs warning message if refresh time set below minimum value", () => {
28
- const loggerSpy = jest.spyOn(feedRefreshLogger, "warning");
29
-
30
- renderHook(() =>
31
- useFeedRefresh({
32
- reloadData,
33
- component: {
34
- ...component,
35
- rules: { enable_data_refreshing: true, refreshing_interval: 2 },
36
- },
37
- })
38
- );
39
-
40
- expect(loggerSpy).toBeCalled();
41
- });
42
-
43
- it("Calls reloadData on a Component that had a timer setup and was re-mounted", () => {
44
- reloadData.mockReset();
45
-
46
- // it is not called before rendering hook"
47
- expect(reloadData).not.toBeCalled();
48
-
49
- // it is not called when rendering new component (Not previously rendered)
50
- renderHook(() =>
51
- useFeedRefresh({ reloadData, component: { ...component, id: "bar" } })
52
- );
53
-
54
- expect(reloadData).not.toBeCalled();
55
-
56
- // it is called when rendering previously rendered component",
57
- renderHook(() => useFeedRefresh({ reloadData, component }));
58
- expect(reloadData).toBeCalled();
59
- });
60
-
61
- it("Doesn't refresh data when enable_data_refreshing if false", () => {
62
- reloadData.mockReset();
63
-
64
- renderHook(() =>
65
- useFeedRefresh({
66
- reloadData,
67
- component: { ...component, rules: { enable_data_refreshing: false } },
68
- })
69
- );
70
-
71
- jest.runOnlyPendingTimers();
72
-
73
- expect(reloadData).not.toBeCalled();
74
- });
75
- });
@@ -1,65 +0,0 @@
1
- import * as React from "react";
2
- import { path, max } from "ramda";
3
- import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
4
- import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
5
- import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
6
-
7
- import { reactHooksLogger } from "../logger";
8
- import { ReloadDataFunction } from "./useFeedLoader";
9
-
10
- export const feedRefreshLogger = reactHooksLogger.addSubsystem("feed-refresh");
11
-
12
- type Props = {
13
- reloadData?: ReloadDataFunction;
14
- component: ZappUIComponent;
15
- };
16
-
17
- const previousTimersMap = {};
18
- const minimumRefreshingInterval = 5;
19
- const defaultRefreshInterval = 60;
20
-
21
- export const useFeedRefresh = ({ reloadData, component }: Props): void => {
22
- const isDataRefreshingEnabled = isTrue(
23
- path(["rules", "enable_data_refreshing"], component)
24
- );
25
-
26
- const refreshing_interval = toNumberWithDefault(
27
- defaultRefreshInterval,
28
- component?.rules?.refreshing_interval
29
- );
30
-
31
- const refreshingIntervalInMilliseconds =
32
- max(refreshing_interval, minimumRefreshingInterval) * 1000;
33
-
34
- const isScreenActive = useIsScreenActive();
35
-
36
- React.useEffect(() => {
37
- if (isDataRefreshingEnabled && refreshing_interval && isScreenActive) {
38
- if (refreshing_interval < minimumRefreshingInterval) {
39
- feedRefreshLogger.warning({
40
- message: `You set your feed refresh interval to ${refreshing_interval} when minimum value is ${minimumRefreshingInterval}seconds.Your feed will refresh after ${minimumRefreshingInterval}seconds.`,
41
- });
42
- }
43
-
44
- if (!reloadData || typeof reloadData !== "function") {
45
- feedRefreshLogger.warning({
46
- message:
47
- "reloadData function is undefined, feed refresh feature won't work properly",
48
- });
49
- }
50
-
51
- if (previousTimersMap[component?.id]) {
52
- reloadData?.();
53
- }
54
-
55
- const refreshInterval = setInterval(() => {
56
- reloadData?.();
57
- }, refreshingIntervalInMilliseconds);
58
-
59
- return () => {
60
- previousTimersMap[component?.id] = true;
61
- clearInterval(refreshInterval);
62
- };
63
- }
64
- }, [reloadData, isScreenActive]);
65
- };