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

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 (155) 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/TV/NavBarContainer.tsx +1 -10
  15. package/Components/Layout/TV/ScreenContainer.tsx +2 -6
  16. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
  17. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
  18. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
  19. package/Components/Layout/TV/index.tsx +5 -7
  20. package/Components/Layout/TV/index.web.tsx +5 -7
  21. package/Components/LinkHandler/LinkHandler.tsx +2 -2
  22. package/Components/MasterCell/CONFIG_BUILDER_TO_REACT_COMPONENT.md +144 -0
  23. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
  24. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
  25. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
  26. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
  27. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
  28. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +165 -0
  29. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +405 -0
  30. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/index.ts +1 -0
  31. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
  32. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
  33. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
  34. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
  35. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
  36. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -10
  37. package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
  38. package/Components/MasterCell/DefaultComponents/ButtonContainerView/components/HorizontalSeparator.tsx +8 -0
  39. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +15 -0
  40. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tv.android.tsx +58 -0
  41. package/Components/MasterCell/DefaultComponents/{tv/ButtonContainerView/index.tsx → ButtonContainerView/index.tv.tsx} +3 -11
  42. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.web.ts +1 -0
  43. package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +40 -0
  44. package/Components/MasterCell/DefaultComponents/DataProvider/index.tsx +163 -0
  45. package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +2 -23
  46. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -22
  47. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +8 -2
  48. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +11 -3
  49. package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +9 -1
  50. package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +15 -14
  51. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +1 -2
  52. package/Components/MasterCell/DefaultComponents/PressableView.tsx +34 -0
  53. package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
  54. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +11 -0
  55. package/Components/MasterCell/DefaultComponents/__tests__/DataProvider.test.tsx +141 -0
  56. package/Components/MasterCell/DefaultComponents/index.ts +9 -3
  57. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +135 -0
  58. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +33 -0
  59. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +22 -0
  60. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +125 -0
  61. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
  62. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
  63. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +37 -0
  64. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +393 -0
  65. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +141 -0
  66. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +343 -0
  67. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
  68. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +122 -0
  69. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
  70. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +238 -0
  71. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Asset.ts +4 -18
  72. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Button.ts +24 -73
  73. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TextLabelsContainer.ts +37 -18
  74. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TvActionButton.tsx +27 -0
  75. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +89 -0
  76. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/renderedTree.test.tsx +231 -0
  77. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +47 -48
  78. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
  79. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +101 -144
  80. package/Components/MasterCell/MappingFunctions/index.js +3 -2
  81. package/Components/MasterCell/README.md +4 -0
  82. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +24 -0
  83. package/Components/MasterCell/__tests__/configInflater.test.js +1 -0
  84. package/Components/MasterCell/__tests__/elementMapper.test.js +46 -0
  85. package/Components/MasterCell/dataAdapter.ts +4 -1
  86. package/Components/MasterCell/elementMapper.tsx +52 -7
  87. package/Components/MasterCell/utils/__tests__/cloneChildrenWithIds.test.tsx +43 -0
  88. package/Components/MasterCell/utils/__tests__/useFilterChildren.test.tsx +80 -0
  89. package/Components/MasterCell/utils/index.ts +85 -15
  90. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +2 -2
  91. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +17 -18
  92. package/Components/OfflineHandler/__tests__/index.test.tsx +27 -18
  93. package/Components/PlayerContainer/PlayerContainer.tsx +8 -5
  94. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
  95. package/Components/River/ComponentsMap/ComponentsMap.tsx +6 -19
  96. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
  97. package/Components/River/RefreshControl.tsx +19 -88
  98. package/Components/River/River.tsx +9 -82
  99. package/Components/River/TV/River.tsx +31 -14
  100. package/Components/River/TV/index.tsx +8 -4
  101. package/Components/River/TV/utils/__tests__/toStringOrEmpty.test.ts +30 -0
  102. package/Components/River/TV/utils/index.ts +4 -0
  103. package/Components/River/TV/withFocusableGroupForContent.tsx +71 -0
  104. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +1 -0
  105. package/Components/River/__tests__/componentsMap.test.js +38 -0
  106. package/Components/River/hooks/__tests__/usePullToRefresh.test.ts +132 -0
  107. package/Components/River/hooks/index.ts +1 -0
  108. package/Components/River/hooks/usePullToRefresh.ts +51 -0
  109. package/Components/Screen/TV/index.web.tsx +4 -2
  110. package/Components/Screen/__tests__/Screen.test.tsx +65 -42
  111. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +68 -44
  112. package/Components/Screen/hooks.ts +2 -3
  113. package/Components/Screen/index.tsx +2 -3
  114. package/Components/Screen/orientationHandler.ts +3 -3
  115. package/Components/ScreenResolver/index.tsx +9 -5
  116. package/Components/ScreenRevealManager/Overlay.tsx +34 -0
  117. package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
  118. package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
  119. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
  120. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +9 -20
  121. package/Components/Tabs/TabContent.tsx +7 -4
  122. package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +201 -0
  123. package/Components/TopCutoffOverlay/hooks/__tests__/useMarginTop.test.ts +130 -0
  124. package/Components/TopCutoffOverlay/hooks/index.ts +1 -0
  125. package/Components/TopCutoffOverlay/hooks/useMarginTop.ts +59 -0
  126. package/Components/TopCutoffOverlay/index.tsx +55 -0
  127. package/Components/Transitioner/index.js +3 -3
  128. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +5 -5
  129. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +15 -7
  130. package/Components/VideoModal/utils.ts +12 -10
  131. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
  132. package/Components/Viewport/ViewportAware/index.tsx +16 -7
  133. package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
  134. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +4 -6
  135. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  136. package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
  137. package/Contexts/ScreenContext/index.tsx +25 -18
  138. package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
  139. package/Decorators/Analytics/index.tsx +6 -5
  140. package/Decorators/ConfigurationWrapper/__tests__/__snapshots__/withConfigurationProvider.test.tsx.snap +1 -0
  141. package/Decorators/ConfigurationWrapper/const.ts +1 -0
  142. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
  143. package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +1 -1
  144. package/Decorators/ZappPipesDataConnector/index.tsx +2 -2
  145. package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +1 -1
  146. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
  147. package/Helpers/DataSourceHelper/__tests__/itemLimitForData.test.ts +80 -0
  148. package/Helpers/DataSourceHelper/index.ts +19 -0
  149. package/Helpers/index.js +7 -1
  150. package/package.json +5 -5
  151. package/Components/Layout/TV/LayoutBackground.tsx +0 -28
  152. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +0 -135
  153. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/types.ts +0 -25
  154. package/Components/River/TV/withTVEventHandler.tsx +0 -36
  155. package/Helpers/DataSourceHelper/index.js +0 -19
