@applicaster/zapp-react-native-ui-components 17.0.0-rc.3 → 17.0.0-rc.4
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/AudioPlayer/index.web.tsx +10 -0
- package/Components/Cell/PlatformCellComponent.ts +9 -0
- package/Components/Cell/PlatformCellComponent.web.ts +3 -0
- package/Components/Cell/index.js +2 -9
- package/Components/CellRendererResolver/index.ts +20 -1
- package/Components/ComponentResolver/ComponentResolver.ts +4 -0
- package/Components/Focusable/index.web.tsx +3 -0
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +29 -4
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.android.tv.tsx +7 -4
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +1 -0
- package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +10 -4
- package/Components/MasterCell/DefaultComponents/Image/index.web.ts +7 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +30 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +22 -4
- package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.missingPlugin.test.tsx +66 -0
- package/Components/MasterCell/__tests__/masterCell.test.js +56 -0
- package/Components/MasterCell/index.tsx +17 -2
- package/Components/MasterCell/utils/__tests__/getFocusableElementId.test.ts +38 -0
- package/Components/MasterCell/utils/index.ts +39 -1
- package/Components/ModalComponent/Button/index.tsx +3 -1
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +29 -2
- package/Components/ModalComponent/presets/index.ts +2 -3
- package/Components/River/ComponentsMap/index.web.tsx +3 -0
- package/Components/River/RiverItem.tsx +4 -0
- package/Components/River/TV/River.tsx +7 -1
- package/Components/ScreenResolver/index.tsx +4 -1
- package/Components/Tabs/TV/index.web.tsx +5 -0
- package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +56 -10
- package/Components/TopCutoffOverlay/index.tsx +41 -10
- package/Components/VideoLive/__tests__/LiveImageManager.test.ts +30 -0
- package/Components/VideoModal/PlayerDetails.tsx +27 -2
- package/Components/VideoModal/PlayerWrapper.tsx +5 -1
- package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +84 -0
- package/Components/VideoModal/__tests__/playerWrapperStyle.test.ts +206 -1
- package/Components/VideoModal/__tests__/playerWrapperUtils.test.ts +110 -1
- package/Components/VideoModal/playerWrapperStyle.ts +41 -20
- package/Components/VideoModal/playerWrapperUtils.ts +134 -0
- package/Components/__tests__/webVariants.test.js +73 -0
- package/Components/default-cell-renderer/containerStyles/index.web.ts +6 -0
- package/Components/default-cell-renderer/viewTrees/index.web.ts +10 -0
- package/Decorators/RiverResolver/__tests__/riverResolver.missingRiver.test.tsx +52 -0
- package/Decorators/RiverResolver/index.tsx +25 -0
- package/package.json +5 -5
|
@@ -11,8 +11,6 @@ export { selectableCell } from "./selectableCell";
|
|
|
11
11
|
|
|
12
12
|
import { dynamicCollectionCell } from "./dynamicCollectionCell";
|
|
13
13
|
|
|
14
|
-
const SELECTION_ROLES = new Set(["collection_selector", "preference_editor"]);
|
|
15
|
-
|
|
16
14
|
/**
|
|
17
15
|
* Resolve the row cell from feed role (+ behavior for future config only).
|
|
18
16
|
* Unknown / none -> standard Button cell.
|
|
@@ -22,6 +20,7 @@ export const getCell = (
|
|
|
22
20
|
_behavior?: SelectionBehavior
|
|
23
21
|
): CellRenderer => {
|
|
24
22
|
if (role === "dynamic_collection") return dynamicCollectionCell;
|
|
23
|
+
if (role === "collection_selector") return selectableCell;
|
|
25
24
|
|
|
26
|
-
return
|
|
25
|
+
return standardCell;
|
|
27
26
|
};
|
|
@@ -124,6 +124,10 @@ function RiverItemComponent(props: RiverItemType) {
|
|
|
124
124
|
if (isComponentMissing) {
|
|
125
125
|
riverLogger.warning({
|
|
126
126
|
message: `Component ${item.component_type} is null - skipping rendering`,
|
|
127
|
+
data: {
|
|
128
|
+
diagnostic: { code: "component-plugin-missing" },
|
|
129
|
+
component: item,
|
|
130
|
+
},
|
|
127
131
|
});
|
|
128
132
|
|
|
129
133
|
onLoadFinished(index);
|
|
@@ -97,7 +97,13 @@ export const River = (props: Props) => {
|
|
|
97
97
|
if (!river) {
|
|
98
98
|
utilsLogger.error({
|
|
99
99
|
message: `River ${screenData.id} not found!`,
|
|
100
|
-
data: {
|
|
100
|
+
data: {
|
|
101
|
+
diagnostic: { code: "type-mapping" },
|
|
102
|
+
screen_id: screenData?.id,
|
|
103
|
+
// Without a river the screen data is the entry that was pushed.
|
|
104
|
+
entry: screenData,
|
|
105
|
+
feedData,
|
|
106
|
+
},
|
|
101
107
|
});
|
|
102
108
|
|
|
103
109
|
return <Text>`River ${screenData?.id} not found!`</Text>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Text } from "react-native";
|
|
2
|
+
import { StyleSheet, Text } from "react-native";
|
|
3
3
|
import { render } from "@testing-library/react-native";
|
|
4
4
|
|
|
5
5
|
jest.mock(
|
|
@@ -29,15 +29,8 @@ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
|
29
29
|
const findOverlayStyle = (node: any): Record<string, any> | null => {
|
|
30
30
|
if (!node) return null;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
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;
|
|
32
|
+
const style = StyleSheet.flatten(node.props?.style);
|
|
33
|
+
if (style?.position === "absolute") return style;
|
|
41
34
|
|
|
42
35
|
const children = node.children || [];
|
|
43
36
|
|
|
@@ -138,6 +131,59 @@ describe("TopCutoffOverlay", () => {
|
|
|
138
131
|
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#ff0000");
|
|
139
132
|
});
|
|
140
133
|
|
|
134
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is transparent", () => {
|
|
135
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "transparent" });
|
|
136
|
+
|
|
137
|
+
const tree = render(
|
|
138
|
+
<TopCutoffOverlay>
|
|
139
|
+
<Text>Child content</Text>
|
|
140
|
+
</TopCutoffOverlay>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is transparent rgba", () => {
|
|
147
|
+
mockUseScreenConfig.mockReturnValue({
|
|
148
|
+
backgroundColor: "rgba(0,0,0,0)",
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const tree = render(
|
|
152
|
+
<TopCutoffOverlay>
|
|
153
|
+
<Text>Child content</Text>
|
|
154
|
+
</TopCutoffOverlay>
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is invalid", () => {
|
|
161
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "not-a-color" });
|
|
162
|
+
|
|
163
|
+
const tree = render(
|
|
164
|
+
<TopCutoffOverlay>
|
|
165
|
+
<Text>Child content</Text>
|
|
166
|
+
</TopCutoffOverlay>
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("falls back to transparent when both screen and theme background colors are invalid", () => {
|
|
173
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "not-a-color" });
|
|
174
|
+
mockUseTheme.mockReturnValue({ app_background_color: "also-not-a-color" });
|
|
175
|
+
|
|
176
|
+
const tree = render(
|
|
177
|
+
<TopCutoffOverlay>
|
|
178
|
+
<Text>Child content</Text>
|
|
179
|
+
</TopCutoffOverlay>
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe(
|
|
183
|
+
"transparent"
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
141
187
|
it("falls back to themeBackgroundColor when screenBackgroundColor is not available", () => {
|
|
142
188
|
mockUseScreenConfig.mockReturnValue({ backgroundColor: undefined });
|
|
143
189
|
|
|
@@ -3,8 +3,32 @@ import { View, StyleSheet } from "react-native";
|
|
|
3
3
|
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
4
4
|
import { useScreenConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration";
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
isValidColor,
|
|
8
|
+
isTransparentColor,
|
|
9
|
+
} from "@applicaster/zapp-react-native-utils/colorUtils";
|
|
10
|
+
|
|
6
11
|
import { useMarginTop } from "./hooks";
|
|
7
12
|
|
|
13
|
+
function getTopCutoffBackgroundColor(
|
|
14
|
+
screenBackgroundColor: string,
|
|
15
|
+
themeBackgroundColor: string
|
|
16
|
+
) {
|
|
17
|
+
if (isTransparentColor(screenBackgroundColor)) {
|
|
18
|
+
return isValidColor(themeBackgroundColor)
|
|
19
|
+
? themeBackgroundColor
|
|
20
|
+
: "transparent";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isValidColor(screenBackgroundColor)) {
|
|
24
|
+
return screenBackgroundColor;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return isValidColor(themeBackgroundColor)
|
|
28
|
+
? themeBackgroundColor
|
|
29
|
+
: "transparent";
|
|
30
|
+
}
|
|
31
|
+
|
|
8
32
|
interface IProps {
|
|
9
33
|
targetScreenId?: string;
|
|
10
34
|
children: React.ReactElement | null;
|
|
@@ -15,6 +39,12 @@ const styles = StyleSheet.create({
|
|
|
15
39
|
container: {
|
|
16
40
|
flex: 1,
|
|
17
41
|
},
|
|
42
|
+
cutoffBlock: {
|
|
43
|
+
position: "absolute",
|
|
44
|
+
top: 0,
|
|
45
|
+
left: 0,
|
|
46
|
+
right: 0,
|
|
47
|
+
},
|
|
18
48
|
});
|
|
19
49
|
|
|
20
50
|
export const TopCutoffOverlay: React.FC<IProps> = ({
|
|
@@ -39,16 +69,17 @@ export const TopCutoffOverlay: React.FC<IProps> = ({
|
|
|
39
69
|
{children}
|
|
40
70
|
|
|
41
71
|
<View
|
|
42
|
-
style={
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
style={[
|
|
73
|
+
styles.cutoffBlock,
|
|
74
|
+
{
|
|
75
|
+
height: cutoffHeight,
|
|
76
|
+
|
|
77
|
+
backgroundColor: getTopCutoffBackgroundColor(
|
|
78
|
+
screenBackgroundColor,
|
|
79
|
+
themeBackgroundColor
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
]}
|
|
52
83
|
/>
|
|
53
84
|
</View>
|
|
54
85
|
);
|
|
@@ -109,6 +109,36 @@ describe("LiveImageManager", () => {
|
|
|
109
109
|
expect(item.player.play).toHaveBeenCalledTimes(1);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
it("does not start a second call that reuses a player id", async () => {
|
|
113
|
+
const manager = new LiveImageManager();
|
|
114
|
+
|
|
115
|
+
const makeItem = (tag: string) => ({
|
|
116
|
+
playerId: "player-1",
|
|
117
|
+
tag,
|
|
118
|
+
player: {
|
|
119
|
+
playerId: "player-1",
|
|
120
|
+
playerState: { isReadyToPlay: false },
|
|
121
|
+
getEntry: jest.fn(),
|
|
122
|
+
play: jest.fn(),
|
|
123
|
+
pause: jest.fn(),
|
|
124
|
+
onPlayerClose: jest.fn(),
|
|
125
|
+
},
|
|
126
|
+
getPlayer: jest.fn(),
|
|
127
|
+
prepareForPlayback: jest.fn().mockResolvedValue(true),
|
|
128
|
+
setMode: jest.fn(),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const first = makeItem("first");
|
|
132
|
+
const second = makeItem("second");
|
|
133
|
+
|
|
134
|
+
manager.playLiveImage(first);
|
|
135
|
+
manager.playLiveImage(second);
|
|
136
|
+
await flushPromises();
|
|
137
|
+
|
|
138
|
+
expect(second.prepareForPlayback).not.toHaveBeenCalled();
|
|
139
|
+
expect(manager.getCurrentlyPlaying()).toBe(first);
|
|
140
|
+
});
|
|
141
|
+
|
|
112
142
|
it("should not start a live image that was paused before the player loaded", async () => {
|
|
113
143
|
const manager = new LiveImageManager();
|
|
114
144
|
|
|
@@ -9,16 +9,22 @@ import {
|
|
|
9
9
|
} from "react-native";
|
|
10
10
|
import { useTargetScreenData } from "@applicaster/zapp-react-native-utils/reactHooks/screen";
|
|
11
11
|
import { ComponentsMap } from "@applicaster/zapp-react-native-ui-components/Components/River/ComponentsMap";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
useSafeAreaFrame,
|
|
14
|
+
useSafeAreaInsets,
|
|
15
|
+
} from "react-native-safe-area-context";
|
|
13
16
|
import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
|
|
14
17
|
import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
15
18
|
import { useDelayedPlayerDetails } from "./hooks";
|
|
19
|
+
import { getVerticalColumnWidth } from "./playerWrapperUtils";
|
|
16
20
|
|
|
17
21
|
const { width: SCREEN_WIDTH } = Dimensions.get("screen");
|
|
18
22
|
|
|
19
23
|
type Configuration = {
|
|
20
24
|
[key: string]: any;
|
|
21
25
|
modal_background_color?: string;
|
|
26
|
+
tablet_landscape_sidebar_width?: string;
|
|
27
|
+
vertical_video_player?: boolean;
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
type Props = {
|
|
@@ -68,6 +74,20 @@ export const PlayerDetails = ({
|
|
|
68
74
|
const isTablet = useIsTablet();
|
|
69
75
|
const screenData = useTargetScreenData(entry);
|
|
70
76
|
const insets = useSafeAreaInsets();
|
|
77
|
+
const frame = useSafeAreaFrame();
|
|
78
|
+
|
|
79
|
+
// Entering fullscreen gives the player the whole row and squeezes this
|
|
80
|
+
// column to nothing. Android keeps that measurement for the text, so the
|
|
81
|
+
// column is derived from the frame -- the same split the player column uses
|
|
82
|
+
// -- instead of being measured, and stays put while fullscreen is open.
|
|
83
|
+
const columnWidth =
|
|
84
|
+
isTablet && isTabletLandscape && configuration.vertical_video_player
|
|
85
|
+
? frame.width -
|
|
86
|
+
getVerticalColumnWidth(
|
|
87
|
+
frame.width,
|
|
88
|
+
configuration.tablet_landscape_sidebar_width
|
|
89
|
+
)
|
|
90
|
+
: undefined;
|
|
71
91
|
|
|
72
92
|
const extraTabletStyles =
|
|
73
93
|
!isAudioPlayer && isTabletLandscape
|
|
@@ -106,6 +126,7 @@ export const PlayerDetails = ({
|
|
|
106
126
|
|
|
107
127
|
return (
|
|
108
128
|
<Animated.View
|
|
129
|
+
collapsable={false}
|
|
109
130
|
style={[
|
|
110
131
|
style,
|
|
111
132
|
extraTabletStyles,
|
|
@@ -118,13 +139,17 @@ export const PlayerDetails = ({
|
|
|
118
139
|
// workaround for avoid wrong text-height after going back to portrait rotation
|
|
119
140
|
// we don't see this view in landscape mode, so we are able to use fixed width from portrait mode
|
|
120
141
|
width: isTablet
|
|
121
|
-
?
|
|
142
|
+
? columnWidth
|
|
122
143
|
: (StyleSheet.flatten(style)?.width ?? SCREEN_WIDTH),
|
|
123
144
|
},
|
|
124
145
|
]}
|
|
125
146
|
>
|
|
126
147
|
{screenData ? (
|
|
127
148
|
<ComponentsMap
|
|
149
|
+
// River components measure themselves once and keep that width when
|
|
150
|
+
// the column changes on rotation, so the text overflows it. Remount
|
|
151
|
+
// them on the new column.
|
|
152
|
+
key={columnWidth}
|
|
128
153
|
riverId={screenData.id}
|
|
129
154
|
feed={screenData?.data?.source}
|
|
130
155
|
riverComponents={screenData.ui_components}
|
|
@@ -56,7 +56,11 @@ const PlayerWrapperComponent = (props: Props) => {
|
|
|
56
56
|
return (
|
|
57
57
|
<WrapperView
|
|
58
58
|
edges={getEdges(isTablet, isInlineModal, vertical) as readonly Edge[]}
|
|
59
|
-
style={
|
|
59
|
+
style={
|
|
60
|
+
styles.wrapperStyle
|
|
61
|
+
? [playerDimensionsHack, styles.wrapperStyle]
|
|
62
|
+
: playerDimensionsHack
|
|
63
|
+
}
|
|
60
64
|
>
|
|
61
65
|
<View
|
|
62
66
|
testID={`${entry?.id}-player-container`}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { Dimensions, StyleSheet } from "react-native";
|
|
2
3
|
import { render } from "@testing-library/react-native";
|
|
3
4
|
|
|
4
5
|
const props = {
|
|
@@ -7,6 +8,10 @@ const props = {
|
|
|
7
8
|
configuration: { modal_background_color: "transparent" },
|
|
8
9
|
};
|
|
9
10
|
|
|
11
|
+
let mockIsTablet = false;
|
|
12
|
+
|
|
13
|
+
const mockFrame = { x: 0, y: 0, width: 390, height: 844 };
|
|
14
|
+
|
|
10
15
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/layout", () => ({
|
|
11
16
|
useDimensions: jest.fn(() => ({
|
|
12
17
|
width: 20,
|
|
@@ -14,11 +19,20 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/layout", () => ({
|
|
|
14
19
|
})),
|
|
15
20
|
}));
|
|
16
21
|
|
|
22
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
|
|
23
|
+
useIsTablet: () => mockIsTablet,
|
|
24
|
+
}));
|
|
25
|
+
|
|
17
26
|
jest.mock("react-native-safe-area-context", () => ({
|
|
18
27
|
useSafeAreaInsets: jest.fn(() => ({
|
|
19
28
|
top: 20,
|
|
20
29
|
bottom: 0,
|
|
21
30
|
})),
|
|
31
|
+
useSafeAreaFrame: () => mockFrame,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
jest.mock("../hooks", () => ({
|
|
35
|
+
useDelayedPlayerDetails: () => true,
|
|
22
36
|
}));
|
|
23
37
|
|
|
24
38
|
jest.mock(
|
|
@@ -38,6 +52,10 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
|
38
52
|
})),
|
|
39
53
|
}));
|
|
40
54
|
|
|
55
|
+
const {
|
|
56
|
+
useTargetScreenData,
|
|
57
|
+
} = require("@applicaster/zapp-react-native-utils/reactHooks/screen");
|
|
58
|
+
|
|
41
59
|
const { PlayerDetails } = require("../PlayerDetails");
|
|
42
60
|
|
|
43
61
|
describe("PlayerDetails", () => {
|
|
@@ -55,3 +73,69 @@ describe("PlayerDetails", () => {
|
|
|
55
73
|
expect(toJSON()).toMatchSnapshot();
|
|
56
74
|
});
|
|
57
75
|
});
|
|
76
|
+
|
|
77
|
+
describe("PlayerDetails text column width", () => {
|
|
78
|
+
// Fullscreen collapses this column to nothing and Android keeps that
|
|
79
|
+
// measurement, so the width has to come from the frame instead of a layout
|
|
80
|
+
// pass. Rendering alone proves it: nothing here ever measures.
|
|
81
|
+
const renderDetails = (overrides = {}) => {
|
|
82
|
+
const { toJSON } = render(
|
|
83
|
+
<PlayerDetails
|
|
84
|
+
{...props}
|
|
85
|
+
configuration={{
|
|
86
|
+
...props.configuration,
|
|
87
|
+
vertical_video_player: true,
|
|
88
|
+
tablet_landscape_sidebar_width: "35%",
|
|
89
|
+
}}
|
|
90
|
+
isTabletLandscape={true}
|
|
91
|
+
{...overrides}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return StyleSheet.flatten(toJSON().props.style)?.width;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
mockIsTablet = true;
|
|
100
|
+
mockFrame.width = 1210;
|
|
101
|
+
mockFrame.height = 834;
|
|
102
|
+
|
|
103
|
+
useTargetScreenData.mockReturnValue({
|
|
104
|
+
id: "test-id",
|
|
105
|
+
ui_components: [{ id: "component-id" }],
|
|
106
|
+
data: { source: "test-source" },
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("derives the column from the frame, not from a measurement", () => {
|
|
111
|
+
expect(renderDetails()).toBeCloseTo(1210 * 0.35);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("follows the frame on rotation", () => {
|
|
115
|
+
mockFrame.width = 834;
|
|
116
|
+
mockFrame.height = 1210;
|
|
117
|
+
|
|
118
|
+
expect(renderDetails()).toBeCloseTo(834 * 0.35);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("leaves the tablet width alone without the vertical player", () => {
|
|
122
|
+
const width = renderDetails({
|
|
123
|
+
configuration: {
|
|
124
|
+
...props.configuration,
|
|
125
|
+
tablet_landscape_sidebar_width: "35%",
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(width).toBeUndefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("leaves the tablet width alone in portrait", () => {
|
|
133
|
+
expect(renderDetails({ isTabletLandscape: false })).toBeUndefined();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("keeps the screen width on a phone", () => {
|
|
137
|
+
mockIsTablet = false;
|
|
138
|
+
|
|
139
|
+
expect(renderDetails()).toBe(Dimensions.get("screen").width);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -4,12 +4,21 @@ import { useStyle } from "../playerWrapperStyle";
|
|
|
4
4
|
import { getScreenAspectRatio } from "../playerWrapperUtils";
|
|
5
5
|
|
|
6
6
|
let mockOrientation = "portrait";
|
|
7
|
+
let mockIsTablet = false;
|
|
8
|
+
|
|
9
|
+
const mockFrame = { x: 0, y: 0, width: 390, height: 844 };
|
|
10
|
+
const mockInsets = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
7
11
|
|
|
8
12
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
|
|
9
|
-
useIsTablet: () =>
|
|
13
|
+
useIsTablet: () => mockIsTablet,
|
|
10
14
|
useOrientation: () => mockOrientation,
|
|
11
15
|
}));
|
|
12
16
|
|
|
17
|
+
jest.mock("react-native-safe-area-context", () => ({
|
|
18
|
+
useSafeAreaFrame: () => mockFrame,
|
|
19
|
+
useSafeAreaInsets: () => mockInsets,
|
|
20
|
+
}));
|
|
21
|
+
|
|
13
22
|
const getAspectRatio = (props: {
|
|
14
23
|
vertical: boolean;
|
|
15
24
|
inline?: boolean;
|
|
@@ -33,6 +42,15 @@ const getAspectRatio = (props: {
|
|
|
33
42
|
describe("useStyle aspectRatio", () => {
|
|
34
43
|
const screenRatio = getScreenAspectRatio();
|
|
35
44
|
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
mockOrientation = "portrait";
|
|
47
|
+
mockIsTablet = false;
|
|
48
|
+
mockFrame.width = 390;
|
|
49
|
+
mockFrame.height = 844;
|
|
50
|
+
mockInsets.top = 0;
|
|
51
|
+
mockInsets.bottom = 0;
|
|
52
|
+
});
|
|
53
|
+
|
|
36
54
|
it("uses the screen ratio when not vertical", () => {
|
|
37
55
|
mockOrientation = "portrait";
|
|
38
56
|
expect(getAspectRatio({ vertical: false })).toBeCloseTo(screenRatio);
|
|
@@ -55,4 +73,191 @@ describe("useStyle aspectRatio", () => {
|
|
|
55
73
|
9 / 16
|
|
56
74
|
);
|
|
57
75
|
});
|
|
76
|
+
|
|
77
|
+
it("stretches tablet landscape vertical video to the column height", () => {
|
|
78
|
+
mockOrientation = "landscape";
|
|
79
|
+
mockIsTablet = true;
|
|
80
|
+
mockFrame.width = 1210;
|
|
81
|
+
mockFrame.height = 834;
|
|
82
|
+
mockInsets.top = 24;
|
|
83
|
+
mockInsets.bottom = 20;
|
|
84
|
+
|
|
85
|
+
const { result } = renderHook(() =>
|
|
86
|
+
useStyle({
|
|
87
|
+
// Android reports the pre-rotation size here; the layout has to follow
|
|
88
|
+
// the frame instead.
|
|
89
|
+
style: { width: 834, height: 1210 },
|
|
90
|
+
inline: true,
|
|
91
|
+
isModal: true,
|
|
92
|
+
isTabletPortrait: false,
|
|
93
|
+
configuration: { tablet_landscape_sidebar_width: "35%" },
|
|
94
|
+
pip: false,
|
|
95
|
+
vertical: true,
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const columnWidth = 1210 * (1 - 35 / 100);
|
|
100
|
+
const videoHeight = 834 - 24 - 20;
|
|
101
|
+
|
|
102
|
+
expect(result.current.wrapperStyle).toEqual({
|
|
103
|
+
width: columnWidth,
|
|
104
|
+
height: 834,
|
|
105
|
+
paddingBottom: 20,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(result.current.childrenStyles).toEqual({
|
|
109
|
+
width: videoHeight * (9 / 16),
|
|
110
|
+
height: videoHeight,
|
|
111
|
+
alignSelf: "center",
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("useStyle keeps the previous frame outside vertical tablet inline", () => {
|
|
117
|
+
const screenRatio = getScreenAspectRatio();
|
|
118
|
+
|
|
119
|
+
const legacyAspectRatio = ({
|
|
120
|
+
vertical,
|
|
121
|
+
inline,
|
|
122
|
+
isModal,
|
|
123
|
+
pip,
|
|
124
|
+
orientation,
|
|
125
|
+
}: {
|
|
126
|
+
vertical: boolean;
|
|
127
|
+
inline: boolean;
|
|
128
|
+
isModal: boolean;
|
|
129
|
+
pip: boolean;
|
|
130
|
+
orientation: string;
|
|
131
|
+
}) => {
|
|
132
|
+
const isInlineModal = inline && isModal;
|
|
133
|
+
const value = !isInlineModal && !pip ? screenRatio : 16 / 9;
|
|
134
|
+
|
|
135
|
+
if (!vertical) {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (orientation === "landscape" && !isInlineModal && !pip) {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return 1 / value;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const cases: Array<{
|
|
147
|
+
name: string;
|
|
148
|
+
vertical: boolean;
|
|
149
|
+
inline: boolean;
|
|
150
|
+
isModal: boolean;
|
|
151
|
+
pip: boolean;
|
|
152
|
+
isTablet: boolean;
|
|
153
|
+
isTabletPortrait: boolean;
|
|
154
|
+
orientation: "portrait" | "landscape";
|
|
155
|
+
}> = [
|
|
156
|
+
{
|
|
157
|
+
name: "phone portrait, horizontal",
|
|
158
|
+
vertical: false,
|
|
159
|
+
inline: true,
|
|
160
|
+
isModal: true,
|
|
161
|
+
pip: false,
|
|
162
|
+
isTablet: false,
|
|
163
|
+
isTabletPortrait: false,
|
|
164
|
+
orientation: "portrait",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "phone landscape, vertical inline",
|
|
168
|
+
vertical: true,
|
|
169
|
+
inline: true,
|
|
170
|
+
isModal: true,
|
|
171
|
+
pip: false,
|
|
172
|
+
isTablet: false,
|
|
173
|
+
isTabletPortrait: false,
|
|
174
|
+
orientation: "landscape",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "tablet portrait, vertical inline",
|
|
178
|
+
vertical: true,
|
|
179
|
+
inline: true,
|
|
180
|
+
isModal: true,
|
|
181
|
+
pip: false,
|
|
182
|
+
isTablet: true,
|
|
183
|
+
isTabletPortrait: true,
|
|
184
|
+
orientation: "portrait",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "tablet landscape, horizontal inline",
|
|
188
|
+
vertical: false,
|
|
189
|
+
inline: true,
|
|
190
|
+
isModal: true,
|
|
191
|
+
pip: false,
|
|
192
|
+
isTablet: true,
|
|
193
|
+
isTabletPortrait: false,
|
|
194
|
+
orientation: "landscape",
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "tablet landscape, vertical fullscreen",
|
|
198
|
+
vertical: true,
|
|
199
|
+
inline: false,
|
|
200
|
+
isModal: true,
|
|
201
|
+
pip: false,
|
|
202
|
+
isTablet: true,
|
|
203
|
+
isTabletPortrait: false,
|
|
204
|
+
orientation: "landscape",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "tablet landscape, vertical inline picture in picture",
|
|
208
|
+
vertical: true,
|
|
209
|
+
inline: true,
|
|
210
|
+
isModal: true,
|
|
211
|
+
pip: true,
|
|
212
|
+
isTablet: true,
|
|
213
|
+
isTabletPortrait: false,
|
|
214
|
+
orientation: "landscape",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: "tablet landscape, vertical inline but not a modal",
|
|
218
|
+
vertical: true,
|
|
219
|
+
inline: true,
|
|
220
|
+
isModal: false,
|
|
221
|
+
pip: false,
|
|
222
|
+
isTablet: true,
|
|
223
|
+
isTabletPortrait: false,
|
|
224
|
+
orientation: "landscape",
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
it.each(cases)(
|
|
229
|
+
"$name keeps the legacy aspect-ratio frame",
|
|
230
|
+
({
|
|
231
|
+
vertical,
|
|
232
|
+
inline,
|
|
233
|
+
isModal,
|
|
234
|
+
pip,
|
|
235
|
+
isTablet,
|
|
236
|
+
isTabletPortrait,
|
|
237
|
+
orientation,
|
|
238
|
+
}) => {
|
|
239
|
+
mockIsTablet = isTablet;
|
|
240
|
+
mockOrientation = orientation;
|
|
241
|
+
|
|
242
|
+
const { result } = renderHook(() =>
|
|
243
|
+
useStyle({
|
|
244
|
+
style: { width: 1210, height: 834 },
|
|
245
|
+
inline,
|
|
246
|
+
isModal,
|
|
247
|
+
isTabletPortrait,
|
|
248
|
+
configuration: { tablet_landscape_sidebar_width: "35%" },
|
|
249
|
+
pip,
|
|
250
|
+
vertical,
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(result.current.wrapperStyle).toBeNull();
|
|
255
|
+
|
|
256
|
+
expect(result.current.containerDimensions.aspectRatio).toBeCloseTo(
|
|
257
|
+
legacyAspectRatio({ vertical, inline, isModal, pip, orientation })
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
expect(result.current.childrenStyles.alignSelf).toBeUndefined();
|
|
261
|
+
}
|
|
262
|
+
);
|
|
58
263
|
});
|