-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sharing video player from chat to attachment modal #37202
Merged
lakchote
merged 3 commits into
Expensify:main
from
software-mansion-labs:@Skalakid/fix-video-sharing
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeed | |
import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext'; | ||
import VideoPopoverMenu from '@components/VideoPopoverMenu'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; | ||
import * as Browser from '@libs/Browser'; | ||
import * as DeviceCapabilities from '@libs/DeviceCapabilities'; | ||
|
@@ -41,7 +40,6 @@ function BaseVideoPlayer({ | |
isVideoHovered, | ||
}) { | ||
const styles = useThemeStyles(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
const {pauseVideo, playVideo, currentlyPlayingURL, updateSharedElements, sharedElement, originalParent, shareVideoPlayerElements, currentVideoPlayerRef, updateCurrentlyPlayingURL} = | ||
usePlaybackContext(); | ||
const [duration, setDuration] = useState(videoDuration * 1000); | ||
|
@@ -96,20 +94,24 @@ function BaseVideoPlayer({ | |
|
||
const handlePlaybackStatusUpdate = useCallback( | ||
(e) => { | ||
if (shouldReplayVideo(e, isPlaying, duration, position)) { | ||
const isVideoPlaying = e.isPlaying || false; | ||
const currentDuration = e.durationMillis || videoDuration * 1000; | ||
const currentPositon = e.positionMillis || 0; | ||
|
||
if (shouldReplayVideo(e, isVideoPlaying, currentDuration, currentPositon)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a bug but can we consider moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change of replacing |
||
videoPlayerRef.current.setStatusAsync({positionMillis: 0, shouldPlay: true}); | ||
} | ||
const isVideoPlaying = e.isPlaying || false; | ||
|
||
preventPausingWhenExitingFullscreen(isVideoPlaying); | ||
setIsPlaying(isVideoPlaying); | ||
setIsLoading(!e.isLoaded || Number.isNaN(e.durationMillis)); // when video is ready to display duration is not NaN | ||
setIsBuffering(e.isBuffering || false); | ||
setDuration(e.durationMillis || videoDuration * 1000); | ||
setPosition(e.positionMillis || 0); | ||
setDuration(currentDuration); | ||
setPosition(currentPositon); | ||
|
||
onPlaybackStatusUpdate(e); | ||
}, | ||
[onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration, isPlaying, duration, position], | ||
[onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration], | ||
); | ||
|
||
const handleFullscreenUpdate = useCallback( | ||
|
@@ -165,44 +167,44 @@ function BaseVideoPlayer({ | |
} | ||
originalParent.appendChild(sharedElement); | ||
}; | ||
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, isSmallScreenWidth, originalParent, sharedElement, shouldUseSharedVideoElement, url]); | ||
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, originalParent, sharedElement, shouldUseSharedVideoElement, url]); | ||
|
||
return ( | ||
<> | ||
<View style={style}> | ||
<Hoverable> | ||
{(isHovered) => ( | ||
<View style={[styles.w100, styles.h100]}> | ||
{shouldUseSharedVideoElement ? ( | ||
<> | ||
<View | ||
ref={sharedVideoPlayerParentRef} | ||
style={[styles.flex1]} | ||
/> | ||
{/* We are adding transparent absolute View between appended video component and control buttons to enable | ||
<PressableWithoutFeedback | ||
accessibilityRole="button" | ||
onPress={() => { | ||
togglePlayCurrentVideo(); | ||
}} | ||
style={styles.flex1} | ||
> | ||
{shouldUseSharedVideoElement ? ( | ||
<> | ||
<View | ||
ref={sharedVideoPlayerParentRef} | ||
style={[styles.flex1]} | ||
/> | ||
{/* We are adding transparent absolute View between appended video component and control buttons to enable | ||
catching onMouse events from Attachment Carousel. Due to late appending React doesn't handle | ||
element's events properly. */} | ||
<View style={[styles.w100, styles.h100, styles.pAbsolute]} /> | ||
</> | ||
) : ( | ||
<View | ||
style={styles.flex1} | ||
ref={(el) => { | ||
if (!el) { | ||
return; | ||
} | ||
videoPlayerElementParentRef.current = el; | ||
if (el.childNodes && el.childNodes[0]) { | ||
videoPlayerElementRef.current = el.childNodes[0]; | ||
} | ||
}} | ||
> | ||
<PressableWithoutFeedback | ||
accessibilityRole="button" | ||
onPress={() => { | ||
togglePlayCurrentVideo(); | ||
}} | ||
<View style={[styles.w100, styles.h100, styles.pAbsolute]} /> | ||
</> | ||
) : ( | ||
<View | ||
style={styles.flex1} | ||
ref={(el) => { | ||
if (!el) { | ||
return; | ||
} | ||
videoPlayerElementParentRef.current = el; | ||
if (el.childNodes && el.childNodes[0]) { | ||
videoPlayerElementRef.current = el.childNodes[0]; | ||
} | ||
}} | ||
> | ||
<Video | ||
ref={videoPlayerRef} | ||
|
@@ -219,9 +221,9 @@ function BaseVideoPlayer({ | |
onPlaybackStatusUpdate={handlePlaybackStatusUpdate} | ||
onFullscreenUpdate={handleFullscreenUpdate} | ||
/> | ||
</PressableWithoutFeedback> | ||
</View> | ||
)} | ||
</View> | ||
)} | ||
</PressableWithoutFeedback> | ||
|
||
{(isLoading || isBuffering) && <FullScreenLoadingIndicator style={[styles.opacity1, styles.bgTransparent]} />} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused this a regression here: #37750