@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.
- package/Components/BaseFocusable/index.ios.ts +12 -2
- package/Components/Cell/FocusableWrapper.tsx +3 -0
- package/Components/Cell/TvOSCellComponent.tsx +6 -3
- package/Components/Focusable/Focusable.tsx +4 -2
- package/Components/Focusable/FocusableTvOS.tsx +18 -1
- package/Components/Focusable/__tests__/__snapshots__/FocusableTvOS.test.tsx.snap +1 -0
- package/Components/FocusableGroup/FocusableTvOS.tsx +30 -1
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +1 -1
- package/Components/HandlePlayable/HandlePlayable.tsx +13 -8
- package/Components/Layout/TV/LayoutBackground.tsx +5 -2
- package/Components/Layout/TV/NavBarContainer.tsx +1 -10
- package/Components/Layout/TV/ScreenContainer.tsx +2 -6
- package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/index.tsx +3 -4
- package/Components/Layout/TV/index.web.tsx +3 -4
- package/Components/LinkHandler/LinkHandler.tsx +2 -2
- package/Components/MasterCell/CONFIG_BUILDER_TO_REACT_COMPONENT.md +144 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +165 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +405 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/index.ts +1 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
- package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -10
- package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/components/HorizontalSeparator.tsx +8 -0
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +15 -0
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tv.android.tsx +58 -0
- package/Components/MasterCell/DefaultComponents/{tv/ButtonContainerView/index.tsx → ButtonContainerView/index.tv.tsx} +3 -11
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.web.ts +1 -0
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +40 -0
- package/Components/MasterCell/DefaultComponents/DataProvider/index.tsx +163 -0
- package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +2 -23
- package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -22
- package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +8 -2
- package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +11 -3
- package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +9 -1
- package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +15 -14
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +1 -2
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +34 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +11 -0
- package/Components/MasterCell/DefaultComponents/__tests__/DataProvider.test.tsx +141 -0
- package/Components/MasterCell/DefaultComponents/index.ts +9 -3
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +135 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +33 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +22 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +125 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +37 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +393 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +141 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +343 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +122 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +238 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Asset.ts +4 -18
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Button.ts +24 -73
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TextLabelsContainer.ts +37 -18
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TvActionButton.tsx +27 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +89 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/renderedTree.test.tsx +231 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +47 -48
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +101 -144
- package/Components/MasterCell/MappingFunctions/index.js +3 -2
- package/Components/MasterCell/README.md +4 -0
- package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +24 -0
- package/Components/MasterCell/__tests__/configInflater.test.js +1 -0
- package/Components/MasterCell/__tests__/elementMapper.test.js +46 -0
- package/Components/MasterCell/dataAdapter.ts +4 -1
- package/Components/MasterCell/elementMapper.tsx +52 -7
- package/Components/MasterCell/utils/__tests__/cloneChildrenWithIds.test.tsx +43 -0
- package/Components/MasterCell/utils/__tests__/useFilterChildren.test.tsx +80 -0
- package/Components/MasterCell/utils/index.ts +85 -15
- package/Components/OfflineHandler/NotificationView/NotificationView.tsx +2 -2
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +17 -18
- package/Components/OfflineHandler/__tests__/index.test.tsx +27 -18
- package/Components/PlayerContainer/PlayerContainer.tsx +14 -13
- package/Components/River/ComponentsMap/ComponentsMap.tsx +6 -19
- package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
- package/Components/River/RefreshControl.tsx +19 -88
- package/Components/River/River.tsx +9 -82
- package/Components/River/TV/River.tsx +31 -14
- package/Components/River/TV/index.tsx +8 -4
- package/Components/River/TV/utils/__tests__/toStringOrEmpty.test.ts +30 -0
- package/Components/River/TV/utils/index.ts +4 -0
- package/Components/River/TV/withFocusableGroupForContent.tsx +71 -0
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +1 -0
- package/Components/River/__tests__/componentsMap.test.js +38 -0
- package/Components/River/hooks/__tests__/usePullToRefresh.test.ts +132 -0
- package/Components/River/hooks/index.ts +1 -0
- package/Components/River/hooks/usePullToRefresh.ts +51 -0
- package/Components/Screen/TV/index.web.tsx +4 -2
- package/Components/Screen/__tests__/Screen.test.tsx +65 -42
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +68 -44
- package/Components/Screen/hooks.ts +2 -3
- package/Components/Screen/index.tsx +2 -3
- package/Components/Screen/orientationHandler.ts +3 -3
- package/Components/ScreenResolver/index.tsx +9 -5
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
- package/Components/Tabs/TabContent.tsx +7 -4
- package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +201 -0
- package/Components/TopCutoffOverlay/hooks/__tests__/useMarginTop.test.ts +130 -0
- package/Components/TopCutoffOverlay/hooks/index.ts +1 -0
- package/Components/TopCutoffOverlay/hooks/useMarginTop.ts +59 -0
- package/Components/TopCutoffOverlay/index.tsx +55 -0
- package/Components/Transitioner/index.js +3 -3
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +5 -5
- package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +15 -7
- package/Components/VideoModal/utils.ts +12 -9
- package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
- package/Components/Viewport/ViewportAware/index.tsx +16 -7
- package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
- package/Components/ZappFrameworkComponents/BarView/BarView.tsx +4 -6
- package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
- package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
- package/Contexts/ScreenContext/index.tsx +25 -18
- package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
- package/Decorators/Analytics/index.tsx +6 -5
- package/Decorators/ConfigurationWrapper/__tests__/__snapshots__/withConfigurationProvider.test.tsx.snap +1 -0
- package/Decorators/ConfigurationWrapper/const.ts +1 -0
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
- package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +1 -1
- package/Decorators/ZappPipesDataConnector/index.tsx +2 -2
- package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +1 -1
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
- package/Helpers/DataSourceHelper/__tests__/itemLimitForData.test.ts +80 -0
- package/Helpers/DataSourceHelper/index.ts +19 -0
- package/package.json +5 -5
- package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +0 -135
- package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/types.ts +0 -25
- package/Components/River/TV/withTVEventHandler.tsx +0 -36
- 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 {
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
99
|
+
this.subject$.next();
|
|
100
|
+
this.subject$.complete();
|
|
70
101
|
}
|
|
71
102
|
};
|
|
72
103
|
|
|
73
|
-
|
|
74
|
-
this.
|
|
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
|
-
|
|
26
|
+
let mockCallback: jest.Mock;
|
|
27
|
+
let timeout$: Subject<void>;
|
|
8
28
|
|
|
9
29
|
beforeEach(() => {
|
|
10
|
-
jest.
|
|
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
|
-
|
|
34
|
+
(withTimeout$ as jest.Mock).mockReturnValue(timeout$);
|
|
35
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(false);
|
|
21
36
|
|
|
22
|
-
|
|
37
|
+
(makeListOf as jest.Mock).mockImplementation((value, length) =>
|
|
38
|
+
Array(length).fill(value)
|
|
39
|
+
);
|
|
40
|
+
});
|
|
23
41
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
jest.clearAllTimers();
|
|
44
|
+
jest.useRealTimers();
|
|
45
|
+
jest.resetAllMocks();
|
|
29
46
|
});
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
53
|
+
expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
54
|
+
expect(makeListOf).toHaveBeenCalledWith(COMPONENT_LOADING_STATE.UNKNOWN, 3);
|
|
55
|
+
});
|
|
39
56
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
// ────────────────────────────────────────────────
|
|
58
|
+
it("should set numberOfComponentsWaitToLoadBeforePresent to 1 if first component is gallery", () => {
|
|
59
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(true);
|
|
43
60
|
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
72
|
+
mgr.onLoadFinished(0);
|
|
73
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
55
74
|
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
89
|
-
|
|
99
|
+
mgr.onLoadFinished(0);
|
|
100
|
+
mgr.onLoadFinished(0); // duplicate
|
|
101
|
+
mgr.onLoadFinished(1);
|
|
102
|
+
mgr.onLoadFinished(2);
|
|
90
103
|
|
|
91
|
-
expect(mockCallback).
|
|
104
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
92
105
|
});
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
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,
|
|
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";
|