@@ -1,67 +1,91 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`<Screen Component /> when the navbar should be hidden renders correctly 1`] = `
4
- <View
5
- importantForAccessibility="yes"
4
+ <RNCSafeAreaProvider
5
+ onInsetsChange={[Function]}
6
6
  style={
7
- {
8
- "backgroundColor": "blue",
9
- "flex": 1,
10
- "paddingTop": 0,
11
- }
7
+ [
8
+ {
9
+ "flex": 1,
10
+ },
11
+ undefined,
12
+ ]
12
13
  }
13
14
  >
14
15
  <View
15
- hasMenu={false}
16
- id="/river/testId"
17
- pathname="/river/testId"
18
- selected="testId"
19
- testID="navBar"
20
- title="Test Title"
21
- />
22
- <View>
16
+ importantForAccessibility="yes"
17
+ style={
18
+ {
19
+ "backgroundColor": "blue",
20
+ "flex": 1,
21
+ "paddingTop": 0,
22
+ }
23
+ }
24
+ >
23
25
  <View
26
+ hasMenu={false}
27
+ id="/river/testId"
24
28
  pathname="/river/testId"
25
- screenData={
26
- {
27
- "id": "testId",
28
- }
29
- }
30
- testID="routeManager"
29
+ selected="testId"
30
+ testID="navBar"
31
+ title="Test Title"
31
32
  />
33
+ <View>
34
+ <View
35
+ pathname="/river/testId"
36
+ screenData={
37
+ {
38
+ "id": "testId",
39
+ }
40
+ }
41
+ testID="routeManager"
42
+ />
43
+ </View>
32
44
  </View>
33
- </View>
45
+ </RNCSafeAreaProvider>
34
46
  `;
35
47
 
36
48
  exports[`<Screen Component /> when the navbar should show renders correctly 1`] = `
37
- <View
38
- importantForAccessibility="yes"
49
+ <RNCSafeAreaProvider
50
+ onInsetsChange={[Function]}
39
51
  style={
40
- {
41
- "backgroundColor": "blue",
42
- "flex": 1,
43
- "paddingTop": 0,
44
- }
52
+ [
53
+ {
54
+ "flex": 1,
55
+ },
56
+ undefined,
57
+ ]
45
58
  }
46
59
  >
47
60
  <View
48
- hasMenu={false}
49
- id="/river/testId"
50
- pathname="/river/testId"
51
- selected="testId"
52
- testID="navBar"
53
- title="Test Title"
54
- />
55
- <View>
61
+ importantForAccessibility="yes"
62
+ style={
63
+ {
64
+ "backgroundColor": "blue",
65
+ "flex": 1,
66
+ "paddingTop": 0,
67
+ }
68
+ }
69
+ >
56
70
  <View
71
+ hasMenu={false}
72
+ id="/river/testId"
57
73
  pathname="/river/testId"
58
- screenData={
59
- {
60
- "id": "testId",
61
- }
62
- }
63
- testID="routeManager"
74
+ selected="testId"
75
+ testID="navBar"
76
+ title="Test Title"
64
77
  />
78
+ <View>
79
+ <View
80
+ pathname="/river/testId"
81
+ screenData={
82
+ {
83
+ "id": "testId",
84
+ }
85
+ }
86
+ testID="routeManager"
87
+ />
88
+ </View>
65
89
  </View>
66
- </View>
90
+ </RNCSafeAreaProvider>
67
91
  `;
