Skip to content

Commit 5d2933d

Browse files
authored
Merge pull request #37202 from software-mansion-labs/@Skalakid/fix-video-sharing
Fix sharing video player from chat to attachment modal
2 parents 46fbe51 + 81ff827 commit 5d2933d

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

src/components/Attachments/AttachmentCarousel/CarouselItem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function CarouselItem({item, onPress, isFocused, isModalHovered}) {
109109
isHovered={isModalHovered}
110110
isFocused={isFocused}
111111
optionalVideoDuration={item.duration}
112+
isUsedInCarousel
112113
/>
113114
</View>
114115

src/components/VideoPlayer/BaseVideoPlayer.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeed
99
import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext';
1010
import VideoPopoverMenu from '@components/VideoPopoverMenu';
1111
import useThemeStyles from '@hooks/useThemeStyles';
12-
import useWindowDimensions from '@hooks/useWindowDimensions';
1312
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
1413
import * as Browser from '@libs/Browser';
1514
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
@@ -43,7 +42,6 @@ function BaseVideoPlayer({
4342
isVideoHovered,
4443
}) {
4544
const styles = useThemeStyles();
46-
const {isSmallScreenWidth} = useWindowDimensions();
4745
const {pauseVideo, playVideo, currentlyPlayingURL, updateSharedElements, sharedElement, originalParent, shareVideoPlayerElements, currentVideoPlayerRef, updateCurrentlyPlayingURL} =
4846
usePlaybackContext();
4947
const [duration, setDuration] = useState(videoDuration * 1000);
@@ -99,20 +97,24 @@ function BaseVideoPlayer({
9997

10098
const handlePlaybackStatusUpdate = useCallback(
10199
(e) => {
102-
if (shouldReplayVideo(e, isPlaying, duration, position)) {
100+
const isVideoPlaying = e.isPlaying || false;
101+
const currentDuration = e.durationMillis || videoDuration * 1000;
102+
const currentPositon = e.positionMillis || 0;
103+
104+
if (shouldReplayVideo(e, isVideoPlaying, currentDuration, currentPositon)) {
103105
videoPlayerRef.current.setStatusAsync({positionMillis: 0, shouldPlay: true});
104106
}
105-
const isVideoPlaying = e.isPlaying || false;
107+
106108
preventPausingWhenExitingFullscreen(isVideoPlaying);
107109
setIsPlaying(isVideoPlaying);
108110
setIsLoading(!e.isLoaded || Number.isNaN(e.durationMillis)); // when video is ready to display duration is not NaN
109111
setIsBuffering(e.isBuffering || false);
110-
setDuration(e.durationMillis || videoDuration * 1000);
111-
setPosition(e.positionMillis || 0);
112+
setDuration(currentDuration);
113+
setPosition(currentPositon);
112114

113115
onPlaybackStatusUpdate(e);
114116
},
115-
[onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration, isPlaying, duration, position],
117+
[onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration],
116118
);
117119

118120
const handleFullscreenUpdate = useCallback(
@@ -168,44 +170,44 @@ function BaseVideoPlayer({
168170
}
169171
originalParent.appendChild(sharedElement);
170172
};
171-
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, isSmallScreenWidth, originalParent, sharedElement, shouldUseSharedVideoElement, url]);
173+
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, originalParent, sharedElement, shouldUseSharedVideoElement, url]);
172174

173175
return (
174176
<>
175177
<View style={style}>
176178
<Hoverable>
177179
{(isHovered) => (
178180
<View style={[styles.w100, styles.h100]}>
179-
{shouldUseSharedVideoElement ? (
180-
<>
181-
<View
182-
ref={sharedVideoPlayerParentRef}
183-
style={[styles.flex1]}
184-
/>
185-
{/* We are adding transparent absolute View between appended video component and control buttons to enable
181+
<PressableWithoutFeedback
182+
accessibilityRole="button"
183+
onPress={() => {
184+
togglePlayCurrentVideo();
185+
}}
186+
style={styles.flex1}
187+
>
188+
{shouldUseSharedVideoElement ? (
189+
<>
190+
<View
191+
ref={sharedVideoPlayerParentRef}
192+
style={[styles.flex1]}
193+
/>
194+
{/* We are adding transparent absolute View between appended video component and control buttons to enable
186195
catching onMouse events from Attachment Carousel. Due to late appending React doesn't handle
187196
element's events properly. */}
188-
<View style={[styles.w100, styles.h100, styles.pAbsolute]} />
189-
</>
190-
) : (
191-
<View
192-
style={styles.flex1}
193-
ref={(el) => {
194-
if (!el) {
195-
return;
196-
}
197-
videoPlayerElementParentRef.current = el;
198-
if (el.childNodes && el.childNodes[0]) {
199-
videoPlayerElementRef.current = el.childNodes[0];
200-
}
201-
}}
202-
>
203-
<PressableWithoutFeedback
204-
accessibilityRole="button"
205-
onPress={() => {
206-
togglePlayCurrentVideo();
207-
}}
197+
<View style={[styles.w100, styles.h100, styles.pAbsolute]} />
198+
</>
199+
) : (
200+
<View
208201
style={styles.flex1}
202+
ref={(el) => {
203+
if (!el) {
204+
return;
205+
}
206+
videoPlayerElementParentRef.current = el;
207+
if (el.childNodes && el.childNodes[0]) {
208+
videoPlayerElementRef.current = el.childNodes[0];
209+
}
210+
}}
209211
>
210212
<Video
211213
ref={videoPlayerRef}
@@ -222,9 +224,9 @@ function BaseVideoPlayer({
222224
onPlaybackStatusUpdate={handlePlaybackStatusUpdate}
223225
onFullscreenUpdate={handleFullscreenUpdate}
224226
/>
225-
</PressableWithoutFeedback>
226-
</View>
227-
)}
227+
</View>
228+
)}
229+
</PressableWithoutFeedback>
228230

229231
{(isLoading || isBuffering) && <FullScreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />}
230232

0 commit comments

Comments
 (0)