@applicaster/zapp-react-native-ui-components 17.0.0-rc.3 → 17.0.0-rc.5
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/PlayerContainer/PlayerContainer.tsx +2 -6
- 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
|
@@ -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
|
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getEdges,
|
|
3
|
+
getPlayerLayout,
|
|
4
|
+
getVerticalColumnWidth,
|
|
5
|
+
} from "../playerWrapperUtils";
|
|
2
6
|
|
|
3
7
|
describe("getEdges", () => {
|
|
4
8
|
it("keeps the top edge in fullscreen when not vertical", () => {
|
|
@@ -14,3 +18,108 @@ describe("getEdges", () => {
|
|
|
14
18
|
expect(getEdges(false, true, true)).toEqual(["top"]);
|
|
15
19
|
});
|
|
16
20
|
});
|
|
21
|
+
|
|
22
|
+
describe("getVerticalColumnWidth", () => {
|
|
23
|
+
it("splits the frame by the configured percentage", () => {
|
|
24
|
+
expect(getVerticalColumnWidth(1000, "25%")).toBeCloseTo(750);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("subtracts a fixed sidebar", () => {
|
|
28
|
+
expect(getVerticalColumnWidth(1000, "300")).toBeCloseTo(700);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("falls back to the default split without a sidebar", () => {
|
|
32
|
+
expect(getVerticalColumnWidth(1000, undefined)).toBeCloseTo(650);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("falls back to the default split for a malformed sidebar", () => {
|
|
36
|
+
expect(getVerticalColumnWidth(1000, "abc")).toBeCloseTo(650);
|
|
37
|
+
expect(getVerticalColumnWidth(1000, "abc%")).toBeCloseTo(650);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("never leaves a negative column for a sidebar wider than the frame", () => {
|
|
41
|
+
expect(getVerticalColumnWidth(1000, "120%")).toBeCloseTo(650);
|
|
42
|
+
expect(getVerticalColumnWidth(1000, "1200")).toBeCloseTo(650);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("has no column before the frame is known", () => {
|
|
46
|
+
expect(getVerticalColumnWidth(0, "35%")).toBe(0);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("getPlayerLayout", () => {
|
|
51
|
+
const baseDimensions = { width: 786.5, height: undefined };
|
|
52
|
+
|
|
53
|
+
it("keeps the aspect-ratio frame when the tablet vertical layout does not apply", () => {
|
|
54
|
+
expect(
|
|
55
|
+
getPlayerLayout({
|
|
56
|
+
baseDimensions,
|
|
57
|
+
aspectRatio: 16 / 9,
|
|
58
|
+
verticalInlineTablet: false,
|
|
59
|
+
frameWidth: 1210,
|
|
60
|
+
frameHeight: 834,
|
|
61
|
+
sidebarWidth: "35%",
|
|
62
|
+
topInset: 24,
|
|
63
|
+
bottomInset: 20,
|
|
64
|
+
})
|
|
65
|
+
).toEqual({
|
|
66
|
+
containerDimensions: {
|
|
67
|
+
width: 786.5,
|
|
68
|
+
height: undefined,
|
|
69
|
+
aspectRatio: 16 / 9,
|
|
70
|
+
},
|
|
71
|
+
playerDimensions: {
|
|
72
|
+
width: 786.5,
|
|
73
|
+
height: undefined,
|
|
74
|
+
aspectRatio: 16 / 9,
|
|
75
|
+
},
|
|
76
|
+
wrapperStyle: null,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("fills the column height and centers a 9:16 video inside the current width", () => {
|
|
81
|
+
const layout = getPlayerLayout({
|
|
82
|
+
baseDimensions,
|
|
83
|
+
aspectRatio: 9 / 16,
|
|
84
|
+
verticalInlineTablet: true,
|
|
85
|
+
frameWidth: 1210,
|
|
86
|
+
frameHeight: 834,
|
|
87
|
+
sidebarWidth: "35%",
|
|
88
|
+
topInset: 24,
|
|
89
|
+
bottomInset: 20,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const videoHeight = 834 - 24 - 20;
|
|
93
|
+
|
|
94
|
+
expect(layout.wrapperStyle).toEqual({
|
|
95
|
+
width: 786.5,
|
|
96
|
+
height: 834,
|
|
97
|
+
paddingBottom: 20,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(layout.playerDimensions).toEqual({
|
|
101
|
+
width: videoHeight * (9 / 16),
|
|
102
|
+
height: videoHeight,
|
|
103
|
+
alignSelf: "center",
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("does not grow wider than the player column", () => {
|
|
108
|
+
const layout = getPlayerLayout({
|
|
109
|
+
baseDimensions: { width: 300, height: undefined },
|
|
110
|
+
aspectRatio: 9 / 16,
|
|
111
|
+
verticalInlineTablet: true,
|
|
112
|
+
frameWidth: 300,
|
|
113
|
+
frameHeight: 834,
|
|
114
|
+
sidebarWidth: "0%",
|
|
115
|
+
topInset: 0,
|
|
116
|
+
bottomInset: 0,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(layout.playerDimensions.width).toBe(300);
|
|
120
|
+
expect(layout.playerDimensions.height).toBeCloseTo(300 * (16 / 9));
|
|
121
|
+
expect(layout.playerDimensions.marginTop).toBe("auto");
|
|
122
|
+
expect(layout.playerDimensions.marginBottom).toBe("auto");
|
|
123
|
+
expect(layout.wrapperStyle).toMatchObject({ width: 300 });
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { StyleSheet, ViewStyle } from "react-native";
|
|
3
|
+
import {
|
|
4
|
+
useSafeAreaFrame,
|
|
5
|
+
useSafeAreaInsets,
|
|
6
|
+
} from "react-native-safe-area-context";
|
|
3
7
|
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
4
8
|
import {
|
|
5
9
|
useIsTablet,
|
|
@@ -10,8 +14,7 @@ import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils
|
|
|
10
14
|
import {
|
|
11
15
|
getBaseDimensions,
|
|
12
16
|
calculateAspectRatio,
|
|
13
|
-
|
|
14
|
-
getContainerDimensions,
|
|
17
|
+
getPlayerLayout,
|
|
15
18
|
} from "./playerWrapperUtils";
|
|
16
19
|
|
|
17
20
|
export const defaultStyles = StyleSheet.create({
|
|
@@ -34,6 +37,9 @@ export const useStyle = ({
|
|
|
34
37
|
|
|
35
38
|
const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
|
|
36
39
|
|
|
40
|
+
const frame = useSafeAreaFrame();
|
|
41
|
+
const insets = useSafeAreaInsets();
|
|
42
|
+
|
|
37
43
|
const tabletWidth = getTabletWidth(
|
|
38
44
|
configuration.tablet_landscape_sidebar_width,
|
|
39
45
|
style
|
|
@@ -64,25 +70,40 @@ export const useStyle = ({
|
|
|
64
70
|
[isInlineModal, pip, vertical, isLandscape]
|
|
65
71
|
);
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
baseDimensions,
|
|
70
|
-
aspectRatio
|
|
71
|
-
);
|
|
73
|
+
const verticalInlineTablet =
|
|
74
|
+
vertical && isInlineModal && isTabletLandscape && !pip;
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
return React.useMemo(() => {
|
|
77
|
+
const { containerDimensions, playerDimensions, wrapperStyle } =
|
|
78
|
+
getPlayerLayout({
|
|
79
|
+
baseDimensions,
|
|
80
|
+
aspectRatio,
|
|
81
|
+
verticalInlineTablet,
|
|
82
|
+
frameWidth: frame.width,
|
|
83
|
+
frameHeight: frame.height,
|
|
84
|
+
sidebarWidth: configuration.tablet_landscape_sidebar_width,
|
|
85
|
+
topInset: insets.top,
|
|
86
|
+
bottomInset: insets.bottom,
|
|
87
|
+
});
|
|
77
88
|
|
|
78
|
-
|
|
79
|
-
...
|
|
80
|
-
|
|
89
|
+
return {
|
|
90
|
+
...StyleSheet.create({
|
|
91
|
+
containerDimensions,
|
|
92
|
+
childrenStyles: {
|
|
93
|
+
...playerDimensions,
|
|
94
|
+
...playerDimensionsHack,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
wrapperStyle,
|
|
81
98
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
}, [
|
|
100
|
+
baseDimensions,
|
|
101
|
+
aspectRatio,
|
|
102
|
+
verticalInlineTablet,
|
|
103
|
+
configuration.tablet_landscape_sidebar_width,
|
|
104
|
+
frame.width,
|
|
105
|
+
frame.height,
|
|
106
|
+
insets.top,
|
|
107
|
+
insets.bottom,
|
|
108
|
+
]);
|
|
88
109
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Dimensions, DimensionValue, Platform, ViewStyle } from "react-native";
|
|
2
2
|
import { Edge } from "react-native-safe-area-context";
|
|
3
|
+
import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
|
|
3
4
|
|
|
4
5
|
export type DimensionsT = {
|
|
5
6
|
width: number | string;
|
|
@@ -13,6 +14,43 @@ export type Configuration = {
|
|
|
13
14
|
tablet_landscape_player_container_background_color?: string;
|
|
14
15
|
};
|
|
15
16
|
|
|
17
|
+
export type PlayerLayout = {
|
|
18
|
+
containerDimensions: ViewStyle;
|
|
19
|
+
playerDimensions: ViewStyle;
|
|
20
|
+
wrapperStyle: ViewStyle | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const VERTICAL_VIDEO_ASPECT_RATIO = 9 / 16;
|
|
24
|
+
|
|
25
|
+
const DEFAULT_PLAYER_COLUMN_RATIO = 0.65;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Player column width for the given frame, using the same split as the rest of
|
|
29
|
+
* the tablet landscape layout. `getTabletWidth` resolves percentages against
|
|
30
|
+
* `Dimensions.get("screen")`, which is the whole device in split view and lags
|
|
31
|
+
* a rotation on Android, so it is fed the live frame instead.
|
|
32
|
+
*/
|
|
33
|
+
export const getVerticalColumnWidth = (
|
|
34
|
+
frameWidth: number,
|
|
35
|
+
sidebarWidth?: string
|
|
36
|
+
): number => {
|
|
37
|
+
if (!(frameWidth > 0)) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const columnWidth = getTabletWidth(sidebarWidth, {
|
|
42
|
+
width: frameWidth,
|
|
43
|
+
height: undefined,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// A malformed sidebar width yields NaN or a negative column.
|
|
47
|
+
if (!(columnWidth > 0)) {
|
|
48
|
+
return frameWidth * DEFAULT_PLAYER_COLUMN_RATIO;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Math.min(columnWidth, frameWidth);
|
|
52
|
+
};
|
|
53
|
+
|
|
16
54
|
// This is safe, remembering screen dimensions once as they do not change during runtime
|
|
17
55
|
// TODO: consider sharing screen orientation as a shared function for the app
|
|
18
56
|
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
|
|
@@ -95,3 +133,99 @@ export const getContainerDimensions = (
|
|
|
95
133
|
...baseDimensions,
|
|
96
134
|
aspectRatio,
|
|
97
135
|
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Tablet landscape inline. Column widths stay put. The 9:16 video fills the
|
|
139
|
+
* height and is centered; controls use the full column.
|
|
140
|
+
*/
|
|
141
|
+
const getTabletVerticalInlineLayout = ({
|
|
142
|
+
columnWidth,
|
|
143
|
+
frameHeight,
|
|
144
|
+
topInset,
|
|
145
|
+
bottomInset,
|
|
146
|
+
}: {
|
|
147
|
+
columnWidth: number;
|
|
148
|
+
frameHeight: number;
|
|
149
|
+
topInset: number;
|
|
150
|
+
bottomInset: number;
|
|
151
|
+
}): PlayerLayout | null => {
|
|
152
|
+
const availableHeight = frameHeight - topInset - bottomInset;
|
|
153
|
+
|
|
154
|
+
if (!(columnWidth > 0) || !(availableHeight > 0)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const videoWidth = Math.min(
|
|
159
|
+
columnWidth,
|
|
160
|
+
availableHeight * VERTICAL_VIDEO_ASPECT_RATIO
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const videoHeight = videoWidth / VERTICAL_VIDEO_ASPECT_RATIO;
|
|
164
|
+
|
|
165
|
+
// alignSelf only centers horizontally. A column narrower than a full-height
|
|
166
|
+
// 9:16 frame (common on Android tablets) leaves empty space below the video.
|
|
167
|
+
const verticalMargins =
|
|
168
|
+
videoHeight < availableHeight
|
|
169
|
+
? { marginTop: "auto" as const, marginBottom: "auto" as const }
|
|
170
|
+
: null;
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
wrapperStyle: {
|
|
174
|
+
width: columnWidth,
|
|
175
|
+
height: frameHeight,
|
|
176
|
+
paddingBottom: bottomInset,
|
|
177
|
+
},
|
|
178
|
+
containerDimensions: {
|
|
179
|
+
flex: 1,
|
|
180
|
+
width: "100%",
|
|
181
|
+
alignSelf: "stretch",
|
|
182
|
+
},
|
|
183
|
+
playerDimensions: {
|
|
184
|
+
width: videoWidth,
|
|
185
|
+
height: videoHeight,
|
|
186
|
+
alignSelf: "center",
|
|
187
|
+
...verticalMargins,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const getPlayerLayout = ({
|
|
193
|
+
baseDimensions,
|
|
194
|
+
aspectRatio,
|
|
195
|
+
verticalInlineTablet,
|
|
196
|
+
frameWidth,
|
|
197
|
+
frameHeight,
|
|
198
|
+
sidebarWidth,
|
|
199
|
+
topInset,
|
|
200
|
+
bottomInset,
|
|
201
|
+
}: {
|
|
202
|
+
baseDimensions: ViewStyle;
|
|
203
|
+
aspectRatio: number;
|
|
204
|
+
verticalInlineTablet: boolean;
|
|
205
|
+
frameWidth: number;
|
|
206
|
+
frameHeight: number;
|
|
207
|
+
sidebarWidth?: string;
|
|
208
|
+
topInset: number;
|
|
209
|
+
bottomInset: number;
|
|
210
|
+
}): PlayerLayout => {
|
|
211
|
+
const columnWidth = getVerticalColumnWidth(frameWidth, sidebarWidth);
|
|
212
|
+
|
|
213
|
+
if (verticalInlineTablet && columnWidth > 0) {
|
|
214
|
+
const layout = getTabletVerticalInlineLayout({
|
|
215
|
+
columnWidth,
|
|
216
|
+
frameHeight,
|
|
217
|
+
topInset,
|
|
218
|
+
bottomInset,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
if (layout) {
|
|
222
|
+
return layout;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
containerDimensions: getContainerDimensions(baseDimensions, aspectRatio),
|
|
228
|
+
playerDimensions: getPlayerDimensions(baseDimensions, aspectRatio),
|
|
229
|
+
wrapperStyle: null,
|
|
230
|
+
};
|
|
231
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Web builds resolve `*.web.*` files first. Each web variant must export what its
|
|
2
|
+
// platformSelect module picks on every web platform, without importing the native
|
|
3
|
+
// implementations.
|
|
4
|
+
|
|
5
|
+
jest.mock(
|
|
6
|
+
"@applicaster/zapp-react-native-ui-components/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions",
|
|
7
|
+
() => ({ withDimensionsHOC: (Component) => Component })
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
const UI = "@applicaster/zapp-react-native-ui-components/Components";
|
|
11
|
+
const TVOS_UI = "@applicaster/zapp-react-native-tvos-ui-components/Components";
|
|
12
|
+
|
|
13
|
+
const SWITCHES = [
|
|
14
|
+
[`${UI}/River/ComponentsMap/index`, "ComponentsMap"],
|
|
15
|
+
[`${UI}/Cell/PlatformCellComponent`, "PlatformCellComponent"],
|
|
16
|
+
[`${UI}/Focusable/index`, "Focusable"],
|
|
17
|
+
[`${UI}/Tabs/TV/index`, "Tabs"],
|
|
18
|
+
[`${UI}/Tabs/TV/index`, "TabContent"],
|
|
19
|
+
[`${UI}/MasterCell/DefaultComponents/Image/index`, "default"],
|
|
20
|
+
[`${TVOS_UI}/TVEventHandlerComponent/index`, "TVEventHandlerComponent"],
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const COMPONENT_TYPES = [
|
|
24
|
+
"hero",
|
|
25
|
+
"screen_picker",
|
|
26
|
+
"grid",
|
|
27
|
+
"horizontal_list",
|
|
28
|
+
"gallery-qb",
|
|
29
|
+
"unknown",
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
describe.each(["web", "samsung_tv", "lg_tv"])("on %s", (platform) => {
|
|
33
|
+
it.each(SWITCHES)("%s.web exports the selected %s", (path, name) => {
|
|
34
|
+
jest.isolateModules(() => {
|
|
35
|
+
require("react-native").Platform.OS = platform;
|
|
36
|
+
|
|
37
|
+
const selected = require(path)[name];
|
|
38
|
+
|
|
39
|
+
expect(selected).toBeDefined();
|
|
40
|
+
expect(require(`${path}.web`)[name]).toBe(selected);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("AudioPlayer.web renders the same player as AudioPlayer", () => {
|
|
45
|
+
jest.isolateModules(() => {
|
|
46
|
+
require("react-native").Platform.OS = platform;
|
|
47
|
+
|
|
48
|
+
const props = { entry: { id: "a" } };
|
|
49
|
+
const selected = require(`${UI}/AudioPlayer/index`).AudioPlayer(props);
|
|
50
|
+
const web = require(`${UI}/AudioPlayer/index.web`).AudioPlayer(props);
|
|
51
|
+
|
|
52
|
+
expect(selected.type).toBe(require(`${UI}/AudioPlayer/tv`).AudioPlayerTV);
|
|
53
|
+
expect(web.type).toBe(selected.type);
|
|
54
|
+
expect(web.props).toEqual(selected.props);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it.each([
|
|
59
|
+
["viewTrees", "viewTreeResolver"],
|
|
60
|
+
["containerStyles", "containerStyleResolver"],
|
|
61
|
+
])("default-cell-renderer %s.web resolves like the original", (dir, name) => {
|
|
62
|
+
jest.isolateModules(() => {
|
|
63
|
+
require("react-native").Platform.OS = platform;
|
|
64
|
+
|
|
65
|
+
const base = require(`${UI}/default-cell-renderer/${dir}/index`)[name];
|
|
66
|
+
const web = require(`${UI}/default-cell-renderer/${dir}/index.web`)[name];
|
|
67
|
+
|
|
68
|
+
COMPONENT_TYPES.forEach((component_type) => {
|
|
69
|
+
expect(web({ component_type })).toEqual(base({ component_type }));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { containerStyleResolver as tvResolver } from "./tv";
|
|
2
|
+
|
|
3
|
+
// Web platforms (web, samsung_tv, lg_tv) always use the TV resolver, so web builds leave the mobile one out.
|
|
4
|
+
export function containerStyleResolver({ component_type }) {
|
|
5
|
+
return tvResolver({ component_type });
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { viewTreeResolver as tvResolver } from "./tv";
|
|
2
|
+
|
|
3
|
+
// Web platforms (web, samsung_tv, lg_tv) always use the TV resolver, so web builds leave the mobile one out.
|
|
4
|
+
export function viewTreeResolver({
|
|
5
|
+
component_type,
|
|
6
|
+
}: {
|
|
7
|
+
component_type: string;
|
|
8
|
+
}) {
|
|
9
|
+
return tvResolver({ component_type });
|
|
10
|
+
}
|