@applicaster/quick-brick-player 15.0.0-alpha.5170277721 → 15.0.0-alpha.5197372201

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.
Files changed (25) hide show
  1. package/package.json +6 -6
  2. package/src/Player/AudioLayer/AudioPlayerWrapper.tsx +17 -1
  3. package/src/Player/AudioLayer/Layout/DockedControls/index.tsx +77 -58
  4. package/src/Player/AudioLayer/Layout/MobileLayout.tsx +1 -6
  5. package/src/Player/AudioLayer/Layout/PlayerImage/index.tsx +27 -25
  6. package/src/Player/AudioLayer/Layout/PlayerImage/styles.ts +6 -1
  7. package/src/Player/AudioLayer/Layout/TabletLandscapeLayout.tsx +5 -8
  8. package/src/Player/AudioLayer/Layout/TabletPortraitLayout.tsx +1 -6
  9. package/src/Player/AudioLayer/utils.ts +1 -27
  10. package/src/Player/PlayNextOverlay/index.tsx +2 -2
  11. package/src/Player/PlayerModal/PlayerModal.tsx +10 -15
  12. package/src/Player/PlayerModal/VideoPlayerModal.tsx +132 -114
  13. package/src/Player/PlayerModal/hooks/index.ts +113 -145
  14. package/src/Player/PlayerModal/styles.ts +5 -0
  15. package/src/Player/PlayerModal/utils/index.ts +94 -12
  16. package/src/Player/Utils/index.tsx +9 -9
  17. package/src/Player/hooks/progressStates/__tests__/utils.test.ts +23 -0
  18. package/src/Player/hooks/progressStates/useLiveProgressState.tsx +78 -0
  19. package/src/Player/hooks/progressStates/useProgressState.tsx +30 -0
  20. package/src/Player/hooks/progressStates/useVodProgressState.tsx +115 -0
  21. package/src/Player/hooks/progressStates/utils.ts +33 -0
  22. package/src/Player/index.tsx +23 -22
  23. package/src/Player/AudioLayer/Layout/PlayerImage/AnimatedImage.tsx +0 -82
  24. package/src/Player/AudioLayer/Layout/PlayerImage/hooks/index.ts +0 -1
  25. package/src/Player/AudioLayer/Layout/PlayerImage/hooks/useChangePlayerState.ts +0 -99
@@ -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 { getWindowHeight, getWindowWidth } from "./utils";
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";
22
32
 
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
- };
33
+ const AnimatedSafeAreaView = Animated.createAnimatedComponent(SafeAreaView);
31
34
 
32
35
  type AnimatedModalProps = {
33
36
  pip?: boolean;
@@ -59,44 +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 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
+ );
65
74
 
66
- let width = WINDOW_WIDTH;
75
+ const height = useMemo(
76
+ () => getWindowHeight(isTablet, !isTabletPortrait),
77
+ []
78
+ ); // remember initial height, ignore rotation changes
67
79
 
68
- if (isTablet && !isTabletPortrait) {
69
- width = style?.tabletLandscapeWidth || width;
70
- }
80
+ const MODAL_COLLAPSE_START = height * MODAL_COLLAPSE_RATIO;
71
81
 
72
82
  const { minimised_height: minimisedHeight } = useConfiguration();
73
83
  const scrollViewRef = useRef<typeof Animated.ScrollView | null>(null);
74
84
 
75
- const translateYRef = useModalAnimationContext().yTranslate;
76
- // used when modal is false, should not be used in animation
77
- const dummyRef = useRef(new Animated.Value(0));
85
+ const { translateY, collapsed, gestureHandlerProps, expand, offset } =
86
+ useVideoModalState();
78
87
 
79
- const {
80
- translateY,
81
- collapsed,
82
- collapsedHeight,
83
- gestureHandlerProps,
84
- expand,
85
- } = useVideoModalState(modal ? translateYRef : dummyRef);
88
+ const frame = useSafeAreaFrame();
89
+ const collapsedHeight = frame.height - offset.current;
86
90
 
87
91
  const heightAboveMinimised = height - collapsedHeight;
88
92
 
89
- const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
90
-
91
93
  const styles = useStyles({ height: collapsedHeight });
92
94
 
93
95
  const SCALE_FACTOR = 1 / (width / aspectRatio / minimisedHeight); // Scale factor for expanded content
94
96
 
95
97
  const insets = useSafeAreaInsets();
96
98
 
97
- 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]);
98
114
 
