@@ -9,7 +9,6 @@ import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeed
9
9
import { usePlaybackContext } from '@components/VideoPlayerContexts/PlaybackContext' ;
10
10
import VideoPopoverMenu from '@components/VideoPopoverMenu' ;
11
11
import useThemeStyles from '@hooks/useThemeStyles' ;
12
- import useWindowDimensions from '@hooks/useWindowDimensions' ;
13
12
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL' ;
14
13
import * as Browser from '@libs/Browser' ;
15
14
import * as DeviceCapabilities from '@libs/DeviceCapabilities' ;
@@ -43,7 +42,6 @@ function BaseVideoPlayer({
43
42
isVideoHovered,
44
43
} ) {
45
44
const styles = useThemeStyles ( ) ;
46
- const { isSmallScreenWidth} = useWindowDimensions ( ) ;
47
45
const { pauseVideo, playVideo, currentlyPlayingURL, updateSharedElements, sharedElement, originalParent, shareVideoPlayerElements, currentVideoPlayerRef, updateCurrentlyPlayingURL} =
48
46
usePlaybackContext ( ) ;
49
47
const [ duration , setDuration ] = useState ( videoDuration * 1000 ) ;
@@ -99,20 +97,24 @@ function BaseVideoPlayer({
99
97
100
98
const handlePlaybackStatusUpdate = useCallback (
101
99
( 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 ) ) {
103
105
videoPlayerRef . current . setStatusAsync ( { positionMillis : 0 , shouldPlay : true } ) ;
104
106
}
105
- const isVideoPlaying = e . isPlaying || false ;
107
+
106
108
preventPausingWhenExitingFullscreen ( isVideoPlaying ) ;
107
109
setIsPlaying ( isVideoPlaying ) ;
108
110
setIsLoading ( ! e . isLoaded || Number . isNaN ( e . durationMillis ) ) ; // when video is ready to display duration is not NaN
109
111
setIsBuffering ( e . isBuffering || false ) ;
110
- setDuration ( e . durationMillis || videoDuration * 1000 ) ;
111
- setPosition ( e . positionMillis || 0 ) ;
112
+ setDuration ( currentDuration ) ;
113
+ setPosition ( currentPositon ) ;
112
114
113
115
onPlaybackStatusUpdate ( e ) ;
114
116
} ,
115
- [ onPlaybackStatusUpdate , preventPausingWhenExitingFullscreen , videoDuration , isPlaying , duration , position ] ,
117
+ [ onPlaybackStatusUpdate , preventPausingWhenExitingFullscreen , videoDuration ] ,
116
118
) ;
117
119
118
120
const handleFullscreenUpdate = useCallback (
@@ -168,44 +170,44 @@ function BaseVideoPlayer({
168
170
}
169
171
originalParent . appendChild ( sharedElement ) ;
170
172
} ;
171
- } , [ bindFunctions , currentVideoPlayerRef , currentlyPlayingURL , isSmallScreenWidth , originalParent , sharedElement , shouldUseSharedVideoElement , url ] ) ;
173
+ } , [ bindFunctions , currentVideoPlayerRef , currentlyPlayingURL , originalParent , sharedElement , shouldUseSharedVideoElement , url ] ) ;
172
174
173
175
return (
174
176
< >
175
177
< View style = { style } >
176
178
< Hoverable >
177
179
{ ( isHovered ) => (
178
180
< 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
186
195
catching onMouse events from Attachment Carousel. Due to late appending React doesn't handle
187
196
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
208
201
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
+ } }
209
211
>
210
212
< Video
211
213
ref = { videoPlayerRef }
@@ -222,9 +224,9 @@ function BaseVideoPlayer({
222
224
onPlaybackStatusUpdate = { handlePlaybackStatusUpdate }
223
225
onFullscreenUpdate = { handleFullscreenUpdate }
224
226
/>
225
- </ PressableWithoutFeedback >
226
- </ View >
227
- ) }
227
+ </ View >
228
+ ) }
229
+ </ PressableWithoutFeedback >
228
230
229
231
{ ( isLoading || isBuffering ) && < FullScreenLoadingIndicator style = { [ styles . opacity1 , styles . bgTransparent ] } /> }
230
232
0 commit comments