@applicaster/zapp-react-native-ui-components 15.1.0-rc.3 → 16.0.0-alpha.7128076344

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 (144) hide show
  1. package/Components/BaseFocusable/index.ios.ts +12 -2
  2. package/Components/Cell/FocusableWrapper.tsx +3 -0
  3. package/Components/Cell/TvOSCellComponent.tsx +6 -3
  4. package/Components/Focusable/Focusable.tsx +4 -2
  5. package/Components/Focusable/FocusableTvOS.tsx +18 -1
  6. package/Components/Focusable/__tests__/__snapshots__/FocusableTvOS.test.tsx.snap +1 -0
  7. package/Components/FocusableGroup/FocusableTvOS.tsx +30 -1
  8. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +1 -1
  9. package/Components/HandlePlayable/HandlePlayable.tsx +13 -8
  10. package/Components/Layout/TV/LayoutBackground.tsx +5 -2
  11. package/Components/Layout/TV/NavBarContainer.tsx +1 -10
  12. package/Components/Layout/TV/ScreenContainer.tsx +2 -6
  13. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
  14. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
  15. package/Components/Layout/TV/index.tsx +3 -4
  16. package/Components/Layout/TV/index.web.tsx +3 -4
  17. package/Components/LinkHandler/LinkHandler.tsx +2 -2
  18. package/Components/MasterCell/CONFIG_BUILDER_TO_REACT_COMPONENT.md +144 -0
  19. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
  20. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
  21. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
  22. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
  23. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +165 -0
  24. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +405 -0
  25. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/index.ts +1 -0
  26. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
  27. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
  28. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
  29. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
  30. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
  31. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -10
  32. package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
  33. package/Components/MasterCell/DefaultComponents/ButtonContainerView/components/HorizontalSeparator.tsx +8 -0
  34. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +15 -0
  35. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tv.android.tsx +58 -0
  36. package/Components/MasterCell/DefaultComponents/{tv/ButtonContainerView/index.tsx → ButtonContainerView/index.tv.tsx} +3 -11
  37. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.web.ts +1 -0
  38. package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +40 -0
  39. package/Components/MasterCell/DefaultComponents/DataProvider/index.tsx +163 -0
  40. package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +2 -23
  41. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -22
  42. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +8 -2
  43. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +11 -3
  44. package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +9 -1
  45. package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +15 -14
  46. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +1 -2
  47. package/Components/MasterCell/DefaultComponents/PressableView.tsx +34 -0
  48. package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
  49. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +11 -0
  50. package/Components/MasterCell/DefaultComponents/__tests__/DataProvider.test.tsx +141 -0
  51. package/Components/MasterCell/DefaultComponents/index.ts +9 -3
  52. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +135 -0
  53. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +33 -0
  54. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +22 -0
  55. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +125 -0
  56. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
  57. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
  58. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +37 -0
  59. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +393 -0
  60. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +141 -0
  61. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +343 -0
  62. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
  63. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +122 -0
  64. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
  65. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +238 -0
  66. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Asset.ts +4 -18
  67. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Button.ts +24 -73
  68. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TextLabelsContainer.ts +37 -18
  69. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TvActionButton.tsx +27 -0
  70. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +89 -0
  71. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/renderedTree.test.tsx +231 -0
  72. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +47 -48
  73. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
  74. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +101 -144
  75. package/Components/MasterCell/MappingFunctions/index.js +3 -2
  76. package/Components/MasterCell/README.md +4 -0
  77. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +24 -0
  78. package/Components/MasterCell/__tests__/configInflater.test.js +1 -0
  79. package/Components/MasterCell/__tests__/elementMapper.test.js +46 -0
  80. package/Components/MasterCell/dataAdapter.ts +4 -1
  81. package/Components/MasterCell/elementMapper.tsx +52 -7
  82. package/Components/MasterCell/utils/__tests__/cloneChildrenWithIds.test.tsx +43 -0
  83. package/Components/MasterCell/utils/__tests__/useFilterChildren.test.tsx +80 -0
  84. package/Components/MasterCell/utils/index.ts +85 -15
  85. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +2 -2
  86. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +17 -18
  87. package/Components/OfflineHandler/__tests__/index.test.tsx +27 -18
  88. package/Components/PlayerContainer/PlayerContainer.tsx +14 -13
  89. package/Components/River/ComponentsMap/ComponentsMap.tsx +6 -19
  90. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
  91. package/Components/River/RefreshControl.tsx +19 -88
  92. package/Components/River/River.tsx +9 -82
  93. package/Components/River/TV/River.tsx +31 -14
  94. package/Components/River/TV/index.tsx +8 -4
  95. package/Components/River/TV/utils/__tests__/toStringOrEmpty.test.ts +30 -0
  96. package/Components/River/TV/utils/index.ts +4 -0
  97. package/Components/River/TV/withFocusableGroupForContent.tsx +71 -0
  98. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +1 -0
  99. package/Components/River/__tests__/componentsMap.test.js +38 -0
  100. package/Components/River/hooks/__tests__/usePullToRefresh.test.ts +132 -0
  101. package/Components/River/hooks/index.ts +1 -0
  102. package/Components/River/hooks/usePullToRefresh.ts +51 -0
  103. package/Components/Screen/TV/index.web.tsx +4 -2
  104. package/Components/Screen/__tests__/Screen.test.tsx +65 -42
  105. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +68 -44
  106. package/Components/Screen/hooks.ts +2 -3
  107. package/Components/Screen/index.tsx +2 -3
  108. package/Components/Screen/orientationHandler.ts +3 -3
  109. package/Components/ScreenResolver/index.tsx +9 -5
  110. package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
  111. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
  112. package/Components/Tabs/TabContent.tsx +7 -4
  113. package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +201 -0
  114. package/Components/TopCutoffOverlay/hooks/__tests__/useMarginTop.test.ts +130 -0
  115. package/Components/TopCutoffOverlay/hooks/index.ts +1 -0
  116. package/Components/TopCutoffOverlay/hooks/useMarginTop.ts +59 -0
  117. package/Components/TopCutoffOverlay/index.tsx +55 -0
  118. package/Components/Transitioner/index.js +3 -3
  119. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +5 -5
  120. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +15 -7
  121. package/Components/VideoModal/utils.ts +12 -9
  122. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
  123. package/Components/Viewport/ViewportAware/index.tsx +16 -7
  124. package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
  125. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +4 -6
  126. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  127. package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
  128. package/Contexts/ScreenContext/index.tsx +25 -18
  129. package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
  130. package/Decorators/Analytics/index.tsx +6 -5
  131. package/Decorators/ConfigurationWrapper/__tests__/__snapshots__/withConfigurationProvider.test.tsx.snap +1 -0
  132. package/Decorators/ConfigurationWrapper/const.ts +1 -0
  133. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
  134. package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +1 -1
  135. package/Decorators/ZappPipesDataConnector/index.tsx +2 -2
  136. package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +1 -1
  137. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
  138. package/Helpers/DataSourceHelper/__tests__/itemLimitForData.test.ts +80 -0
  139. package/Helpers/DataSourceHelper/index.ts +19 -0
  140. package/package.json +5 -5
  141. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +0 -135
  142. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/types.ts +0 -25
  143. package/Components/River/TV/withTVEventHandler.tsx +0 -36
  144. 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
  }
