@applicaster/quick-brick-player 13.0.5 → 13.0.6-alpha.4390983410

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.
@@ -0,0 +1,237 @@
1
+ import React, { useRef, ReactElement } from "react";
2
+
3
+ import { StyleSheet, Animated, Pressable, ViewStyle } from "react-native";
4
+ import { PanGestureHandler } from "react-native-gesture-handler";
5
+ import { useStyles } from "./styles";
6
+ import { useConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
7
+ import { useVideoModalState } from "./hooks";
8
+ import {
9
+ DEFAULT_IMAGE_RATIO_VIDEO,
10
+ MODAL_COLLAPSE_START,
11
+ MODAL_RADIUS,
12
+ SCREEN_HEIGHT,
13
+ SCREEN_WIDTH,
14
+ VIDEO_TRANSITION_THRESHOLD,
15
+ } from "./consts";
16
+ import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
17
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
18
+ import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/useModalAnimationContext";
19
+ import { PROGRESS_BAR_HEIGHT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/utils";
20
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
21
+ import { GestureAnimatedScrollView } from "./GestureAnimatedScrollView";
22
+
23
+ const orientationStyles = StyleSheet.create({
24
+ landscape: { flexDirection: "row" },
25
+ portrait: { flexDirection: "column" },
26
+ });
27
+
28
+ const directionStyles = (isLandscape: boolean): ViewStyle => {
29
+ return isLandscape ? orientationStyles.landscape : orientationStyles.portrait;
30
+ };
31
+
32
+ type AnimatedModalProps = {
33
+ enabled?: boolean;
34
+ pip?: boolean;
35
+ content?: (
36
+ opacity: Animated.Value | Animated.AnimatedInterpolation
37
+ ) => ReactElement;
38
+ collapsedContent?: (
39
+ opacity: Animated.Value | Animated.AnimatedInterpolation
40
+ ) => ReactElement;
41
+ extraContent?: (
42
+ opacity: Animated.Value | Animated.AnimatedInterpolation
43
+ ) => ReactElement;
44
+ aspectRatio?: number;
45
+ isTabletPortrait?: boolean;
46
+ style?: {
47
+ tabletLandscapeWidth?: number;
48
+ width?: number;
49
+ height?: number;
50
+ };
51
+ };
52
+
53
+ const height = SCREEN_HEIGHT;
54
+
55
+ export function VideoPlayerModal({
56
+ enabled = true,
57
+ aspectRatio = DEFAULT_IMAGE_RATIO_VIDEO,
58
+ content,
59
+ extraContent,
60
+ collapsedContent,
61
+ isTabletPortrait,
62
+ style,
63
+ pip = false,
64
+ }: AnimatedModalProps) {
65
+ const isTablet = useIsTablet();
66
+
67
+ let width = SCREEN_WIDTH;
68
+
69
+ if (isTablet && !isTabletPortrait) {
70
+ width = style?.tabletLandscapeWidth || width;
71
+ }
72
+
73
+ const { minimised_height: minimisedHeight } = useConfiguration();
74
+ const scrollViewRef = useRef<typeof Animated.ScrollView | null>(null);
75
+
76
+ const translateYRef = useModalAnimationContext().yTranslate;
77
+
78
+ const {
79
+ translateY,
80
+ collapsed,
81
+ collapsedHeight,
82
+ gestureHandlerProps,
83
+ expand,
84
+ } = useVideoModalState(translateYRef);
85
+
86
+ const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
87
+
88
+ const styles = useStyles({ height: collapsedHeight });
89
+
90
+ const SCALE_FACTOR = 1 / (width / aspectRatio / minimisedHeight); // Scale factor for expanded content
91
+
92
+ const insets = useSafeAreaInsets();
93
+
94
+ // Interpolated opacities for smooth cross-fade
95
+ const collapsedOpacity = translateY.interpolate({
96
+ inputRange: [MODAL_COLLAPSE_START, height - collapsedHeight],
97
+ outputRange: [0, 1],
98
+ extrapolate: "clamp",
99
+ });
100
+
101
+ const expandedOpacity = translateY.interpolate({
102
+ inputRange: [0, height - collapsedHeight],
103
+ outputRange: [1, 0],
104
+ extrapolate: "clamp",
105
+ });
106
+
107
+ const xPosition = translateY.interpolate({
108
+ inputRange: [height * VIDEO_TRANSITION_THRESHOLD, height - collapsedHeight],
109
+ outputRange: [0, -(width - width * SCALE_FACTOR) / 2],
110
+ extrapolate: "clamp",
111
+ });
112
+
113
+ const vidHeight = width / aspectRatio;
114
+
115
+ const yPosition = translateY.interpolate({
116
+ inputRange: [height * VIDEO_TRANSITION_THRESHOLD, height - collapsedHeight],
117
+ outputRange: [
118
+ 0,
119
+ isTablet && isTabletLandscape
120
+ ? -(
121
+ (-PROGRESS_BAR_HEIGHT + SCREEN_HEIGHT - vidHeight * SCALE_FACTOR) /
122
+ 2
123
+ )
124
+ : -(
125
+ PROGRESS_BAR_HEIGHT +
126
+ insets.top / 2 +
127
+ (SCREEN_WIDTH / aspectRatio -
128
+ (SCREEN_WIDTH / aspectRatio) * SCALE_FACTOR) /
129
+ 2
130
+ ),
131
+ ],
132
+ extrapolate: "clamp",
133
+ });
134
+
135
+ const scalePosition = translateY.interpolate({
136
+ inputRange: [
137
+ SCREEN_HEIGHT * VIDEO_TRANSITION_THRESHOLD,
138
+ SCREEN_HEIGHT - collapsedHeight,
139
+ ],
140
+ outputRange: [1, SCALE_FACTOR],
141
+ extrapolate: "clamp",
142
+ });
143
+
144
+ const borderTopRadiusAnimated = translateY.interpolate({
145
+ inputRange: [0, SCREEN_HEIGHT - collapsedHeight],
146
+ outputRange: [MODAL_RADIUS, 0],
147
+ extrapolate: "clamp",
148
+ });
149
+
150
+ if (pip) {
151
+ return content(new Animated.Value(1));
152
+ }
153
+
154
+ return (
155
+ <PanGestureHandler
156
+ enabled={enabled}
157
+ waitFor={scrollViewRef}
158
+ {...gestureHandlerProps}
159
+ >
160
+ <Animated.View
161
+ pointerEvents={"auto"}
162
+ style={[
163
+ styles.modalWrapper,
164
+ {
165
+ borderTopLeftRadius: borderTopRadiusAnimated,
166
+ borderTopRightRadius: borderTopRadiusAnimated,
167
+ transform: [{ translateY }],
168
+ height: SCREEN_HEIGHT,
169
+ },
170
+ ]}
171
+ >
172
+ <Animated.View
173
+ pointerEvents={"auto"}
174
+ style={[
175
+ styles.modal,
176
+ collapsed ? styles.collapsedModalBg : null,
177
+ {
178
+ borderTopLeftRadius: borderTopRadiusAnimated,
179
+ borderTopRightRadius: borderTopRadiusAnimated,
180
+ height: SCREEN_HEIGHT,
181
+ },
182
+ ]}
183
+ >
184
+ <Animated.View
185
+ pointerEvents={!collapsed ? "auto" : "none"}
186
+ style={[styles.modalContent, directionStyles(isTabletLandscape)]}
187
+ >
188
+ <Animated.View
189
+ style={[
190
+ styles.expandedContentContainer,
191
+ {
192
+ transform: [
193
+ { translateX: xPosition },
194
+ { translateY: yPosition },
195
+ { scale: scalePosition },
196
+ ],
197
+ },
198
+ ]}
199
+ >
200
+ {content(expandedOpacity)}
201
+ </Animated.View>
202
+ {extraContent ? (
203
+ <GestureAnimatedScrollView
204
+ ref={scrollViewRef}
205
+ contentContainerStyle={{
206
+ paddingBottom: insets.bottom,
207
+ }}
208
+ style={[
209
+ styles.extraContentScrollView,
210
+ { opacity: expandedOpacity },
211
+ ]}
212
+ >
213
+ {extraContent ? extraContent(expandedOpacity) : null}
214
+ </GestureAnimatedScrollView>
215
+ ) : null}
216
+ </Animated.View>
217
+
218
+ <Animated.View
219
+ pointerEvents={collapsed ? "box-none" : "none"}
220
+ style={[
221
+ styles.collapsedBarContainer,
222
+ { opacity: collapsedOpacity },
223
+ ]}
224
+ >
225
+ <Pressable
226
+ testID="collapsedBarWrapper"
227
+ onPress={expand}
228
+ style={styles.collapsedBarWrapper}
229
+ >
230
+ {collapsedContent}
231
+ </Pressable>
232
+ </Animated.View>
233
+ </Animated.View>
234
+ </Animated.View>
235
+ </PanGestureHandler>
236
+ );
237
+ }
@@ -0,0 +1,34 @@
1
+ import { isAndroidTablet } from "@applicaster/zapp-react-native-utils/reactHooks/layout/isTablet";
2
+ import {
3
+ isAndroidPlatform,
4
+ isAndroidVersionAtLeast,
5
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
6
+ import { Dimensions, StatusBar } from "react-native";
7
+
8
+ export const DOCKED_PROGRESSBAR_HEIGHT = 3; // Height of the docked progress bar plugins/mobile-transport-controls/src/ProgressBar/layouts/DockedLayout.tsx
9
+
10
+ export const VIDEO_TRANSITION_THRESHOLD = 0.5; // Threshold for video transition
11
+
12
+ const windowDimensions = Dimensions.get("window");
13
+
14
+ const isOldAndroidDevice =
15
+ isAndroidPlatform() && !isAndroidVersionAtLeast(35) && !isAndroidTablet();
16
+
17
+ export const SCREEN_WIDTH = windowDimensions.width;
18
+
19
+ export const SCREEN_HEIGHT =
20
+ windowDimensions.height + (isOldAndroidDevice ? StatusBar.currentHeight : 0);
21
+
22
+ export const MODAL_COLLAPSE_START = SCREEN_HEIGHT * 0.7; // 70% of screen height
23
+
24
+ export const DRAG_TO_COLLAPSE = 0.02; // 2% to collapse
25
+
26
+ export const DRAG_TO_EXPAND = 0.02; // 2% to expand
27
+
28
+ export const DEFAULT_IMAGE_RATIO_VIDEO = 16 / 9; // Default aspect ratio for video
29
+
30
+ export const DEFAULT_IMAGE_RATIO_AUDIO = 1; // Default aspect ratio for audio
31
+
32
+ export const ANIMATION_DURATION = 250; // Default animation duration in milliseconds
33
+
34
+ export const MODAL_RADIUS = 16; // Default border radius for modal
@@ -0,0 +1,161 @@
1
+ import { VideoModalMode } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainer";
2
+ import { useConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
3
+ import { getTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/getTabBarHeight";
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
5
+ import { useCallback, useEffect, useMemo, useRef } from "react";
6
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
7
+ import {
8
+ ANIMATION_DURATION,
9
+ DRAG_TO_COLLAPSE,
10
+ DRAG_TO_EXPAND,
11
+ SCREEN_HEIGHT,
12
+ } from "../consts";
13
+ import { State } from "react-native-gesture-handler";
14
+ import { Animated } from "react-native";
15
+ import { PROGRESS_BAR_HEIGHT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/utils";
16
+
17
+ const bottomTabBarHeight = getTabBarHeight();
18
+
19
+ export const useVideoModalState = (
20
+ translateYRef: React.MutableRefObject<Animated.Value>
21
+ ) => {
22
+ const { minimised_height: minimisedHeight } = useConfiguration();
23
+
24
+ const { maximiseVideoModal, minimiseVideoModal, videoModalState } =
25
+ useNavigation();
26
+
27
+ const collapsed = videoModalState.mode === VideoModalMode.MINIMIZED;
28
+
29
+ const { bottom } = useSafeAreaInsets();
30
+
31
+ const collapsedHeight =
32
+ minimisedHeight + bottom + bottomTabBarHeight + PROGRESS_BAR_HEIGHT;
33
+
34
+ const translateY = translateYRef.current;
35
+
36
+ const handleExpand = useCallback(
37
+ (toValue: number) => {
38
+ return Animated.timing(translateYRef.current, {
39
+ toValue,
40
+ duration: ANIMATION_DURATION,
41
+ useNativeDriver: true,
42
+ });
43
+ },
44
+ [translateYRef]
45
+ );
46
+
47
+ const handleCollapse = useCallback(
48
+ (toValue: number) => {
49
+ return Animated.timing(translateYRef.current, {
50
+ toValue,
51
+ duration: ANIMATION_DURATION,
52
+ useNativeDriver: true,
53
+ });
54
+ },
55
+ [translateYRef]
56
+ );
57
+
58
+ const offset = useRef(SCREEN_HEIGHT - collapsedHeight);
59
+
60
+ // Gesture handler for modal
61
+ const onGestureEvent = (event: any) => {
62
+ if (event.nativeEvent.state === State.ACTIVE) {
63
+ const y = event.nativeEvent.translationY;
64
+ let newY = offset.current + y;
65
+ if (newY < 0) newY = 0;
66
+
67
+ if (newY > SCREEN_HEIGHT - collapsedHeight) {
68
+ newY = SCREEN_HEIGHT - collapsedHeight;
69
+ }
70
+
71
+ translateY.setValue(newY);
72
+ }
73
+ };
74
+
75
+ const onHandlerStateChange = (event: any) => {
76
+ if (event.nativeEvent.oldState === State.ACTIVE) {
77
+ const { translationY } = event.nativeEvent;
78
+ let newY = offset.current + translationY;
79
+ if (newY < 0) newY = 0;
80
+
81
+ if (newY > SCREEN_HEIGHT - collapsedHeight) {
82
+ newY = SCREEN_HEIGHT - collapsedHeight;
83
+ }
84
+
85
+ const shouldCollapse =
86
+ translationY > (SCREEN_HEIGHT - collapsedHeight) * DRAG_TO_COLLAPSE;
87
+
88
+ const shouldExpand =
89
+ translationY < -(SCREEN_HEIGHT - collapsedHeight) * DRAG_TO_EXPAND;
90
+
91
+ if (!collapsed && shouldCollapse) {
92
+ // Collapse
93
+ Animated.timing(translateY, {
94
+ toValue: SCREEN_HEIGHT - collapsedHeight,
95
+ duration: ANIMATION_DURATION,
96
+ useNativeDriver: true,
97
+ }).start(() => {
98
+ minimiseVideoModal();
99
+ offset.current = SCREEN_HEIGHT - collapsedHeight;
100
+ });
101
+ } else if (collapsed && shouldExpand) {
102
+ // Expand
103
+ Animated.timing(translateY, {
104
+ toValue: 0,
105
+ duration: ANIMATION_DURATION,
106
+ useNativeDriver: true,
107
+ }).start(() => {
108
+ maximiseVideoModal();
109
+ offset.current = 0;
110
+ translateY.setValue(0);
111
+ });
112
+ } else {
113
+ // Snap back to current state
114
+ Animated.spring(translateY, {
115
+ toValue: collapsed ? SCREEN_HEIGHT - collapsedHeight : 0,
116
+ useNativeDriver: true,
117
+ }).start(() => {
118
+ offset.current = collapsed ? SCREEN_HEIGHT - collapsedHeight : 0;
119
+ translateY.setValue(offset.current);
120
+ });
121
+ }
122
+ } else if (event.nativeEvent.state === State.BEGAN) {
123
+ // Gesture started, set offset
124
+ translateY.stopAnimation((value: number) => {
125
+ offset.current = value;
126
+ });
127
+ }
128
+ };
129
+
130
+ const gestureHandlerProps = useMemo(() => {
131
+ return {
132
+ onGestureEvent,
133
+ onHandlerStateChange,
134
+ };
135
+ }, [onGestureEvent, onHandlerStateChange]);
136
+
137
+ useEffect(() => {
138
+ if (videoModalState.mode === VideoModalMode.MAXIMIZED) {
139
+ handleExpand(0).start(() => {
140
+ maximiseVideoModal();
141
+ offset.current = 0;
142
+ translateY.setValue(0);
143
+ });
144
+ } else if (videoModalState.mode === VideoModalMode.MINIMIZED) {
145
+ handleCollapse(SCREEN_HEIGHT - collapsedHeight).start(() => {
146
+ minimiseVideoModal();
147
+ offset.current = SCREEN_HEIGHT - collapsedHeight;
148
+ translateY.setValue(SCREEN_HEIGHT - collapsedHeight);
149
+ });
150
+ }
151
+ }, [videoModalState.visible, videoModalState.mode]);
152
+
153
+ return {
154
+ collapsed,
155
+ collapsedHeight,
156
+ offset,
157
+ gestureHandlerProps,
158
+ translateY,
159
+ expand: maximiseVideoModal,
160
+ };
161
+ };
@@ -0,0 +1,3 @@
1
+ export { AnimatedModal as default } from "./PlayerModal";
2
+
3
+ export { VideoPlayerModal } from "./VideoPlayerModal";
@@ -0,0 +1,101 @@
1
+ import { useConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
2
+ import {
3
+ useIsTablet,
4
+ useNavigation,
5
+ } from "@applicaster/zapp-react-native-utils/reactHooks";
6
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
7
+ import { useMemo } from "react";
8
+ import { StyleSheet } from "react-native";
9
+
10
+ export const useBackgroundColor = (): string => {
11
+ const {
12
+ modal_background_color: modalBackgroundColor,
13
+ tablet_landscape_player_container_background_color: tabletBackgroundColor,
14
+ } = useConfiguration();
15
+
16
+ const {
17
+ videoModalState: { mode },
18
+ } = useNavigation();
19
+
20
+ const isTablet = useIsTablet();
21
+
22
+ const theme = useTheme<BaseThemePropertiesMobile>();
23
+ const isFullscreen = mode === "FULLSCREEN";
24
+
25
+ /**
26
+ * For the new audio player, the background color setting work that way
27
+ * Layer 0 - modal_background_color
28
+ * Layer 1 - screen_background_color ( can be combined with layer 0 ), If the parameter is not set, it will be a solid black.
29
+ * audio_player_background_color is used only in the old player when the background image is not set
30
+ * modal_background_color is used as the background for player details, and in useBackgroundColor to set a background for a video modal.
31
+ * If it’s not set, theme?.status_background_color will be used instead
32
+ *
33
+ * This hook cover only case with layer 0: modal_background_color, layer 1: screen_background_color is used in the styles.expandedContentContainer
34
+ *
35
+ * For the video player, inline player will use tablet_landscape_player_container_background_color as background color, and transparent for fullscreen.
36
+ * Mobile player will use
37
+ * modal_background_color as background color.
38
+ */
39
+
40
+ return isTablet
41
+ ? !isFullscreen
42
+ ? tabletBackgroundColor
43
+ : "transparent"
44
+ : modalBackgroundColor || theme?.status_background_color;
45
+ };
46
+
47
+ export const useStyles = ({ height }: { height: number }) => {
48
+ const COLLAPSED_HEIGHT = height;
49
+
50
+ const backgroundColor = useBackgroundColor();
51
+
52
+ const BG_COLOR_DEFAULT_BLACK = "black";
53
+ const BG_COLOR_DEFAULT_TRANSPARENT = "transparent";
54
+
55
+ const styles = StyleSheet.create({
56
+ modal: {
57
+ position: "absolute",
58
+ left: 0,
59
+ right: 0,
60
+ top: 0,
61
+ backgroundColor,
62
+ elevation: 10,
63
+ zIndex: 100,
64
+ overflow: "hidden",
65
+ },
66
+ modalWrapper: {
67
+ backgroundColor: BG_COLOR_DEFAULT_BLACK,
68
+ },
69
+ collapsedModalBg: {
70
+ backgroundColor: BG_COLOR_DEFAULT_BLACK,
71
+ },
72
+ modalContent: {
73
+ flex: 1,
74
+ alignItems: "center",
75
+ },
76
+ expandedContentContainer: {
77
+ justifyContent: "flex-start",
78
+ backgroundColor: BG_COLOR_DEFAULT_TRANSPARENT,
79
+ zIndex: 1,
80
+ flex: 0,
81
+ },
82
+ extraContentScrollView: {
83
+ width: "100%",
84
+ backgroundColor: BG_COLOR_DEFAULT_TRANSPARENT,
85
+ },
86
+ collapsedBarContainer: {
87
+ ...StyleSheet.absoluteFillObject,
88
+ height: COLLAPSED_HEIGHT,
89
+ justifyContent: "flex-end",
90
+ },
91
+ collapsedBarWrapper: {
92
+ flex: 1,
93
+ },
94
+ flexNone: {
95
+ ...StyleSheet.absoluteFillObject,
96
+ flex: -1,
97
+ },
98
+ });
99
+
100
+ return useMemo(() => styles, [styles]);
101
+ };