@applicaster/zapp-react-native-ui-components 15.1.0-rc.9 → 16.0.0-alpha.1740103407

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 (156) hide show
  1. package/Components/BackgroundImage/BackgroundImage.tsx +42 -0
  2. package/Components/BackgroundImage/BackgroundImage.tv.android.tsx +28 -0
  3. package/Components/BackgroundImage/BackgroundImage.tv.ios.tsx +24 -0
  4. package/Components/BackgroundImage/index.ts +1 -0
  5. package/Components/BaseFocusable/index.ios.ts +12 -2
  6. package/Components/Cell/FocusableWrapper.tsx +3 -0
  7. package/Components/Cell/TvOSCellComponent.tsx +6 -3
  8. package/Components/Focusable/Focusable.tsx +4 -2
  9. package/Components/Focusable/FocusableTvOS.tsx +18 -1
  10. package/Components/Focusable/__tests__/__snapshots__/FocusableTvOS.test.tsx.snap +1 -0
  11. package/Components/FocusableGroup/FocusableTvOS.tsx +41 -8
  12. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +1 -1
  13. package/Components/HandlePlayable/HandlePlayable.tsx +13 -8
  14. package/Components/Layout/FullWidthRow.tsx +38 -0
  15. package/Components/Layout/TV/NavBarContainer.tsx +1 -10
  16. package/Components/Layout/TV/ScreenContainer.tsx +2 -6
  17. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
  18. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
  19. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
  20. package/Components/Layout/TV/index.tsx +5 -7
  21. package/Components/Layout/TV/index.web.tsx +5 -7
  22. package/Components/LinkHandler/LinkHandler.tsx +2 -2
  23. package/Components/MasterCell/CONFIG_BUILDER_TO_REACT_COMPONENT.md +144 -0
  24. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
  25. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
  26. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
  27. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
  28. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
  29. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +165 -0
  30. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +405 -0
  31. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/index.ts +1 -0
  32. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
  33. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
  34. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
  35. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
  36. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
  37. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -10
  38. package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
  39. package/Components/MasterCell/DefaultComponents/ButtonContainerView/components/HorizontalSeparator.tsx +8 -0
  40. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +15 -0
  41. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tv.android.tsx +58 -0
  42. package/Components/MasterCell/DefaultComponents/{tv/ButtonContainerView/index.tsx → ButtonContainerView/index.tv.tsx} +3 -11
  43. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.web.ts +1 -0
  44. package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +40 -0
  45. package/Components/MasterCell/DefaultComponents/DataProvider/index.tsx +163 -0
  46. package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +2 -23
  47. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -22
  48. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +8 -2
  49. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +11 -3
  50. package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +9 -1
  51. package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +15 -14
  52. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +1 -2
  53. package/Components/MasterCell/DefaultComponents/PressableView.tsx +34 -0
  54. package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
  55. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +11 -0
  56. package/Components/MasterCell/DefaultComponents/__tests__/DataProvider.test.tsx +141 -0
  57. package/Components/MasterCell/DefaultComponents/index.ts +9 -3
  58. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +135 -0
  59. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +33 -0
  60. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +22 -0
  61. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +125 -0
  62. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
  63. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
  64. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +37 -0
  65. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +393 -0
  66. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +141 -0
  67. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +343 -0
  68. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
  69. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +122 -0
  70. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
  71. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +238 -0
  72. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Asset.ts +4 -18
  73. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Button.ts +24 -73
  74. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TextLabelsContainer.ts +37 -18
  75. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TvActionButton.tsx +27 -0
  76. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +89 -0
  77. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/renderedTree.test.tsx +231 -0
  78. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +47 -48
  79. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
  80. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +101 -144
  81. package/Components/MasterCell/MappingFunctions/index.js +3 -2
  82. package/Components/MasterCell/README.md +4 -0
  83. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +24 -0
  84. package/Components/MasterCell/__tests__/configInflater.test.js +1 -0
  85. package/Components/MasterCell/__tests__/elementMapper.test.js +46 -0
  86. package/Components/MasterCell/dataAdapter.ts +4 -1
  87. package/Components/MasterCell/elementMapper.tsx +52 -7
  88. package/Components/MasterCell/utils/__tests__/cloneChildrenWithIds.test.tsx +43 -0
  89. package/Components/MasterCell/utils/__tests__/useFilterChildren.test.tsx +80 -0
  90. package/Components/MasterCell/utils/index.ts +85 -15
  91. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +2 -2
  92. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +17 -18
  93. package/Components/OfflineHandler/__tests__/index.test.tsx +27 -18
  94. package/Components/PlayerContainer/PlayerContainer.tsx +8 -5
  95. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
  96. package/Components/River/ComponentsMap/ComponentsMap.tsx +188 -118
  97. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
  98. package/Components/River/RefreshControl.tsx +19 -88
  99. package/Components/River/River.tsx +9 -82
  100. package/Components/River/TV/River.tsx +31 -14
  101. package/Components/River/TV/index.tsx +8 -4
  102. package/Components/River/TV/utils/__tests__/toStringOrEmpty.test.ts +30 -0
  103. package/Components/River/TV/utils/index.ts +4 -0
  104. package/Components/River/TV/withFocusableGroupForContent.tsx +71 -0
  105. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -22
  106. package/Components/River/__tests__/componentsMap.test.js +38 -0
  107. package/Components/River/hooks/__tests__/usePullToRefresh.test.ts +132 -0
  108. package/Components/River/hooks/index.ts +1 -0
  109. package/Components/River/hooks/usePullToRefresh.ts +51 -0
  110. package/Components/Screen/TV/index.web.tsx +4 -2
  111. package/Components/Screen/__tests__/Screen.test.tsx +65 -42
  112. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +68 -44
  113. package/Components/Screen/hooks.ts +2 -3
  114. package/Components/Screen/index.tsx +2 -3
  115. package/Components/Screen/orientationHandler.ts +3 -3
  116. package/Components/ScreenResolver/index.tsx +9 -5
  117. package/Components/ScreenRevealManager/Overlay.tsx +34 -0
  118. package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
  119. package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
  120. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
  121. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +9 -20
  122. package/Components/Tabs/TabContent.tsx +7 -4
  123. package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +201 -0
  124. package/Components/TopCutoffOverlay/hooks/__tests__/useMarginTop.test.ts +130 -0
  125. package/Components/TopCutoffOverlay/hooks/index.ts +1 -0
  126. package/Components/TopCutoffOverlay/hooks/useMarginTop.ts +59 -0
  127. package/Components/TopCutoffOverlay/index.tsx +55 -0
  128. package/Components/Transitioner/index.js +3 -3
  129. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +5 -5
  130. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +15 -7
  131. package/Components/VideoModal/utils.ts +12 -10
  132. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
  133. package/Components/Viewport/ViewportAware/index.tsx +16 -7
  134. package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
  135. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +4 -6
  136. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  137. package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
  138. package/Contexts/ScreenContext/index.tsx +25 -18
  139. package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
  140. package/Decorators/Analytics/index.tsx +6 -5
  141. package/Decorators/ConfigurationWrapper/__tests__/__snapshots__/withConfigurationProvider.test.tsx.snap +1 -0
  142. package/Decorators/ConfigurationWrapper/const.ts +1 -0
  143. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
  144. package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +1 -1
  145. package/Decorators/ZappPipesDataConnector/index.tsx +2 -2
  146. package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +1 -1
  147. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
  148. package/Helpers/DataSourceHelper/__tests__/itemLimitForData.test.ts +80 -0
  149. package/Helpers/DataSourceHelper/index.ts +19 -0
  150. package/Helpers/index.js +7 -1
  151. package/package.json +5 -5
  152. package/Components/Layout/TV/LayoutBackground.tsx +0 -28
  153. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +0 -135
  154. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/types.ts +0 -25
  155. package/Components/River/TV/withTVEventHandler.tsx +0 -36
  156. package/Helpers/DataSourceHelper/index.js +0 -19
