@applicaster/quick-brick-player 15.0.0-alpha.3441591506 → 15.0.0-alpha.3512356987

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-player",
3
- "version": "15.0.0-alpha.3441591506",
3
+ "version": "15.0.0-alpha.3512356987",
4
4
  "description": "Quick Brick Player",
5
5
  "main": "./src/index.ts",
6
6
  "types": "index.d.ts",
@@ -35,11 +35,11 @@
35
35
  },
36
36
  "homepage": "https://github.com/applicaster/quickbrick#readme",
37
37
  "dependencies": {
38
- "@applicaster/quick-brick-mobile-transport-controls": "15.0.0-alpha.3441591506",
39
- "@applicaster/quick-brick-tv-transport-controls": "15.0.0-alpha.3441591506",
40
- "@applicaster/zapp-react-native-tvos-app": "15.0.0-alpha.3441591506",
41
- "@applicaster/zapp-react-native-ui-components": "15.0.0-alpha.3441591506",
42
- "@applicaster/zapp-react-native-utils": "15.0.0-alpha.3441591506",
38
+ "@applicaster/quick-brick-mobile-transport-controls": "15.0.0-rc.34",
39
+ "@applicaster/quick-brick-tv-transport-controls": "15.0.0-rc.15",
40
+ "@applicaster/zapp-react-native-tvos-app": "15.0.0-alpha.3512356987",
41
+ "@applicaster/zapp-react-native-ui-components": "15.0.0-alpha.3512356987",
42
+ "@applicaster/zapp-react-native-utils": "15.0.0-alpha.3512356987",
43
43
  "query-string": "7.1.3",
44
44
  "shaka-player": "4.3.5",
45
45
  "typeface-montserrat": "^0.0.54",
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { LayoutChangeEvent, View } from "react-native";
2
+ import { Animated, LayoutChangeEvent, View } from "react-native";
3
3
 
4
4
  import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
5
5
  import { toBooleanWithDefaultTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
@@ -8,6 +8,7 @@ import { FlexImage } from "./FlexImage";
8
8
 
9
9
  import { styles } from "./styles";
10
10
  import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
11
+ import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
11
12
 
12
13
  type Props = {
13
14
  entry: ZappEntry;
@@ -29,15 +30,34 @@ export const PlayerImage = (props: Props) => {
29
30
  configuration.audio_player_artwork_border_radius
30
31
  );
31
32
 
33
+ const { yTranslate } = useModalAnimationContext();
34
+
35
+ const isModalExpanded = yTranslate.current.interpolate({
36
+ inputRange: [0, 1], // this should be end with `1` only when it's in initial state ( 0pos), otherwise `0`
37
+ outputRange: [1, 0],
38
+ });
39
+
40
+ // do not use styles.shadow when isModalExpanded is 0
41
+
42
+ const animatedStyle = {
43
+ opacity: isModalExpanded,
44
+ };
45
+
32
46
  return (
33
47
  <View style={styles.alignItemsCenter}>
48
+ {/* Using an Animated.View to apply shadow to the image */}
49
+ <Animated.View
50
+ style={[
51
+ animatedStyle,
52
+ shouldShowShadow ? styles.shadow : undefined,
53
+ { borderRadius },
54
+ ]}
55
+ />
34
56
  <View
35
57
  onLayout={onLayoutImage}
36
- style={[shouldShowShadow ? styles.shadow : undefined, { borderRadius }]}
58
+ style={[styles.defaultImageWrapperView, { borderRadius }]}
37
59
  >
38
- <View style={[styles.defaultImageWrapperView, { borderRadius }]}>
39
- <FlexImage entry={entry} style={styles.backgroundImageContainer} />
40
- </View>
60
+ <FlexImage entry={entry} style={styles.backgroundImageContainer} />
41
61
  </View>
42
62
  </View>
43
63
  );
@@ -23,7 +23,12 @@ export const styles = StyleSheet.create({
23
23
  overflow: "hidden",
24
24
  },
25
25
  shadow: {
26
- borderColor: "transparent",
26
+ zIndex: 0,
27
+ position: "absolute",
28
+ top: 0,
29
+ left: 0,
30
+ right: 0,
31
+ bottom: 0,
27
32
  shadowColor: SHADOW_COLOR,
28
33
  shadowOffset: { width: 0, height: 24 },
29
34
  shadowOpacity: platformSelect({
@@ -5,8 +5,8 @@ import { PanGestureHandler } from "react-native-gesture-handler";
5
5
  import { useStyles } from "./styles";
6
6
  import { useVideoModalState } from "./hooks";
7
7
  import { MODAL_COLLAPSE_RATIO, MODAL_RADIUS } from "./consts";
8
- import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
9
- import { getScreenHeight, getWindowHeight } from "./utils";
8
+ import { getWindowHeight } from "./utils";
9
+ import { useSafeAreaFrame } from "react-native-safe-area-context";
10
10
 
11
11
  type AnimatedModalProps = {
12
12
  content?: ReactElement;
@@ -17,23 +17,18 @@ export function AnimatedModal({
17
17
  content,
18
18
  collapsedContent,
19
19
  }: AnimatedModalProps) {
20
- const translateYRef = useModalAnimationContext().yTranslate;
20
+ const { translateY, collapsed, gestureHandlerProps, expand, offset } =
21
+ useVideoModalState();
21
22
 
22
- const {
23
- translateY,
24
- collapsed,
25
- collapsedHeight,
26
- gestureHandlerProps,
27
- expand,
28
- } = useVideoModalState(translateYRef);
23
+ const frame = useSafeAreaFrame();
24
+ const collapsedHeight = frame.height - offset.current;
29
25
 
30
- const styles = useStyles({ height: collapsedHeight, type: "audio" });
26
+ const height = getWindowHeight();
27
+ const heightAboveMinimised = height - collapsedHeight;
31
28
 
32
- const WINDOW_HEIGHT = getWindowHeight();
33
- const heightAboveMinimised = WINDOW_HEIGHT - collapsedHeight;
34
- const screenHeight = getScreenHeight();
29
+ const styles = useStyles({ height: collapsedHeight, type: "audio" });
35
30
 
36
- const MODAL_COLLAPSE_START = WINDOW_HEIGHT * MODAL_COLLAPSE_RATIO;
31
+ const MODAL_COLLAPSE_START = height * MODAL_COLLAPSE_RATIO;
37
32
 
38
33
  // Interpolated opacities for smooth cross-fade
39
34
  const collapsedOpacity = translateY.interpolate({
@@ -64,7 +59,7 @@ export function AnimatedModal({
64
59
  borderTopLeftRadius: borderTopRadiusAnimated,
65
60
  borderTopRightRadius: borderTopRadiusAnimated,
66
61
  transform: [{ translateY }],
67
- height: screenHeight,
62
+ height: height,
68
63
  },
69
64
  ]}
70
65
  >
@@ -74,7 +69,6 @@ export function AnimatedModal({
74
69
  {
75
70
  borderTopLeftRadius: borderTopRadiusAnimated,
76
71
  borderTopRightRadius: borderTopRadiusAnimated,
77
- height: screenHeight,
78
72
  },
79
73
  ]}
80
74
  >
@@ -1,6 +1,6 @@
1
1
  import React, { ReactElement, useMemo, useRef } from "react";
2
2
 
3
- import { Animated, Pressable, StyleSheet, ViewStyle } from "react-native";
3
+ import { Animated, Pressable } from "react-native";
4
4
  import { PanGestureHandler } from "react-native-gesture-handler";
5
5
  import { useStyles } from "./styles";
6
6
  import { useConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
@@ -12,22 +12,25 @@ import {
12
12
  VIDEO_TRANSITION_THRESHOLD,
13
13
  } from "./consts";
14
14
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
15
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
16
- import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/useModalAnimationContext";
17
15
  import { PROGRESS_BAR_HEIGHT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/utils";
18
- import { useSafeAreaInsets } from "react-native-safe-area-context";
16
+ import {
17
+ SafeAreaView,
18
+ useSafeAreaFrame,
19
+ useSafeAreaInsets,
20
+ } from "react-native-safe-area-context";
19
21
  import { GestureAnimatedScrollView } from "./GestureAnimatedScrollView";
20
22
  import { PlayerDetailsWrapperHeightContext } from "./context";
21
- import { getScreenHeight, getWindowHeight, getWindowWidth } from "./utils";
22
-
23
- const orientationStyles = StyleSheet.create({
24
- landscape: { flexDirection: "row" },
25
- portrait: { flexDirection: "column" },
26
- });
23
+ import {
24
+ getInsetsOffset,
25
+ getWindowHeight,
26
+ getWindowWidth,
27
+ directionStyles,
28
+ getScaledPos,
29
+ getExtraContentPadding,
30
+ } from "./utils";
31
+ import { addOrientationChangeListener } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
27
32
 
28
- const directionStyles = (isLandscape: boolean): ViewStyle => {
29
- return isLandscape ? orientationStyles.landscape : orientationStyles.portrait;
30
- };
33
+ const AnimatedSafeAreaView = Animated.createAnimatedComponent(SafeAreaView);
31
34
 
32
35
  type AnimatedModalProps = {
33
36
  pip?: boolean;
@@ -59,45 +62,61 @@ export function VideoPlayerModal({
59
62
  const enabled = !!modal && !fullscreen;
60
63
  const isTablet = useIsTablet();
61
64
 
62
- const WINDOW_WIDTH = useMemo(() => getWindowWidth(), []); // remember initial width, ignore rotation changes
63
- const height = useMemo(() => getWindowHeight(), []); // remember initial height, ignore rotation changes
64
- const screenHeight = useMemo(() => getScreenHeight(), []); // remember initial height, ignore rotation changes
65
- const MODAL_COLLAPSE_START = height * MODAL_COLLAPSE_RATIO;
65
+ // remember initial width, ignore rotation changes
66
+ const width = useMemo(
67
+ () =>
68
+ isTablet && !isTabletPortrait
69
+ ? style.tabletLandscapeWidth
70
+ : getWindowWidth(isTablet, !isTabletPortrait),
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ []
73
+ );
66
74
 
67
- let width = WINDOW_WIDTH;
75
+ const height = useMemo(
76
+ () => getWindowHeight(isTablet, !isTabletPortrait),
77
+ []
78
+ ); // remember initial height, ignore rotation changes
68
79
 
69
- if (isTablet && !isTabletPortrait) {
70
- width = style?.tabletLandscapeWidth || width;
71
- }
80
+ const MODAL_COLLAPSE_START = height * MODAL_COLLAPSE_RATIO;
72
81
 
73
82
  const { minimised_height: minimisedHeight } = useConfiguration();
74
83
  const scrollViewRef = useRef<typeof Animated.ScrollView | null>(null);
75
84
 
76
- const translateYRef = useModalAnimationContext().yTranslate;
77
- // used when modal is false, should not be used in animation
78
- const dummyRef = useRef(new Animated.Value(0));
85
+ const { translateY, collapsed, gestureHandlerProps, expand, offset } =
86
+ useVideoModalState();
79
87
 
80
- const {
81
- translateY,
82
- collapsed,
83
- collapsedHeight,
84
- gestureHandlerProps,
85
- expand,
86
- } = useVideoModalState(modal ? translateYRef : dummyRef);
88
+ const frame = useSafeAreaFrame();
89
+ const collapsedHeight = frame.height - offset.current;
87
90
 
88
91
  const heightAboveMinimised = height - collapsedHeight;
89
92
 
90
- const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
91
-
92
93
  const styles = useStyles({ height: collapsedHeight });
93
94
 
94
95
  const SCALE_FACTOR = 1 / (width / aspectRatio / minimisedHeight); // Scale factor for expanded content
95
96
 
96
97
  const insets = useSafeAreaInsets();
97
98
 
98
- const isFullScreenOrPIP = fullscreen || pip;
99
+ const [isFullScreenMode, setFullScreenMode] = React.useState(
100
+ fullscreen || pip
101
+ );
102
+
103
+ React.useEffect(() => {
104
+ const listener = addOrientationChangeListener(({ toOrientation }) => {
105
+ /* ignored in collapsed mode non-PiP player */
106
+ if (collapsed && !pip) return;
107
+ setFullScreenMode(!(toOrientation === 1));
108
+ });
109
+
110
+ return () => {
111
+ listener.remove();
112
+ };
113
+ }, [collapsed, pip]);
114
+
115
+ const isFullScreenOrPIP = isFullScreenMode;
116
+
117
+ const vidHeight = width / aspectRatio;
99
118
 
100
- // Interpolated opacities for smooth cross-fade
119
+ // animated opacity for smooth cross-fade of collapsed content
101
120
  const collapsedOpacity = !isFullScreenOrPIP
102
121
  ? translateY.interpolate({
103
122
  inputRange: [MODAL_COLLAPSE_START, heightAboveMinimised],
@@ -106,6 +125,7 @@ export function VideoPlayerModal({
106
125
  })
107
126
  : new Animated.Value(0);
108
127
 
128
+ // animated opacity for extra content
109
129
  const expandedOpacity = !isFullScreenOrPIP
110
130
  ? translateY.interpolate({
111
131
  inputRange: [0, heightAboveMinimised],
@@ -114,6 +134,7 @@ export function VideoPlayerModal({
114
134
  })
115
135
  : new Animated.Value(1);
116
136
 
137
+ // animated x position for video content
117
138
  const xPosition = !isFullScreenOrPIP
118
139
  ? translateY.interpolate({
119
140
  inputRange: [height * VIDEO_TRANSITION_THRESHOLD, MODAL_COLLAPSE_START],
@@ -122,32 +143,23 @@ export function VideoPlayerModal({
122
143
  })
123
144
  : new Animated.Value(0);
124
145
 
125
- const vidHeight = width / aspectRatio;
126
-
146
+ // animated y position for video content
127
147
  const yPosition = !isFullScreenOrPIP
128
148
  ? translateY.interpolate({
129
149
  inputRange: [height * VIDEO_TRANSITION_THRESHOLD, MODAL_COLLAPSE_START],
130
150
  outputRange: [
131
151
  0,
132
- isTablet && isTabletLandscape
133
- ? -(
134
- (-PROGRESS_BAR_HEIGHT +
135
- screenHeight -
136
- vidHeight * SCALE_FACTOR) /
137
- 2
138
- )
139
- : -(
140
- PROGRESS_BAR_HEIGHT +
141
- insets.top / 2 +
142
- (WINDOW_WIDTH / aspectRatio -
143
- (WINDOW_WIDTH / aspectRatio) * SCALE_FACTOR) /
144
- 2
145
- ),
152
+ -(
153
+ PROGRESS_BAR_HEIGHT +
154
+ getInsetsOffset(insets, isTabletPortrait) +
155
+ getScaledPos(height, vidHeight, minimisedHeight, isTabletPortrait)
156
+ ),
146
157
  ],
147
158
  extrapolate: "clamp",
148
159
  })
149
160
  : new Animated.Value(0);
150
161
 
162
+ // animated position for video content
151
163
  const scalePosition = !isFullScreenOrPIP
152
164
  ? translateY.interpolate({
153
165
  inputRange: [height * VIDEO_TRANSITION_THRESHOLD, MODAL_COLLAPSE_START],
@@ -158,7 +170,7 @@ export function VideoPlayerModal({
158
170
 
159
171
  const borderTopRadiusAnimated = !isFullScreenOrPIP
160
172
  ? translateY.interpolate({
161
- inputRange: [0, height - collapsedHeight],
173
+ inputRange: [0, heightAboveMinimised],
162
174
  outputRange: [MODAL_RADIUS, 0],
163
175
  extrapolate: "clamp",
164
176
  })
@@ -182,93 +194,96 @@ export function VideoPlayerModal({
182
194
  <PanGestureHandler
183
195
  enabled={enabled}
184
196
  waitFor={scrollViewRef}
197
+ activeOffsetY={[-25, 25]}
198
+ activeOffsetX={[-25, 25]}
185
199
  {...gestureHandlerProps}
186
200
  >
187
- <Animated.View
188
- pointerEvents={"auto"}
189
- style={[
190
- styles.modalWrapper,
191
- {
192
- borderTopLeftRadius: borderTopRadiusAnimated,
193
- borderTopRightRadius: borderTopRadiusAnimated,
194
- transform: [{ translateY: isFullScreenOrPIP ? 0 : translateY }],
195
- height: screenHeight,
196
- },
197
- ]}
198
- >
201
+ <AnimatedSafeAreaView pointerEvents="box-none" edges={["bottom"]}>
199
202
  <Animated.View
200
203
  pointerEvents={"auto"}
201
204
  style={[
202
- styles.modal,
203
- collapsed ? styles.collapsedModalBg : null,
205
+ styles.modalWrapper,
204
206
  {
205
207
  borderTopLeftRadius: borderTopRadiusAnimated,
206
208
  borderTopRightRadius: borderTopRadiusAnimated,
207
- height: screenHeight,
209
+ transform: [{ translateY: isFullScreenOrPIP ? 0 : translateY }],
210
+ height: frame.height,
208
211
  },
209
212
  ]}
210
213
  >
211
214
  <Animated.View
212
- pointerEvents={!collapsed ? "auto" : "none"}
215
+ pointerEvents={"auto"}
213
216
  style={[
214
- pip ? styles.modalContentPiP : styles.modalContent,
215
- directionStyles(isTabletLandscape),
217
+ styles.modal,
218
+ collapsed ? styles.collapsedModalBg : null,
219
+ {
220
+ borderTopLeftRadius: borderTopRadiusAnimated,
221
+ borderTopRightRadius: borderTopRadiusAnimated,
222
+ },
216
223
  ]}
217
224
  >
218
225
  <Animated.View
226
+ pointerEvents={!collapsed ? "auto" : "none"}
219
227
  style={[
220
- styles.expandedContentContainer,
221
- {
222
- transform: [
223
- { translateX: xPosition },
224
- { translateY: yPosition },
225
- { scale: scalePosition },
226
- ],
227
- },
228
+ pip ? styles.modalContentPiP : styles.modalContent,
229
+ directionStyles(isTabletPortrait),
228
230
  ]}
229
231
  >
230
- {content}
232
+ <Animated.View
233
+ style={[
234
+ styles.expandedContentContainer,
235
+ {
236
+ transform: [
237
+ { translateX: xPosition },
238
+ { translateY: yPosition },
239
+ { scale: scalePosition },
240
+ ],
241
+ },
242
+ ]}
243
+ >
244
+ {content}
245
+ </Animated.View>
246
+ {extraContent ? (
247
+ <GestureAnimatedScrollView
248
+ ref={scrollViewRef}
249
+ contentContainerStyle={getExtraContentPadding(insets)}
250
+ bounces={false}
251
+ overScrollMode="never"
252
+ onLayout={onScrollViewLayout}
253
+ style={[
254
+ styles.extraContentScrollView,
255
+ { opacity: expandedOpacity },
256
+ ]}
257
+ >
258
+ <PlayerDetailsWrapperHeightContext.Provider
259
+ value={playerDetailsWrapperHeight}
260
+ >
261
+ {extraContent}
262
+ </PlayerDetailsWrapperHeightContext.Provider>
263
+ </GestureAnimatedScrollView>
264
+ ) : null}
231
265
  </Animated.View>
232
- {extraContent ? (
233
- <GestureAnimatedScrollView
234
- ref={scrollViewRef}
235
- contentContainerStyle={{
236
- paddingBottom: insets.bottom,
237
- }}
238
- onLayout={onScrollViewLayout}
266
+
267
+ {!isFullScreenOrPIP ? (
268
+ <Animated.View
269
+ pointerEvents={collapsed ? "box-none" : "none"}
239
270
  style={[
240
- styles.extraContentScrollView,
241
- { opacity: expandedOpacity },
271
+ styles.collapsedBarContainer,
272
+ { opacity: collapsedOpacity },
242
273
  ]}
243
274
  >
244
- <PlayerDetailsWrapperHeightContext.Provider
245
- value={playerDetailsWrapperHeight}
275
+ <Pressable
276
+ testID="collapsedBarWrapper"
277
+ onPress={expand}
278
+ style={styles.collapsedBarWrapper}
246
279
  >
247
- {extraContent}
248
- </PlayerDetailsWrapperHeightContext.Provider>
249
- </GestureAnimatedScrollView>
280
+ {collapsedContent}
281
+ </Pressable>
282
+ </Animated.View>
250
283
  ) : null}
251
284
  </Animated.View>
252
-
253
- {!isFullScreenOrPIP ? (
254
- <Animated.View
255
- pointerEvents={collapsed ? "box-none" : "none"}
256
- style={[
257
- styles.collapsedBarContainer,
258
- { opacity: collapsedOpacity },
259
- ]}
260
- >
261
- <Pressable
262
- testID="collapsedBarWrapper"
263
- onPress={expand}
264
- style={styles.collapsedBarWrapper}
265
- >
266
- {collapsedContent}
267
- </Pressable>
268
- </Animated.View>
269
- ) : null}
270
285
  </Animated.View>
271
- </Animated.View>
286
+ </AnimatedSafeAreaView>
272
287
  </PanGestureHandler>
273
288
  );
274
289
  }
@@ -1,159 +1,132 @@
1
1
  import { useCallback, useEffect, useMemo, useRef } from "react";
2
- import {
3
- useSafeAreaFrame,
4
- useSafeAreaInsets,
5
- } from "react-native-safe-area-context";
2
+
6
3
  import { State } from "react-native-gesture-handler";
7
- import { Animated } from "react-native";
8
4
 
9
5
  import { VideoModalMode } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainer";
10
- import { useConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
11
- import { getTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/getTabBarHeight";
6
+ import { useAnimationStateStore } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
12
7
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
13
- import { isMenuVisible } from "@applicaster/zapp-react-native-ui-components/Components/Screen/navigationHandler";
14
8
  import {
15
9
  ANIMATION_DURATION,
16
10
  DRAG_TO_COLLAPSE,
17
11
  DRAG_TO_EXPAND,
18
12
  } from "../consts";
19
- import { PROGRESS_BAR_HEIGHT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/utils";
20
- import { usePlugins } from "@applicaster/zapp-react-native-redux";
21
- import { isOldAndroidDevice } from "../utils";
22
-
23
- const bottomTabBarHeight = getTabBarHeight();
13
+ import { Animated } from "react-native";
14
+ import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
24
15
 
25
- export const useVideoModalState = (
26
- translateYRef: React.MutableRefObject<Animated.Value>
27
- ) => {
28
- const { minimised_height: minimisedHeight } = useConfiguration();
16
+ const getAnimatedValue = (animatedValue: Animated.Value): number => {
17
+ return (animatedValue as any).__getValue() as number;
18
+ };
29
19
 
20
+ export const useVideoModalState = () => {
30
21
  const {
31
- maximiseVideoModal,
32
- minimiseVideoModal,
33
- videoModalState,
34
- currentRoute,
35
- screenData,
36
- } = useNavigation();
37
-
38
- const plugins = usePlugins();
39
-
40
- const menuVisible = isMenuVisible(currentRoute, screenData, plugins);
41
-
42
- const collapsed =
43
- videoModalState.visible &&
44
- videoModalState.mode === VideoModalMode.MINIMIZED;
45
-
46
- const frame = useSafeAreaFrame();
47
- const insets = useSafeAreaInsets();
48
-
49
- const collapsedHeight =
50
- minimisedHeight +
51
- (menuVisible ? bottomTabBarHeight : 0) +
52
- (isOldAndroidDevice ? 0 : insets.bottom) +
53
- PROGRESS_BAR_HEIGHT;
54
-
55
- const heightAboveMinimised = frame.height - collapsedHeight;
22
+ yTranslate,
23
+ offset,
24
+ heightAboveMinimised,
25
+ gestureTranslationRef,
26
+ offsetAnimatedValueRef,
27
+ } = useModalAnimationContext();
56
28
 
57
- const translateY = translateYRef.current;
29
+ const modalAnimatedValue = offsetAnimatedValueRef.current;
30
+ const gestureTranslation = gestureTranslationRef.current;
58
31
 
59
- const handleExpand = useCallback(
60
- (toValue: number) => {
61
- return Animated.timing(translateYRef.current, {
32
+ const updateModalTranslation = useCallback(
33
+ (toValue: number, duration: number = ANIMATION_DURATION) =>
34
+ Animated.timing(modalAnimatedValue, {
62
35
  toValue,
63
- duration: ANIMATION_DURATION,
36
+ duration,
64
37
  useNativeDriver: true,
65
- });
66
- },
67
- [translateYRef]
38
+ }),
39
+ [modalAnimatedValue]
68
40
  );
69
41
 
70
- const handleCollapse = useCallback(
71
- (toValue: number) => {
72
- return Animated.timing(translateYRef.current, {
73
- toValue,
74
- duration: ANIMATION_DURATION,
75
- useNativeDriver: true,
76
- });
77
- },
78
- [translateYRef]
79
- );
42
+ const translateY = yTranslate.current;
80
43
 
81
- const offset = useRef(heightAboveMinimised);
44
+ const { maximiseVideoModal, minimiseVideoModal, videoModalState } =
45
+ useNavigation();
82
46
 
83
- // Gesture handler for modal
84
- const onGestureEvent = useCallback(
85
- (event: any) => {
86
- if (event.nativeEvent.state === State.ACTIVE) {
87
- const y = event.nativeEvent.translationY;
88
- let newY = offset.current + y;
89
- if (newY < 0) newY = 0;
47
+ const videoModalMode = videoModalState.mode;
90
48
 
91
- if (newY > heightAboveMinimised) {
92
- newY = heightAboveMinimised;
93
- }
49
+ const prevModeStateRef = useRef(videoModalMode); // keep track of last non-PIP mode
50
+ const gestureStateRef = useRef<any>(State.UNDETERMINED); // keep track of gesture state
94
51
 
95
- translateY.setValue(newY);
96
- }
97
- },
98
- [collapsedHeight, translateY]
52
+ // Track last non-PIP mode
53
+ if (videoModalMode !== prevModeStateRef.current) {
54
+ if (["MAXIMIZED", "MINIMIZED"].includes(videoModalMode)) {
55
+ prevModeStateRef.current = videoModalMode;
56
+ }
57
+ }
58
+
59
+ const collapsed =
60
+ videoModalState.visible &&
61
+ ((prevModeStateRef.current === "MINIMIZED" &&
62
+ videoModalState.mode === "PIP") || // If STILL in PIP mode, check if last non-PIP mode was MINIMIZED
63
+ videoModalState.mode === VideoModalMode.MINIMIZED); // Or if currently in MINIMIZED mode
64
+
65
+ // Gesture handler for modal
66
+ const onGestureEvent = useMemo(
67
+ () =>
68
+ Animated.event([{ nativeEvent: { translationY: gestureTranslation } }], {
69
+ useNativeDriver: true,
70
+ }),
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ []
99
73
  );
100
74
 
101
75
  const onHandlerStateChange = useCallback(
102
76
  (event: any) => {
103
- if (event.nativeEvent.oldState === State.ACTIVE) {
104
- const { translationY } = event.nativeEvent;
105
- let newY = offset.current + translationY;
106
- if (newY < 0) newY = 0;
77
+ const { state: newState, oldState, translationY } = event.nativeEvent;
107
78
 
108
- if (newY > heightAboveMinimised) {
109
- newY = heightAboveMinimised;
110
- }
79
+ if (newState === State.ACTIVE || oldState === State.ACTIVE) {
80
+ useAnimationStateStore.setState({
81
+ isAnimationInProgress: newState === State.ACTIVE,
82
+ });
83
+ }
111
84
 
112
- const shouldCollapse =
113
- translationY > heightAboveMinimised * DRAG_TO_COLLAPSE;
114
-
115
- const shouldExpand =
116
- translationY < -heightAboveMinimised * DRAG_TO_EXPAND;
117
-
118
- if (!collapsed && shouldCollapse) {
119
- // Collapse
120
- Animated.timing(translateY, {
121
- toValue: heightAboveMinimised,
122
- duration: ANIMATION_DURATION,
123
- useNativeDriver: true,
124
- }).start(() => {
125
- minimiseVideoModal();
126
- offset.current = heightAboveMinimised;
127
- });
128
- } else if (collapsed && shouldExpand) {
129
- // Expand
130
- Animated.timing(translateY, {
131
- toValue: 0,
132
- duration: ANIMATION_DURATION,
133
- useNativeDriver: true,
134
- }).start(() => {
135
- maximiseVideoModal();
136
- offset.current = 0;
137
- translateY.setValue(0);
138
- });
139
- } else {
140
- // Snap back to current state
141
- Animated.spring(translateY, {
142
- toValue: collapsed ? heightAboveMinimised : 0,
143
- useNativeDriver: true,
144
- }).start(() => {
145
- offset.current = collapsed ? heightAboveMinimised : 0;
146
- translateY.setValue(offset.current);
147
- });
85
+ // Update gesture state tracking
86
+ gestureStateRef.current = newState;
87
+
88
+ if (translationY !== 0) {
89
+ if (newState === State.BEGAN) {
90
+ // clean up gesture translation
91
+ gestureTranslation.setValue(0);
92
+ } else if (
93
+ newState === State.END ||
94
+ newState === State.FAILED ||
95
+ newState === State.CANCELLED
96
+ ) {
97
+ const newY = getAnimatedValue(gestureTranslation);
98
+
99
+ // clean up gesture translation
100
+ gestureTranslation.setValue(0);
101
+
102
+ const v = getAnimatedValue(modalAnimatedValue);
103
+
104
+ // store current offset
105
+ modalAnimatedValue.setValue(v + newY);
106
+
107
+ const shouldCollapse = newY > offset.current * DRAG_TO_COLLAPSE;
108
+
109
+ const shouldExpand = newY < offset.current * DRAG_TO_EXPAND;
110
+
111
+ if (!collapsed && shouldCollapse) {
112
+ // Collapse
113
+ updateModalTranslation(offset.current).start(() => {
114
+ minimiseVideoModal();
115
+ });
116
+ } else if (collapsed && shouldExpand) {
117
+ // Expand
118
+ updateModalTranslation(0).start(() => {
119
+ maximiseVideoModal();
120
+ });
121
+ } else {
122
+ // Snap back to current state
123
+ updateModalTranslation(collapsed ? offset.current : 0).start();
124
+ }
148
125
  }
149
- } else if (event.nativeEvent.state === State.BEGAN) {
150
- // Gesture started, set offset
151
- translateY.stopAnimation((value: number) => {
152
- offset.current = value;
153
- });
154
126
  }
155
127
  },
156
- [collapsedHeight, translateY, collapsed, videoModalState]
128
+ // eslint-disable-next-line react-hooks/exhaustive-deps
129
+ [collapsed]
157
130
  );
158
131
 
159
132
  const gestureHandlerProps = useMemo(() => {
@@ -163,44 +136,34 @@ export const useVideoModalState = (
163
136
  };
164
137
  }, [onGestureEvent, onHandlerStateChange]);
165
138
 
139
+ // Track video modal state changes & calling updateAnimatedPosition
166
140
  useEffect(() => {
167
141
  if (videoModalState.visible) {
168
- if (videoModalState.mode === VideoModalMode.MAXIMIZED) {
169
- handleExpand(0).start(() => {
170
- maximiseVideoModal();
171
- offset.current = 0;
172
- translateY.setValue(0);
173
- });
174
- } else if (videoModalState.mode === VideoModalMode.MINIMIZED) {
175
- handleCollapse(heightAboveMinimised).start(() => {
176
- minimiseVideoModal();
177
- offset.current = heightAboveMinimised;
178
- translateY.setValue(heightAboveMinimised);
179
- });
142
+ const mode =
143
+ videoModalMode === "PIP" ? prevModeStateRef.current : videoModalMode;
144
+
145
+ // Prevent changes during active gesture states to avoid interference
146
+ if ([State.ACTIVE].includes(gestureStateRef.current)) {
147
+ return;
148
+ }
149
+
150
+ if (mode === VideoModalMode.MAXIMIZED) {
151
+ updateModalTranslation(0).start();
152
+ } else if (mode === VideoModalMode.MINIMIZED) {
153
+ updateModalTranslation(heightAboveMinimised).start();
180
154
  }
181
155
  }
182
- }, [
183
- videoModalState.visible,
184
- videoModalState.mode,
185
- collapsedHeight,
186
- heightAboveMinimised,
187
- ]);
156
+ // eslint-disable-next-line react-hooks/exhaustive-deps
157
+ }, [videoModalState.visible, videoModalState.mode, heightAboveMinimised]);
188
158
 
189
159
  return useMemo(
190
160
  () => ({
191
161
  collapsed,
192
- collapsedHeight,
193
162
  offset,
194
163
  gestureHandlerProps,
195
164
  translateY,
196
165
  expand: maximiseVideoModal,
197
166
  }),
198
- [
199
- collapsed,
200
- collapsedHeight,
201
- gestureHandlerProps,
202
- translateY,
203
- maximiseVideoModal,
204
- ]
167
+ [collapsed, offset, gestureHandlerProps, translateY, maximiseVideoModal]
205
168
  );
206
169
  };
@@ -63,6 +63,7 @@ export const useStyles = ({ height }: { height: number }) => {
63
63
  backgroundColor,
64
64
  elevation: 10,
65
65
  zIndex: 100,
66
+ height: "100%",
66
67
  overflow: "hidden",
67
68
  },
68
69
  modalWrapper: {
@@ -1,18 +1,32 @@
1
- import { Dimensions } from "react-native";
1
+ import { StyleSheet, Dimensions, ViewStyle } from "react-native";
2
2
 
3
3
  import {
4
4
  isAndroidPlatform,
5
5
  isAndroidVersionAtLeast,
6
+ isTV,
6
7
  } from "@applicaster/zapp-react-native-utils/reactUtils";
8
+ import { useIsTablet as getIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
7
9
 
8
- const MIN_SUPPORTED_ANDROID_API = 34;
10
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
9
11
 
10
12
  export const isOldAndroidDevice =
11
- isAndroidPlatform() && !isAndroidVersionAtLeast(MIN_SUPPORTED_ANDROID_API);
13
+ isAndroidPlatform() &&
14
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION);
12
15
 
13
- export const getWindowHeight = (): number => {
16
+ export const getWindowHeight = (
17
+ isTablet: boolean,
18
+ landscape: boolean
19
+ ): number => {
14
20
  const windowDimensions = Dimensions.get("window");
15
21
 
22
+ if (isTablet && landscape) {
23
+ return windowDimensions.height;
24
+ }
25
+
26
+ if (windowDimensions.width > windowDimensions.height) {
27
+ return windowDimensions.width;
28
+ }
29
+
16
30
  return windowDimensions.height;
17
31
  };
18
32
 
@@ -22,8 +36,76 @@ export const getScreenHeight = (): number => {
22
36
  return screenDimensions.height;
23
37
  };
24
38
 
25
- export const getWindowWidth = (): number => {
39
+ export const getWindowWidth = (
40
+ isTablet: boolean,
41
+ landscape: boolean
42
+ ): number => {
26
43
  const windowDimensions = Dimensions.get("window");
27
44
 
45
+ if (isTablet && landscape) {
46
+ return windowDimensions.width;
47
+ }
48
+
49
+ if (windowDimensions.width > windowDimensions.height) {
50
+ return windowDimensions.height;
51
+ }
52
+
28
53
  return windowDimensions.width;
29
54
  };
55
+
56
+ const getIsTabletLandscape = (isTabletPortrait: boolean): boolean => {
57
+ return !isTV() && getIsTablet() && !isTabletPortrait;
58
+ };
59
+
60
+ export const getInsetsOffset = (
61
+ insets: { top: number; bottom: number },
62
+ isTabletPortrait: boolean
63
+ ): number => {
64
+ const isTabletLandscape = getIsTabletLandscape(isTabletPortrait);
65
+
66
+ return getIsTablet() && isTabletLandscape
67
+ ? isOldAndroidDevice
68
+ ? insets.top / 2
69
+ : 0
70
+ : insets.top / 2;
71
+ };
72
+
73
+ const orientationStyles = StyleSheet.create({
74
+ landscape: { flexDirection: "row" },
75
+ portrait: { flexDirection: "column" },
76
+ });
77
+
78
+ export const directionStyles = (isTabletPortrait: boolean): ViewStyle => {
79
+ const isTabletLandscape = getIsTabletLandscape(isTabletPortrait);
80
+
81
+ return isTabletLandscape
82
+ ? orientationStyles.landscape
83
+ : orientationStyles.portrait;
84
+ };
85
+
86
+ export const getScaledPos = (
87
+ height,
88
+ vidHeight,
89
+ minimisedHeight,
90
+ isTabletPortrait
91
+ ) => {
92
+ const isTabletLandscape = getIsTabletLandscape(isTabletPortrait);
93
+
94
+ const SCALE_FACTOR = minimisedHeight / vidHeight; // Scale factor for expanded content
95
+
96
+ return (
97
+ ((isTabletLandscape ? height : vidHeight) - vidHeight * SCALE_FACTOR) / 2
98
+ );
99
+ };
100
+
101
+ export const getExtraContentPadding = (insets: {
102
+ top: number;
103
+ bottom: number;
104
+ }): ViewStyle => {
105
+ const isTablet = getIsTablet(); // not a hook, just a utility function
106
+
107
+ return {
108
+ paddingTop: isTablet ? insets.top : 0,
109
+ paddingBottom: insets.bottom,
110
+ };
111
+ };
@@ -835,25 +835,25 @@ export default class VideoPlayer extends React.Component<
835
835
  : styles.playerContainerBlack;
836
836
 
837
837
  private getBackgroundImageStyle = (
838
- dimensions: any,
838
+ dimensions: ViewStyle,
839
839
  isAudioItem: boolean
840
- ): ViewStyle => ({
841
- ...(isAudioItem ? styles.audio : { position: "absolute" }),
842
- ...dimensions,
843
- });
840
+ ): ViewStyle[] => [
841
+ isAudioItem ? styles.audio : { position: "absolute" },
842
+ dimensions,
843
+ ];
844
844
 
845
845
  /* Returns player view style based on platform and content type (audio/video) */
846
846
  private getPlayerViewStyle = (
847
847
  dimensions: ViewStyle,
848
848
  isAudioItem: boolean
849
- ): ViewStyle => {
850
- const generalStyles = isAudioItem ? styles.audio : {};
849
+ ): ViewStyle | ViewStyle[] => {
850
+ const generalStyles = isAudioItem ? styles.audio : undefined;
851
851
 
852
852
  if (isAndroidPlatform() && isAudioItem) {
853
853
  return generalStyles;
854
854
  }
855
855
 
856
- return { ...generalStyles, ...dimensions };
856
+ return [generalStyles, dimensions];
857
857
  };
858
858
 
859
859
  private renderAudioPlayer = (
@@ -876,7 +876,7 @@ export default class VideoPlayer extends React.Component<
876
876
  shouldRender: boolean,
877
877
  imageKey: string,
878
878
  entry: ZappEntry,
879
- style: ViewStyle
879
+ style: ViewStyle | ViewStyle[]
880
880
  ) => {
881
881
  if (!shouldRender) return null;
882
882
 
@@ -887,7 +887,7 @@ export default class VideoPlayer extends React.Component<
887
887
 
888
888
  private renderNativePlayer = (
889
889
  shouldRender: boolean,
890
- style: ViewStyle,
890
+ style: ViewStyle | ViewStyle[],
891
891
  nativeEvents: ReturnType<typeof this.getNativeEvents>,
892
892
  nativeProps: ReturnType<typeof this.getNativeProps>,
893
893
  pluginConfiguration: Record<string, any>
@@ -1265,13 +1265,13 @@ export default class VideoPlayer extends React.Component<
1265
1265
  </View>
1266
1266
  }
1267
1267
  />
1268
- ) : (
1268
+ ) : isModal ? (
1269
1269
  <VideoPlayerModal
1270
1270
  isTabletPortrait={isTabletPortrait}
1271
1271
  aspectRatio={aspectRatio}
1272
1272
  pip={piped}
1273
1273
  fullscreen={fullscreen}
1274
- modal={isModal}
1274
+ modal
1275
1275
  style={{
1276
1276
  tabletLandscapeWidth: getTabletWidth(
1277
1277
  this.getPluginConfiguration().tablet_landscape_sidebar_width,
@@ -1309,6 +1309,13 @@ export default class VideoPlayer extends React.Component<
1309
1309
  </View>
1310
1310
  }
1311
1311
  />
1312
+ ) : (
1313
+ <View style={style} testID={"player-view"}>
1314
+ <PlayerWrapper
1315
+ {...sharedWrapperViewProps}
1316
+ playerContent={this.renderPlayerContent}
1317
+ />
1318
+ </View>
1312
1319
  );
1313
1320
  };
1314
1321
 
@@ -1,23 +0,0 @@
1
- import { calculateLiveProgressBarTime } from "../utils";
2
-
3
- describe("Utils", () => {
4
- describe("calculateLiveProgressBarTime", () => {
5
- it("Should return 0", () => {
6
- expect(calculateLiveProgressBarTime(68, 1)).toBe(0);
7
-
8
- expect(calculateLiveProgressBarTime(68, 0)).toBe(0);
9
-
10
- expect(calculateLiveProgressBarTime(68, -1)).toBe(0);
11
-
12
- expect(calculateLiveProgressBarTime(68, -5)).toBe(0);
13
- });
14
-
15
- it("Should return equal duration", () => {
16
- expect(calculateLiveProgressBarTime(68, -100)).toBe(-68);
17
-
18
- expect(calculateLiveProgressBarTime(68, -68)).toBe(-68);
19
-
20
- expect(calculateLiveProgressBarTime(68, -105)).toBe(-68);
21
- });
22
- });
23
- });
@@ -1,78 +0,0 @@
1
- import * as React from "react";
2
-
3
- import { calculateLiveProgressBarTime, formatTimeDisplay } from "./utils";
4
- import { ProgressState } from "./useProgressState";
5
-
6
- // TODO: Must Add check RTL support
7
- const getSliderValues = (seekableDuration: number, time: number) => {
8
- const value = calculateLiveProgressBarTime(seekableDuration, time);
9
-
10
- return {
11
- minimumValue: -seekableDuration,
12
- maximumValue: 0,
13
- value: Math.min(0, value),
14
- };
15
- };
16
-
17
- const prepareNewState = ({ seekableDuration, time }) => {
18
- const sliderValues = getSliderValues(seekableDuration, time);
19
-
20
- const getProgress = (
21
- seekableDuration: number,
22
- currentTime: number
23
- ): number => {
24
- return Math.round((currentTime / seekableDuration) * 100);
25
- };
26
-
27
- const getElapsedTime = (currentTime: number): string => {
28
- return currentTime === 0
29
- ? ""
30
- : `-${formatTimeDisplay(Math.abs(currentTime))}`;
31
- };
32
-
33
- const getLiveOffsetPercent = (): number =>
34
- (100 * (sliderValues.value - sliderValues.minimumValue)) /
35
- (sliderValues.maximumValue - sliderValues.minimumValue);
36
-
37
- return {
38
- progress: getProgress(seekableDuration, sliderValues.value),
39
- liveOffsetPercent: getLiveOffsetPercent(),
40
- time: [getElapsedTime(sliderValues.value), null],
41
- currentTime: sliderValues.value,
42
- duration: Math.max(0, seekableDuration),
43
- sliderValues,
44
- };
45
- };
46
-
47
- // TODO: Add for `NOW` localization
48
- export const useLiveProgressState = ({
49
- playerState: { currentTime, seekableDuration },
50
- }): [ProgressState, (seek: number) => void] => {
51
- const stateRef = React.useRef<ProgressState>({
52
- progress: 0,
53
- liveOffsetPercent: 0,
54
- time: ["--:--", "--:--"],
55
- currentTime: 0,
56
- duration: 0,
57
- sliderValues: {
58
- minimumValue: 0,
59
- maximumValue: 0,
60
- value: 0,
61
- },
62
- });
63
-
64
- const updateState = React.useCallback(
65
- (seekTime: number): void => {
66
- if (seekTime == null || seekableDuration == null) {
67
- return;
68
- }
69
-
70
- stateRef.current = prepareNewState({ seekableDuration, time: -seekTime });
71
- },
72
- [seekableDuration]
73
- );
74
-
75
- updateState(currentTime);
76
-
77
- return [stateRef.current, updateState];
78
- };
@@ -1,29 +0,0 @@
1
- import { useLiveProgressState } from "./useLiveProgressState";
2
- import { useVodProgressState } from "./useVodProgressState";
3
-
4
- export type ProgressState = {
5
- liveOffsetPercent?: number;
6
- progress: number;
7
- time: string[];
8
- currentTime: number;
9
- duration: number;
10
- sliderValues: { minimumValue: number; maximumValue: number; value: number };
11
- };
12
-
13
- // TODO: Try refactor to remove code duplication
14
- export const useProgressState = ({
15
- playerState: { seekableDuration, duration, isLive },
16
- remainingTimeDisplay = false,
17
- currentTime,
18
- }): [ProgressState, (seek) => void] => {
19
- const liveData = useLiveProgressState({
20
- playerState: { currentTime, seekableDuration },
21
- });
22
-
23
- const vodData = useVodProgressState({
24
- playerState: { currentTime, duration },
25
- remainingTimeDisplay,
26
- });
27
-
28
- return isLive ? liveData : vodData;
29
- };
@@ -1,115 +0,0 @@
1
- import * as React from "react";
2
-
3
- import { formatTimeDisplay } from "./utils";
4
- import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
5
- import { ProgressState } from "./useProgressState";
6
-
7
- // TODO: Refactor if needed, code was aligned to new structure only
8
-
9
- const getSliderValues = (duration: number, time: number, isRTL: boolean) => {
10
- const minimumValue = 0;
11
-
12
- // Default max value should be greater than duration due to RTL thumb animation
13
- const maximumValue = duration || 9999;
14
- const initValue = isRTL ? maximumValue : minimumValue;
15
- const currentValue = isRTL ? duration - time : time;
16
- const progressValue = !duration ? initValue : currentValue;
17
- const timeValue = !duration ? minimumValue : time;
18
-
19
- return {
20
- minimumValue,
21
- maximumValue,
22
- value: Math.max(0, progressValue),
23
- timeValue: Math.max(0, timeValue),
24
- };
25
- };
26
-
27
- const prepareNewState = ({ duration, time, remainingTimeDisplay, isRTL }) => {
28
- const sliderValues = getSliderValues(duration, time, isRTL);
29
-
30
- const getProgress = (duration, currentTime): number => {
31
- return Math.round((currentTime / duration) * 100);
32
- };
33
-
34
- const getElapsedTime = (currentTime): string => {
35
- return formatTimeDisplay(currentTime);
36
- };
37
-
38
- const getRemainingTime = (duration, currentTime): string => {
39
- if (isNaN(duration)) {
40
- return "--:--";
41
- }
42
-
43
- return formatTimeDisplay(duration - currentTime);
44
- };
45
-
46
- const remaining = getRemainingTime(duration, sliderValues.value);
47
-
48
- const remainingTimeState = remainingTimeDisplay
49
- ? `-${remaining}`
50
- : formatTimeDisplay(duration);
51
-
52
- return {
53
- progress: getProgress(duration, sliderValues.value),
54
- time: [getElapsedTime(sliderValues.timeValue), remainingTimeState],
55
- currentTime: sliderValues.timeValue,
56
- duration: Math.max(0, duration),
57
- sliderValues,
58
- };
59
- };
60
-
61
- export const useVodProgressState = ({
62
- remainingTimeDisplay = false,
63
- playerState: { currentTime, duration },
64
- }): [ProgressState, (seek) => void] => {
65
- const [state, setState] = React.useState<ProgressState>({
66
- progress: 0,
67
- time: ["--:--", "--:--"],
68
- currentTime: 0,
69
- duration: 0,
70
- sliderValues: {
71
- minimumValue: 0,
72
- maximumValue: 0,
73
- value: 0,
74
- },
75
- });
76
-
77
- const isRTL = useIsRTL();
78
-
79
- React.useEffect(() => {
80
- if (currentTime == null || duration == null) {
81
- return;
82
- }
83
-
84
- setState(
85
- prepareNewState({
86
- duration,
87
- time: currentTime,
88
- remainingTimeDisplay,
89
- isRTL,
90
- })
91
- );
92
- }, [currentTime, duration, isRTL, remainingTimeDisplay]);
93
-
94
- const updateState = React.useCallback(
95
- (seekTime?: number): void => {
96
- if (seekTime == null || duration == null) {
97
- return;
98
- }
99
-
100
- const time =
101
- (seekTime || seekTime === 0) && Math.abs(seekTime - currentTime) > 1
102
- ? seekTime
103
- : currentTime;
104
-
105
- if (duration && (time || time === 0)) {
106
- setState(
107
- prepareNewState({ duration, time, remainingTimeDisplay, isRTL })
108
- );
109
- }
110
- },
111
- [duration, currentTime, remainingTimeDisplay, isRTL]
112
- );
113
-
114
- return [state, updateState];
115
- };
@@ -1,33 +0,0 @@
1
- const prependZeroIfNeeded = (value) => {
2
- const s = typeof value === "number" ? String(value) : String(value ?? "");
3
-
4
- return `0${s}`.slice(-2);
5
- };
6
-
7
- export const calculateLiveProgressBarTime = (duration, time) => {
8
- const minimumLiveOffsetStart = -5;
9
-
10
- if (time < minimumLiveOffsetStart && time > -duration) {
11
- // -67 < -5 && -67 > -68
12
- return time;
13
- } else if (time <= -duration) {
14
- return -duration;
15
- }
16
-
17
- return 0;
18
- };
19
-
20
- export function formatTimeDisplay(durationInSeconds) {
21
- const hours = Math.floor(durationInSeconds / 60 / 60);
22
- const minutes = Math.floor((durationInSeconds - hours * 60 * 60) / 60);
23
-
24
- const seconds = Math.floor(
25
- durationInSeconds - hours * 60 * 60 - minutes * 60
26
- );
27
-
28
- const hr = prependZeroIfNeeded(hours);
29
- const mn = prependZeroIfNeeded(minutes);
30
- const sc = prependZeroIfNeeded(seconds);
31
-
32
- return `${hours ? `${hr}:` : ""}${mn || "00"}:${sc}`;
33
- }