@@ -1,4 +1,4 @@
1
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
1
+ import { useAppData } from "@applicaster/zapp-react-native-redux/hooks";
2
2
  import {
3
3
  useGetScreenOrientation,
4
4
  isOrientationCompatible,
@@ -95,8 +95,7 @@ export const useWaitForValidOrientation = () => {
95
95
 
96
96
  const isTablet = useIsTablet();
97
97
 
98
- const { appData } = usePickFromState(["appData"]);
99
- const isTabletPortrait = appData?.isTabletPortrait;
98
+ const { isTabletPortrait } = useAppData();
100
99
 
101
100
  const layoutData = useMemo(
102
101
  () => ({ isTablet, isTabletPortrait, width: screenWidth, height }),
@@ -1,8 +1,7 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import React from "react";
3
3
  import { AccessibilityInfo, findNodeHandle, View } from "react-native";
4
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
5
-
4
+ import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
6
5
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
7
6
  import { getComponentModule } from "@applicaster/zapp-react-native-utils/pluginUtils";
8
7
  import {
@@ -41,7 +40,7 @@ type Props = {
41
40
  export function Screen(_props: Props) {
42
41
  const theme = useTheme<BaseThemePropertiesMobile>();
43
42
  const navigation = useNavigation();
44
- const { plugins } = usePickFromState(["plugins"]);
43
+ const plugins = usePlugins();
45
44
 
46
45
  // Gets the data for the current screen configuration
47
46
  const currentScreenData = useCurrentScreenData();
@@ -7,7 +7,7 @@ import {
7
7
  useGetScreenOrientation,
8
8
  } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
9
9
  import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
10
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
10
+ import { usePlugins, useAppData } from "@applicaster/zapp-react-native-redux";
11
11
  import { findPluginByType } from "@applicaster/zapp-react-native-utils/pluginUtils";
12
12
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
13
13
  import { zappHookModalStore } from "../../Contexts/ZappHookModalContext";
@@ -63,8 +63,8 @@ export function useNewOrientationForScreenData({
63
63
  }: OrientationHookArgs) {
64
64
  const isTablet = useIsTablet();
65
65
 
66
- const { appData, plugins } = usePickFromState(["appData", "plugins"]);
67
- const isTabletPortrait = appData?.isTabletPortrait;
66
+ const plugins = usePlugins();
67
+ const { isTabletPortrait } = useAppData();
68
68
  const isLandscapeTablet = isTablet && !isTabletPortrait;
69
69
 
70
70
  const screenOrientation = useGetScreenOrientation(screenData);
@@ -1,10 +1,18 @@
1
1
  import * as React from "react";
2
2
 
3
3
  import { componentsLogger } from "../../Helpers/logger";
4
+
4
5
  import { useScreenAnalytics } from "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks";
6
+
7
+ import { ScreenResultCallback } from "@applicaster/zapp-react-native-utils/zappFrameworkUtils/HookCallback/callbackNavigationAction";
5
8
  import { useScreenComponentResolver } from "./hooks/useScreenComponentResolver";
6
9
  import { withDefaultScreenContext } from "./withDefaultScreenContext";
7
10
 
11
+ export enum PresentationType {
12
+ Standalone = "Standalone",
13
+ Hook = "Hook",
14
+ }
15
+
8
16
  const logger = componentsLogger.addSubsystem("ScreenResolver");
9
17
 
10
18
  type Props = {
@@ -14,6 +22,7 @@ type Props = {
14
22
  feedId?: string;
15
23
  feedTitle?: string;
16
24
  focused?: boolean;
25
+ resultCallback?: ScreenResultCallback;
17
26
  parentFocus?: {
18
27
  nextFocusDown?: React.Ref<any>;
19
28
  nextFocusRight?: React.Ref<any>;
@@ -23,11 +32,6 @@ type Props = {
23
32
  groupId?: string;
24
33
  };
25
34
 
26
- export enum PresentationType {
27
- Standalone = "Standalone",
28
- Hook = "Hook",
29
- }
30
-
31
35
  export function ScreenResolverComponent(props: Props) {
32
36
  const { screenType } = props;
33
37
  const component = useScreenComponentResolver(screenType, props);
@@ -0,0 +1,34 @@
1
+ import * as React from "react";
2
+ import { Animated, StyleSheet } from "react-native";
3
+
4
+ import { BackgroundImage } from "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage";
5
+
6
+ const styles = StyleSheet.create({
7
+ container: {
8
+ ...StyleSheet.absoluteFillObject,
9
+ position: "absolute",
10
+ },
11
+ });
12
+
13
+ export const Overlay = ({
14
+ opacity,
15
+ backgroundColor,
16
+ }: {
17
+ opacity: Animated.Value;
18
+ backgroundColor: string;
19
+ }) => {
20
+ return (
21
+ <Animated.View
22
+ style={[
23
+ styles.container,
24
+ {
25
+ opacity,
26
+ backgroundColor,
27
+ },
28
+ ]}
29
+ testID="animated-component"
30
+ >
31
+ <BackgroundImage />
32
+ </Animated.View>
33
+ );
34
+ };
@@ -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
  });