99
- // Interpolated opacities for smooth cross-fade
115
+ const isFullScreenOrPIP = isFullScreenMode;
116
+
117
+ const vidHeight = width / aspectRatio;
118
+
119
+ // animated opacity for smooth cross-fade of collapsed content
100
120
  const collapsedOpacity = !isFullScreenOrPIP
101
121
  ? translateY.interpolate({
102
122
  inputRange: [MODAL_COLLAPSE_START, heightAboveMinimised],
@@ -105,6 +125,7 @@ export function VideoPlayerModal({
105
125
  })
106
126
  : new Animated.Value(0);
107
127
 
128
+ // animated opacity for extra content
108
129
  const expandedOpacity = !isFullScreenOrPIP
109
130
  ? translateY.interpolate({
110
131
  inputRange: [0, heightAboveMinimised],
@@ -113,44 +134,35 @@ export function VideoPlayerModal({
113
134
  })
114
135
  : new Animated.Value(1);
115
136
 
137
+ // animated x position for video content
116
138
  const xPosition = !isFullScreenOrPIP
117
139
  ? translateY.interpolate({
118
- inputRange: [height * VIDEO_TRANSITION_THRESHOLD, heightAboveMinimised],
140
+ inputRange: [height * VIDEO_TRANSITION_THRESHOLD, MODAL_COLLAPSE_START],
119
141
  outputRange: [0, -(width - width * SCALE_FACTOR) / 2],
120
142
  extrapolate: "clamp",
121
143
  })
122
144
  : new Animated.Value(0);
123
145
 
124
- const vidHeight = width / aspectRatio;
125
-
146
+ // animated y position for video content
126
147
  const yPosition = !isFullScreenOrPIP
127
148
  ? translateY.interpolate({
128
- inputRange: [
129
- height * VIDEO_TRANSITION_THRESHOLD,
130
- height - collapsedHeight,
131
- ],
149
+ inputRange: [height * VIDEO_TRANSITION_THRESHOLD, MODAL_COLLAPSE_START],
132
150
  outputRange: [
133
151
  0,
134
- isTablet && isTabletLandscape
135
- ? -((-PROGRESS_BAR_HEIGHT + height - vidHeight * SCALE_FACTOR) / 2)
136
- : -(
137
- PROGRESS_BAR_HEIGHT +
138
- insets.top / 2 +
139
- (WINDOW_WIDTH / aspectRatio -
140
- (WINDOW_WIDTH / aspectRatio) * SCALE_FACTOR) /
141
- 2
142
- ),
152
+ -(
153
+ PROGRESS_BAR_HEIGHT +
154
+ getInsetsOffset(insets, isTabletPortrait) +
155
+ getScaledPos(height, vidHeight, minimisedHeight, isTabletPortrait)
156
+ ),
143
157
  ],
144
158
  extrapolate: "clamp",
145
159
  })
146
160
  : new Animated.Value(0);
147
161
 
162
+ // animated position for video content
148
163
  const scalePosition = !isFullScreenOrPIP
149
164
  ? translateY.interpolate({
150
- inputRange: [
151
- height * VIDEO_TRANSITION_THRESHOLD,
152
- height - collapsedHeight,
153
- ],
165
+ inputRange: [height * VIDEO_TRANSITION_THRESHOLD, MODAL_COLLAPSE_START],
154
166
  outputRange: [1, SCALE_FACTOR],
155
167
  extrapolate: "clamp",
156
168
  })
@@ -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,90 +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: height,
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: height,
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"}
213
- style={[styles.modalContent, directionStyles(isTabletLandscape)]}
215
+ pointerEvents={"auto"}
216
+ style={[
217
+ styles.modal,
218
+ collapsed ? styles.collapsedModalBg : null,
219
+ {
220
+ borderTopLeftRadius: borderTopRadiusAnimated,
221
+ borderTopRightRadius: borderTopRadiusAnimated,
222
+ },
223
+ ]}
214
224
  >
215
225
  <Animated.View
226
+ pointerEvents={!collapsed ? "auto" : "none"}
216
227
  style={[
217
- styles.expandedContentContainer,
218
- {
219
- transform: [
220
- { translateX: xPosition },
221
- { translateY: yPosition },
222
- { scale: scalePosition },
223
- ],
224
- },
228
+ pip ? styles.modalContentPiP : styles.modalContent,
229
+ directionStyles(isTabletPortrait),
225
230
  ]}
226
231
  >
227
- {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}
228
265
  </Animated.View>
229
- {extraContent ? (
230
- <GestureAnimatedScrollView
231
- ref={scrollViewRef}
232
- contentContainerStyle={{
233
- paddingBottom: insets.bottom,
234
- }}
235
- onLayout={onScrollViewLayout}
266
+
267
+ {!isFullScreenOrPIP ? (
268
+ <Animated.View
269
+ pointerEvents={collapsed ? "box-none" : "none"}
236
270
  style={[
237
- styles.extraContentScrollView,
238
- { opacity: expandedOpacity },
271
+ styles.collapsedBarContainer,
272
+ { opacity: collapsedOpacity },
239
273
  ]}
240
274
  >
241
- <PlayerDetailsWrapperHeightContext.Provider
242
- value={playerDetailsWrapperHeight}
275
+ <Pressable
276
+ testID="collapsedBarWrapper"
277
+ onPress={expand}
278
+ style={styles.collapsedBarWrapper}
243
279
  >
244
- {extraContent}
245
- </PlayerDetailsWrapperHeightContext.Provider>
246
- </GestureAnimatedScrollView>
280
+ {collapsedContent}
281
+ </Pressable>
282
+ </Animated.View>
247
283
  ) : null}
248
284
  </Animated.View>
249
-
250
- {!isFullScreenOrPIP ? (
251
- <Animated.View
252
- pointerEvents={collapsed ? "box-none" : "none"}
253
- style={[
254
- styles.collapsedBarContainer,
255
- { opacity: collapsedOpacity },
256
- ]}
257
- >
258
- <Pressable
259
- testID="collapsedBarWrapper"
260
- onPress={expand}
261
- style={styles.collapsedBarWrapper}
262
- >
263
- {collapsedContent}
264
- </Pressable>
265
- </Animated.View>
266
- ) : null}
267
285
  </Animated.View>
268
- </Animated.View>
286
+ </AnimatedSafeAreaView>
269
287
  </PanGestureHandler>
270
288
  );
271
289
  }
@@ -1,159 +1,132 @@
1
1
  import { useCallback, useEffect, useMemo, useRef } from "react";
2
- import { useSafeAreaInsets } from "react-native-safe-area-context";
2
+
3
3
  import { State } from "react-native-gesture-handler";
4
- import { Animated } from "react-native";
5
4
 
6
5
  import { VideoModalMode } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainer";
7
- import { useConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
8
- import { getTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/getTabBarHeight";
6
+ import { useAnimationStateStore } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/utils";
9
7
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
10
- import { isMenuVisible } from "@applicaster/zapp-react-native-ui-components/Components/Screen/navigationHandler";
11
8
  import {
12
9
  ANIMATION_DURATION,
13
10
  DRAG_TO_COLLAPSE,
14
11
  DRAG_TO_EXPAND,
15
12
  } from "../consts";
16
- import { PROGRESS_BAR_HEIGHT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/utils";
17
- import { usePlugins } from "@applicaster/zapp-react-native-redux";
18
- import { getWindowHeight } from "../utils";
19
-
20
- const bottomTabBarHeight = getTabBarHeight();
21
-
22
- export const useVideoModalState = (
23
- translateYRef: React.MutableRefObject<Animated.Value>
24
- ) => {
25
- const { minimised_height: minimisedHeight } = useConfiguration();
13
+ import { Animated } from "react-native";
14
+ import { useModalAnimationContext } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
26
15
 
27
- const WINDOW_HEIGHT = getWindowHeight();
16
+ const getAnimatedValue = (animatedValue: Animated.Value): number => {
17
+ return (animatedValue as any).__getValue() as number;
18
+ };
28
19
 
20
+ export const useVideoModalState = () => {
29
21
  const {
30
- maximiseVideoModal,
31
- minimiseVideoModal,
32
- videoModalState,
33
- currentRoute,
34
- screenData,
35
- } = useNavigation();
36
-
37
- const plugins = usePlugins();
22
+ yTranslate,
23
+ offset,
24
+ heightAboveMinimised,
25
+ gestureTranslationRef,
26
+ offsetAnimatedValueRef,
27
+ } = useModalAnimationContext();
28
+
29
+ const modalAnimatedValue = offsetAnimatedValueRef.current;
30
+ const gestureTranslation = gestureTranslationRef.current;
31
+
32
+ const updateModalTranslation = useCallback(
33
+ (toValue: number, duration: number = ANIMATION_DURATION) =>
34
+ Animated.timing(modalAnimatedValue, {
35
+ toValue,
36
+ duration,
37
+ useNativeDriver: true,
38
+ }),
39
+ [modalAnimatedValue]
40
+ );
38
41
 
39
- const menuVisible = isMenuVisible(currentRoute, screenData, plugins);
42
+ const translateY = yTranslate.current;
40
43
 
41
- const collapsed =
42
- videoModalState.visible &&
43
- videoModalState.mode === VideoModalMode.MINIMIZED;
44
+ const { maximiseVideoModal, minimiseVideoModal, videoModalState } =
45
+ useNavigation();
44
46
 
45
- const { bottom } = useSafeAreaInsets();
47
+ const videoModalMode = videoModalState.mode;
46
48
 
47
- const initialBottomOffset = useRef(bottom).current;
49
+ const prevModeStateRef = useRef(videoModalMode); // keep track of last non-PIP mode
50
+ const gestureStateRef = useRef<any>(State.UNDETERMINED); // keep track of gesture state
48
51
 
49
- const collapsedHeight =
50
- minimisedHeight +
51
- initialBottomOffset +
52
- (menuVisible ? bottomTabBarHeight : 0) +
53
- PROGRESS_BAR_HEIGHT;
54
-
55
- const heightAboveMinimised = WINDOW_HEIGHT - collapsedHeight;
52
+ // Track last non-PIP mode
53
+ if (videoModalMode !== prevModeStateRef.current) {
54
+ if (["MAXIMIZED", "MINIMIZED"].includes(videoModalMode)) {
55
+ prevModeStateRef.current = videoModalMode;
56
+ }
57
+ }
56
58
 
57
- const translateY = translateYRef.current;
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
58
64
 
59
- const handleExpand = useCallback(
60
- (toValue: number) => {
61
- return Animated.timing(translateYRef.current, {
62
- toValue,
63
- duration: ANIMATION_DURATION,
65
+ // Gesture handler for modal
66
+ const onGestureEvent = useMemo(
67
+ () =>
68
+ Animated.event([{ nativeEvent: { translationY: gestureTranslation } }], {
64
69
  useNativeDriver: true,
65
- });
66
- },
67
- [translateYRef]
70
+ }),
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ []
68
73
  );
69
74
 
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
- );
80
-
81
- const offset = useRef(heightAboveMinimised);
82
-
83
- // Gesture handler for modal
84
- const onGestureEvent = useCallback(
75
+ const onHandlerStateChange = useCallback(
85
76
  (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;
90
-
91
- if (newY > heightAboveMinimised) {
92
- newY = heightAboveMinimised;
93
- }
77
+ const { state: newState, oldState, translationY } = event.nativeEvent;
94
78
 
95
- translateY.setValue(newY);
79
+ if (newState === State.ACTIVE || oldState === State.ACTIVE) {
80
+ useAnimationStateStore.setState({
81
+ isAnimationInProgress: newState === State.ACTIVE,
82
+ });
96
83
  }
97
- },
98
- [collapsedHeight, translateY]
99
- );
100
84
 
101
- const onHandlerStateChange = useCallback(
102
- (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;
85
+ // Update gesture state tracking
86
+ gestureStateRef.current = newState;
107
87
 
108
- if (newY > heightAboveMinimised) {
109
- newY = heightAboveMinimised;
110
- }
88
+ if (newState === State.FAILED) {
89
+ return;
90
+ }
111
91
 
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
- });
92
+ if (translationY !== 0) {
93
+ if (newState === State.BEGAN) {
94
+ // clean up gesture translation
95
+ gestureTranslation.setValue(0);
96
+ } else if (newState === State.END || newState === State.CANCELLED) {
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,39 +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
- }, [videoModalState.visible, videoModalState.mode, collapsedHeight]);
156
+ // eslint-disable-next-line react-hooks/exhaustive-deps
157
+ }, [videoModalState.visible, videoModalState.mode, heightAboveMinimised]);
183
158
 
184
159
  return useMemo(
185
160
  () => ({
186
161
  collapsed,
187
- collapsedHeight,
188
162
  offset,
189
163
  gestureHandlerProps,
190
164
  translateY,
191
165
  expand: maximiseVideoModal,
192
166
  }),
193
- [
194
- collapsed,
195
- collapsedHeight,
196
- gestureHandlerProps,
197
- translateY,
198
- maximiseVideoModal,
199
- ]
167
+ [collapsed, offset, gestureHandlerProps, translateY, maximiseVideoModal]
200
168
  );
201
169
  };