@@ -1,6 +1,11 @@
1
1
  import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
2
2
  import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
3
- import { once } from "ramda";
3
+ import { race, Subject, Subscription } from "rxjs";
4
+ import { first } from "rxjs/operators";
5
+
6
+ import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
7
+
8
+ const MAX_TIMEOUT_TO_WAIT_COMPONENTS_TO_LOAD = 2000; // 2 seconds
4
9
 
5
10
  const INITIAL_NUMBER_TO_LOAD = 3;
6
11
 
@@ -34,7 +39,8 @@ const getNumberOfComponentsWaitToLoadBeforePresent = (
34
39
  export class ScreenRevealManager {
35
40
  public numberOfComponentsWaitToLoadBeforePresent: number;
36
41
  private renderingState: Array<ComponentLoadingState>;
37
- private callback: Callback;
42
+ private subject$ = new Subject<void>();
43
+ private subscription: Subscription;
38
44
 
39
45
  constructor(componentsToRender: ZappUIComponent[], callback: Callback) {
40
46
  this.numberOfComponentsWaitToLoadBeforePresent =
@@ -45,32 +51,58 @@ export class ScreenRevealManager {
45
51
  this.numberOfComponentsWaitToLoadBeforePresent
46
52
  );
47
53
 
48
- this.callback = once(callback);
54
+ this.subscription = race(
55
+ withTimeout$(MAX_TIMEOUT_TO_WAIT_COMPONENTS_TO_LOAD),
56
+ this.subject$
57
+ )
58
+ .pipe(first())
59
+ .subscribe(callback);
49
60
  }
50
61
 
51
62
  onLoadFinished = (index: number): void => {
63
+ const currentState = this.renderingState[index];
64
+
65
+ if (
66
+ COMPONENT_LOADING_STATE.LOADED_WITH_SUCCESS === currentState ||
67
+ COMPONENT_LOADING_STATE.LOADED_WITH_FAILURE === currentState
68
+ ) {
69
+ return;
70
+ }
71
+
52
72
  this.renderingState[index] = COMPONENT_LOADING_STATE.LOADED_WITH_SUCCESS;
53
73
 
54
74
  if (
55
75
  getNumberOfLoaded(this.renderingState) >=
56
76
  this.numberOfComponentsWaitToLoadBeforePresent
57
77
  ) {
58
- this.setIsReadyToShow();
78
+ this.subject$.next();
79
+ this.subject$.complete();
59
80
  }
60
81
  };
61
82
 
62
83
  onLoadFailed = (index: number): void => {
84
+ const currentState = this.renderingState[index];
85
+
86
+ if (
87
+ COMPONENT_LOADING_STATE.LOADED_WITH_SUCCESS === currentState ||
88
+ COMPONENT_LOADING_STATE.LOADED_WITH_FAILURE === currentState
89
+ ) {
90
+ return;
91
+ }
92
+
63
93
  this.renderingState[index] = COMPONENT_LOADING_STATE.LOADED_WITH_FAILURE;
64
94
 
65
95
  if (
66
96
  getNumberOfLoaded(this.renderingState) >=
67
97
  this.numberOfComponentsWaitToLoadBeforePresent
68
98
  ) {
69
- this.setIsReadyToShow();
99
+ this.subject$.next();
100
+ this.subject$.complete();
70
101
  }
71
102
  };
72
103
 
73
- setIsReadyToShow = (): void => {
74
- this.callback();
75
- };
104
+ dispose(): void {
105
+ this.subscription?.unsubscribe();
106
+ this.subject$.complete();
107
+ }
76
108
  }
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import { Animated } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ jest.mock(
6
+ "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage",
7
+ () => {
8
+ const { Text } = require("react-native");
9
+
10
+ return {
11
+ BackgroundImage: () => (
12
+ <Text testID="background-image">BackgroundImage</Text>
13
+ ),
14
+ };
15
+ }
16
+ );
17
+
18
+ import { Overlay } from "../Overlay";
19
+
20
+ const flattenStyle = (style: unknown): Record<string, unknown> => {
21
+ if (!style) {
22
+ return {};
23
+ }
24
+
25
+ if (Array.isArray(style)) {
26
+ return style.reduce<Record<string, unknown>>(
27
+ (acc, item) => ({ ...acc, ...flattenStyle(item) }),
28
+ {}
29
+ );
30
+ }
31
+
32
+ if (typeof style === "object") {
33
+ return style as Record<string, unknown>;
34
+ }
35
+
36
+ return {};
37
+ };
38
+
39
+ describe("Overlay", () => {
40
+ it("renders the animated overlay container", () => {
41
+ const opacity = new Animated.Value(1);
42
+
43
+ const { getByTestId } = render(
44
+ <Overlay opacity={opacity} backgroundColor="#000000" />
45
+ );
46
+
47
+ expect(getByTestId("animated-component")).toBeTruthy();
48
+ });
49
+
50
+ it("applies opacity and backgroundColor to the overlay", () => {
51
+ const opacity = new Animated.Value(0.5);
52
+
53
+ const { getByTestId } = render(
54
+ <Overlay opacity={opacity} backgroundColor="#ff0000" />
55
+ );
56
+
57
+ const style = flattenStyle(getByTestId("animated-component").props.style);
58
+
59
+ expect(style.backgroundColor).toBe("#ff0000");
60
+ expect(style.opacity).toBe(0.5);
61
+ });
62
+
63
+ it("positions the overlay with absolute fill layout", () => {
64
+ const opacity = new Animated.Value(1);
65
+
66
+ const { getByTestId } = render(
67
+ <Overlay opacity={opacity} backgroundColor="#000000" />
68
+ );
69
+
70
+ const style = flattenStyle(getByTestId("animated-component").props.style);
71
+
72
+ expect(style.position).toBe("absolute");
73
+ expect(style.top).toBe(0);
74
+ expect(style.left).toBe(0);
75
+ expect(style.right).toBe(0);
76
+ expect(style.bottom).toBe(0);
77
+ });
78
+
79
+ it("renders BackgroundImage inside the overlay", () => {
80
+ const opacity = new Animated.Value(1);
81
+
82
+ const { getByTestId } = render(
83
+ <Overlay opacity={opacity} backgroundColor="#000000" />
84
+ );
85
+
86
+ expect(getByTestId("background-image")).toBeTruthy();
87
+ });
88
+ });
@@ -2,106 +2,123 @@ import {
2
2
  ScreenRevealManager,
3
3
  COMPONENT_LOADING_STATE,
4
4
  } from "../ScreenRevealManager";
5
+ import { Subject } from "rxjs";
6
+
7
+ jest.mock("@applicaster/zapp-react-native-utils/arrayUtils", () => ({
8
+ makeListOf: jest.fn((value: any, length: number) =>
9
+ Array(length).fill(value)
10
+ ),
11
+ }));
12
+
13
+ jest.mock("@applicaster/zapp-react-native-utils/componentsUtils", () => ({
14
+ isFirstComponentGallery: jest.fn(),
15
+ }));
16
+
17
+ jest.mock("@applicaster/zapp-react-native-utils/idleUtils", () => ({
18
+ withTimeout$: jest.fn(),
19
+ }));
20
+
21
+ import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
22
+ import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
23
+ import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
5
24
 
6
25
  describe("ScreenRevealManager", () => {
7
- const mockCallback = jest.fn();
26
+ let mockCallback: jest.Mock;
27
+ let timeout$: Subject<void>;
8
28
 
9
29
  beforeEach(() => {
10
- jest.clearAllMocks();
11
- });
12
-
13
- it("should initialize with the correct number of components to wait for", () => {
14
- const componentsToRender: ZappUIComponent[] = [
15
- { component_type: "component1" },
16
- { component_type: "component2" },
17
- { component_type: "component3" },
18
- ];
30
+ jest.useFakeTimers();
31
+ mockCallback = jest.fn();
32
+ timeout$ = new Subject();
19
33
 
20
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
34
+ (withTimeout$ as jest.Mock).mockReturnValue(timeout$);
35
+ (isFirstComponentGallery as jest.Mock).mockReturnValue(false);
21
36
 
22
- expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
37
+ (makeListOf as jest.Mock).mockImplementation((value, length) =>
38
+ Array(length).fill(value)
39
+ );
40
+ });
23
41
 
24
- expect(manager.renderingState).toEqual([
25
- COMPONENT_LOADING_STATE.UNKNOWN,
26
- COMPONENT_LOADING_STATE.UNKNOWN,
27
- COMPONENT_LOADING_STATE.UNKNOWN,
28
- ]);
42
+ afterEach(() => {
43
+ jest.clearAllTimers();
44
+ jest.useRealTimers();
45
+ jest.resetAllMocks();
29
46
  });
30
47
 
31
- it("should call the callback when the required number of components are loaded successfully", () => {
32
- const componentsToRender: ZappUIComponent[] = [
33
- { component_type: "component1" },
34
- { component_type: "component2" },
35
- { component_type: "component3" },
36
- ];
48
+ // ────────────────────────────────────────────────
49
+ it("should initialize with correct number of components and UNKNOWN state", () => {
50
+ const components = new Array(5).fill({});
51
+ const mgr = new ScreenRevealManager(components, mockCallback);
37
52
 
38
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
53
+ expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
54
+ expect(makeListOf).toHaveBeenCalledWith(COMPONENT_LOADING_STATE.UNKNOWN, 3);
55
+ });
39
56
 
40
- manager.onLoadFinished(0);
41
- manager.onLoadFinished(1);
42
- manager.onLoadFinished(2);
57
+ // ────────────────────────────────────────────────
58
+ it("should set numberOfComponentsWaitToLoadBeforePresent to 1 if first component is gallery", () => {
59
+ (isFirstComponentGallery as jest.Mock).mockReturnValue(true);
43
60
 
44
- expect(mockCallback).toHaveBeenCalledTimes(1);
61
+ const components = new Array(5).fill({});
62
+ const mgr = new ScreenRevealManager(components, mockCallback);
63
+
64
+ expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(1);
45
65
  });
46
66
 
47
- it("should call the callback when the required number of components fail to load", () => {
48
- const componentsToRender: ZappUIComponent[] = [
49
- { component_type: "component1" },
50
- { component_type: "component2" },
51
- { component_type: "component3" },
52
- ];
67
+ // ────────────────────────────────────────────────
68
+ it("should trigger callback after all components load successfully", () => {
69
+ const components = new Array(3).fill({});
70
+ const mgr = new ScreenRevealManager(components, mockCallback);
53
71
 
54
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
72
+ mgr.onLoadFinished(0);
73
+ expect(mockCallback).not.toHaveBeenCalled();
55
74
 
56
- manager.onLoadFailed(0);
57
- manager.onLoadFailed(1);
58
- manager.onLoadFailed(2);
75
+ mgr.onLoadFinished(1);
76
+ expect(mockCallback).not.toHaveBeenCalled();
59
77
 
78
+ mgr.onLoadFinished(2);
60
79
  expect(mockCallback).toHaveBeenCalledTimes(1);
61
80
  });
62
81
 
63
- it("should call the callback when a mix of successful and failed loads meet the required number", () => {
64
- const componentsToRender: ZappUIComponent[] = [
65
- { component_type: "component1" },
66
- { component_type: "component2" },
67
- { component_type: "component3" },
68
- ];
69
-
70
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
82
+ // ────────────────────────────────────────────────
83
+ it("should trigger callback after some components fail to load but all finished", () => {
84
+ const components = new Array(3).fill({});
85
+ const mgr = new ScreenRevealManager(components, mockCallback);
71
86
 
72
- manager.onLoadFinished(0);
73
- manager.onLoadFailed(1);
74
- manager.onLoadFinished(2);
87
+ mgr.onLoadFinished(0);
88
+ mgr.onLoadFailed(1);
89
+ mgr.onLoadFailed(2);
75
90
 
76
91
  expect(mockCallback).toHaveBeenCalledTimes(1);
77
92
  });
78
93
 
79
- it("should not call the callback if the required number of components are not loaded", () => {
80
- const componentsToRender: ZappUIComponent[] = [
81
- { component_type: "component1" },
82
- { component_type: "component2" },
83
- { component_type: "component3" },
84
- ];
85
-
86
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
94
+ // ────────────────────────────────────────────────
95
+ it("should not trigger callback twice when same component finishes twice", () => {
96
+ const components = new Array(3).fill({});
97
+ const mgr = new ScreenRevealManager(components, mockCallback);
87
98
 
88
- manager.onLoadFinished(0);
89
- manager.onLoadFailed(1);
99
+ mgr.onLoadFinished(0);
100
+ mgr.onLoadFinished(0); // duplicate
101
+ mgr.onLoadFinished(1);
102
+ mgr.onLoadFinished(2);
90
103
 
91
- expect(mockCallback).not.toHaveBeenCalled();
104
+ expect(mockCallback).toHaveBeenCalledTimes(1);
92
105
  });
93
106
 
94
- it("should call the callback when the when first component is gallery and it was loaded successfully", () => {
95
- const componentsToRender: ZappUIComponent[] = [
96
- { component_type: "gallery-qb" },
97
- { component_type: "component2" },
98
- { component_type: "component3" },
99
- ];
107
+ // ────────────────────────────────────────────────
108
+ it("should trigger callback when timeout$ emits before all loaded", () => {
109
+ const components = new Array(3).fill({});
110
+ new ScreenRevealManager(components, mockCallback);
100
111
 
101
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
102
-
103
- manager.onLoadFinished(0);
112
+ timeout$.next(); // simulate timeout event from withTimeout$
104
113
 
105
114
  expect(mockCallback).toHaveBeenCalledTimes(1);
106
115
  });
116
+
117
+ // ────────────────────────────────────────────────
118
+ it("should not call callback if nothing loads and no timeout emitted", () => {
119
+ const components = new Array(3).fill({});
120
+ new ScreenRevealManager(components, mockCallback);
121
+
122
+ expect(mockCallback).not.toHaveBeenCalled();
123
+ });
107
124
  });
@@ -1,8 +1,10 @@
1
1
  import * as React from "react";
2
- import { Animated, StyleSheet } from "react-native";
2
+ import { Animated } from "react-native";
3
+
3
4
  import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
4
5
  import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
5
6
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
7
+ import { Overlay } from "./Overlay";
6
8
 
7
9
  import { ScreenRevealManager } from "./ScreenRevealManager";
8
10
  import {
@@ -10,13 +12,6 @@ import {
10
12
  emitScreenRevealManagerIsNotReadyToShow,
11
13
  } from "./utils";
12
14
 
13
- const styles = StyleSheet.create({
14
- container: {
15
- ...StyleSheet.absoluteFillObject,
16
- position: "absolute",
17
- },
18
- });
19
-
20
15
  export const TIMEOUT = 300; // 300 ms
21
16
 
22
17
  const HIDDEN = 0; // opacity = 0
@@ -77,7 +72,7 @@ export const withScreenRevealManager = (Component) => {
77
72
 
78
73
  if (isFirstComponentScreenPicker(componentsToRender)) {
79
74
  // for screen-picker with have additional internal ComponentsMap, no need to add this wrapper
80
- return <Component {...props} initialNumberToLoad={1} />;
75
+ return <Component {...props} />;
81
76
  }
82
77
 
83
78
  return (
@@ -93,17 +88,11 @@ export const withScreenRevealManager = (Component) => {
93
88
  onLoadFailedFromScreenRevealManager={managerRef.current.onLoadFailed}
94
89
  />
95
90
  {isShowOverlay ? (
96
- <Animated.View
97
- style={[
98
- styles.container,
99
- {
100
- opacity: opacityRef.current,
101
- // TODO: we should support background image as well, but for now we will use background color from theme
102
- backgroundColor:
103
- props.backgroundColor ?? theme.app_background_color,
104
- },
105
- ]}
106
- testID="animated-component"
91
+ <Overlay
92
+ opacity={opacityRef.current}
93
+ backgroundColor={
94
+ props.backgroundColor ?? theme.app_background_color
95
+ }
107
96
  />
108
97
  ) : null}
109
98
  </>
@@ -1,11 +1,10 @@
1
1
  import React from "react";
2
- import { View, ViewStyle } from "react-native";
2
+ import { View, StyleSheet } from "react-native";
3
3
 
4
4
  import { River } from "@applicaster/zapp-react-native-ui-components/Components";
5
5
  import { withNestedNavigationContextProvider } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
6
6
 
7
7
  type Props = {
8
- styles: Record<string, ViewStyle>;
9
8
  minHeight: number;
10
9
  changingTab: boolean;
11
10
  feedUrl: string;
@@ -14,9 +13,14 @@ type Props = {
14
13
  backgroundColor: string;
15
14
  };
16
15
 
16
+ const styles = StyleSheet.create({
17
+ riverWrapper: {
18
+ flex: 1,
19
+ },
20
+ });
21
+
17
22
  function TabContentComponent(props: Props) {
18
23
  const {
19
- styles,
20
24
  minHeight,
21
25
  backgroundColor,
22
26
  changingTab,
@@ -29,7 +33,6 @@ function TabContentComponent(props: Props) {
29
33
  <View
30
34
  style={[
31
35
  styles.riverWrapper,
32
-
33
36
  {
34
37
  backgroundColor,
35
38
  minHeight,
@@ -0,0 +1,201 @@
1
+ import React from "react";
2
+ import { Text } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ jest.mock(
6
+ "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration",
7
+ () => ({
8
+ useScreenConfiguration: jest.fn(),
9
+ })
10
+ );
11
+
12
+ jest.mock(
13
+ "@applicaster/zapp-react-native-ui-components/Components/TopCutoffOverlay/hooks",
14
+ () => ({
15
+ useMarginTop: jest.fn(),
16
+ })
17
+ );
18
+
19
+ jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
20
+ useTheme: jest.fn(),
21
+ }));
22
+
23
+ import { TopCutoffOverlay } from "../index";
24
+ import { useMarginTop } from "../hooks";
25
+ import { useScreenConfiguration } from "../../River/useScreenConfiguration";
26
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
27
+
28
+ // Recursively find a View with position: absolute in the JSON tree
29
+ const findOverlayStyle = (node: any): Record<string, any> | null => {
30
+ if (!node) return null;
31
+
32
+ // Style can be a plain object or an array of style objects
33
+ const styles = Array.isArray(node.props?.style)
34
+ ? node.props.style
35
+ : node.props?.style
36
+ ? [node.props.style]
37
+ : [];
38
+
39
+ const styleObj = styles.find((s: any) => s?.position === "absolute");
40
+ if (styleObj) return styleObj;
41
+
42
+ const children = node.children || [];
43
+
44
+ if (Array.isArray(children)) {
45
+ for (const child of children) {
46
+ const result = findOverlayStyle(child);
47
+ if (result) return result;
48
+ }
49
+ }
50
+
51
+ const propChildren = node.props?.children;
52
+
53
+ if (propChildren && Array.isArray(propChildren)) {
54
+ for (const child of propChildren) {
55
+ const result = findOverlayStyle(child);
56
+ if (result) return result;
57
+ }
58
+ }
59
+
60
+ if (
61
+ typeof propChildren === "object" &&
62
+ propChildren !== null &&
63
+ "type" in propChildren
64
+ ) {
65
+ return findOverlayStyle(propChildren);
66
+ }
67
+
68
+ return null;
69
+ };
70
+
71
+ describe("TopCutoffOverlay", () => {
72
+ const mockUseMarginTop = useMarginTop as jest.MockedFunction<
73
+ typeof useMarginTop
74
+ >;
75
+
76
+ const mockUseScreenConfig = useScreenConfiguration as jest.MockedFunction<
77
+ typeof useScreenConfiguration
78
+ >;
79
+
80
+ const mockUseTheme = useTheme as jest.MockedFunction<typeof useTheme>;
81
+
82
+ beforeEach(() => {
83
+ jest.clearAllMocks();
84
+ mockUseMarginTop.mockReturnValue(60);
85
+ mockUseScreenConfig.mockReturnValue({ backgroundColor: "#1a1a1a" });
86
+ mockUseTheme.mockReturnValue({ app_background_color: "#222222" });
87
+ });
88
+
89
+ it("renders children when applyTopCutoff is false", () => {
90
+ const { getByText } = render(
91
+ <TopCutoffOverlay applyTopCutoff={false}>
92
+ <Text>Child content</Text>
93
+ </TopCutoffOverlay>
94
+ );
95
+
96
+ expect(getByText("Child content")).toBeTruthy();
97
+ });
98
+
99
+ it("does not render overlay when applyTopCutoff is false", () => {
100
+ const tree = render(
101
+ <TopCutoffOverlay applyTopCutoff={false}>
102
+ <Text>Child content</Text>
103
+ </TopCutoffOverlay>
104
+ );
105
+
106
+ expect(findOverlayStyle(tree.toJSON())).toBeNull();
107
+ });
108
+
109
+ it("renders overlay when applyTopCutoff is true (default)", () => {
110
+ const tree = render(
111
+ <TopCutoffOverlay>
112
+ <Text>Child content</Text>
113
+ </TopCutoffOverlay>
114
+ );
115
+
116
+ expect(findOverlayStyle(tree.toJSON())).not.toBeNull();
117
+ });
118
+
119
+ it("renders overlay with correct height from useMarginTop", () => {
120
+ const tree = render(
121
+ <TopCutoffOverlay>
122
+ <Text>Child content</Text>
123
+ </TopCutoffOverlay>
124
+ );
125
+
126
+ expect(findOverlayStyle(tree.toJSON())?.height).toBe(60);
127
+ });
128
+
129
+ it("uses screenBackgroundColor from useScreenConfiguration when available", () => {
130
+ mockUseScreenConfig.mockReturnValue({ backgroundColor: "#ff0000" });
131
+
132
+ const tree = render(
133
+ <TopCutoffOverlay>
134
+ <Text>Child content</Text>
135
+ </TopCutoffOverlay>
136
+ );
137
+
138
+ expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#ff0000");
139
+ });
140
+
141
+ it("falls back to themeBackgroundColor when screenBackgroundColor is not available", () => {
142
+ mockUseScreenConfig.mockReturnValue({ backgroundColor: undefined });
143
+
144
+ const tree = render(
145
+ <TopCutoffOverlay>
146
+ <Text>Child content</Text>
147
+ </TopCutoffOverlay>
148
+ );
149
+
150
+ expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
151
+ });
152
+
153
+ it("falls back to transparent when neither screenBackgroundColor nor themeBackgroundColor is available", () => {
154
+ mockUseScreenConfig.mockReturnValue({ backgroundColor: undefined });
155
+ mockUseTheme.mockReturnValue({});
156
+
157
+ const tree = render(
158
+ <TopCutoffOverlay>
159
+ <Text>Child content</Text>
160
+ </TopCutoffOverlay>
161
+ );
162
+
163
+ expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe(
164
+ "transparent"
165
+ );
166
+ });
167
+
168
+ it("passes targetScreenId to useMarginTop and useScreenConfiguration", () => {
169
+ render(
170
+ <TopCutoffOverlay targetScreenId="custom-screen-1">
171
+ <Text>Child content</Text>
172
+ </TopCutoffOverlay>
173
+ );
174
+
175
+ expect(mockUseMarginTop).toHaveBeenCalledWith("custom-screen-1");
176
+ expect(mockUseScreenConfig).toHaveBeenCalledWith("custom-screen-1");
177
+ });
178
+
179
+ it("positions overlay at top with left/right 0", () => {
180
+ const tree = render(
181
+ <TopCutoffOverlay>
182
+ <Text>Child content</Text>
183
+ </TopCutoffOverlay>
184
+ );
185
+
186
+ const style = findOverlayStyle(tree.toJSON());
187
+ expect(style?.top).toBe(0);
188
+ expect(style?.left).toBe(0);
189
+ expect(style?.right).toBe(0);
190
+ });
191
+
192
+ it("renders children inside the container", () => {
193
+ const { getByText } = render(
194
+ <TopCutoffOverlay>
195
+ <Text>Child content</Text>
196
+ </TopCutoffOverlay>
197
+ );
198
+
199
+ expect(getByText("Child content")).toBeTruthy();
200
+ });
201
+ });