@@ -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,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
+ });
@@ -0,0 +1,130 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import { useMarginTop } from "../useMarginTop";
3
+
4
+ // Mocks
5
+ jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
6
+ useTheme: jest.fn(),
7
+ }));
8
+
9
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
10
+ useCurrentScreenData: jest.fn(),
11
+ }));
12
+
13
+ jest.mock("@applicaster/zapp-react-native-utils/componentsUtils", () => ({
14
+ isFirstComponentScreenPicker: jest.fn(),
15
+ }));
16
+
17
+ // Imports after mocks
18
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
19
+ import { useCurrentScreenData } from "@applicaster/zapp-react-native-utils/reactHooks";
20
+ import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
21
+
22
+ describe("useMarginTop", () => {
23
+ const mockTheme = {
24
+ screen_margin_top: 10,
25
+ };
26
+
27
+ beforeEach(() => {
28
+ jest.clearAllMocks();
29
+
30
+ (useTheme as jest.Mock).mockReturnValue(mockTheme);
31
+ });
32
+
33
+ it("returns 0 when ScreenPicker is first component", () => {
34
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
35
+ ui_components: [],
36
+ });
37
+
38
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(true);
39
+
40
+ const { result } = renderHook(() => useMarginTop("screen1"));
41
+
42
+ expect(result.current).toBe(0);
43
+ });
44
+
45
+ it("returns 0 for player screen", () => {
46
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
47
+ plugin_type: "player",
48
+ });
49
+
50
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(false);
51
+
52
+ const { result } = renderHook(() => useMarginTop("screen1"));
53
+
54
+ expect(result.current).toBe(0);
55
+ });
56
+
57
+ it("returns theme value when margin is empty string", () => {
58
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
59
+ styles: {
60
+ screen_margin_top: "",
61
+ },
62
+ });
63
+
64
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(false);
65
+
66
+ const { result } = renderHook(() => useMarginTop("screen1"));
67
+
68
+ expect(result.current).toBe(10);
69
+ });
70
+
71
+ it("returns theme value when undefined and general content screen", () => {
72
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
73
+ plugin_type: "general_content",
74
+ styles: {
75
+ screen_margin_top: undefined,
76
+ },
77
+ });
78
+
79
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(false);
80
+
81
+ const { result } = renderHook(() => useMarginTop("screen1"));
82
+
83
+ expect(result.current).toBe(10);
84
+ });
85
+
86
+ it("returns theme value when undefined and supports ui_components", () => {
87
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
88
+ ui_components: ["something"],
89
+ styles: {
90
+ screen_margin_top: undefined,
91
+ },
92
+ });
93
+
94
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(false);
95
+
96
+ const { result } = renderHook(() => useMarginTop("screen1"));
97
+
98
+ expect(result.current).toBe(10);
99
+ });
100
+
101
+ it("returns 0 when undefined and not general content and no ui_components", () => {
102
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
103
+ plugin_type: "other",
104
+ ui_components: null,
105
+ styles: {
106
+ screen_margin_top: undefined,
107
+ },
108
+ });
109
+
110
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(false);
111
+
112
+ const { result } = renderHook(() => useMarginTop("screen1"));
113
+
114
+ expect(result.current).toBe(0);
115
+ });
116
+
117
+ it("returns value from screenData when defined", () => {
118
+ (useCurrentScreenData as jest.Mock).mockReturnValue({
119
+ styles: {
120
+ screen_margin_top: 25,
121
+ },
122
+ });
123
+
124
+ (isFirstComponentScreenPicker as jest.Mock).mockReturnValue(false);
125
+
126
+ const { result } = renderHook(() => useMarginTop("screen1"));
127
+
128
+ expect(result.current).toBe(25);
129
+ });
130
+ });
@@ -0,0 +1 @@
1
+ export { useMarginTop } from "./useMarginTop";