This commit is contained in:
xmflsct 2022-10-10 23:43:26 +02:00
parent 34d02c9ca3
commit 35c585fb81
1 changed files with 9 additions and 16 deletions

View File

@ -7,6 +7,7 @@ import { Blurhash } from 'react-native-blurhash'
import attachmentAspectRatio from './aspectRatio' import attachmentAspectRatio from './aspectRatio'
import analytics from '@components/analytics' import analytics from '@components/analytics'
import AttachmentAltText from './AltText' import AttachmentAltText from './AltText'
import { Platform } from 'expo-modules-core'
export interface Props { export interface Props {
total: number total: number
@ -27,6 +28,7 @@ const AttachmentVideo: React.FC<Props> = ({
const [videoLoading, setVideoLoading] = useState(false) const [videoLoading, setVideoLoading] = useState(false)
const [videoLoaded, setVideoLoaded] = useState(false) const [videoLoaded, setVideoLoaded] = useState(false)
const [videoPosition, setVideoPosition] = useState<number>(0) const [videoPosition, setVideoPosition] = useState<number>(0)
const [videoResizeMode, setVideoResizeMode] = useState<ResizeMode>(ResizeMode.COVER)
const playOnPress = useCallback(async () => { const playOnPress = useCallback(async () => {
analytics('timeline_shared_attachment_video_length', { analytics('timeline_shared_attachment_video_length', {
length: video.meta?.length length: video.meta?.length
@ -39,6 +41,7 @@ const AttachmentVideo: React.FC<Props> = ({
if (!videoLoaded) { if (!videoLoaded) {
await videoPlayer.current?.loadAsync({ uri: video.url }) await videoPlayer.current?.loadAsync({ uri: video.url })
} }
Platform.OS === 'android' && setVideoResizeMode(ResizeMode.CONTAIN)
await videoPlayer.current?.setPositionAsync(videoPosition) await videoPlayer.current?.setPositionAsync(videoPosition)
await videoPlayer.current?.presentFullscreenPlayer() await videoPlayer.current?.presentFullscreenPlayer()
videoPlayer.current?.playAsync() videoPlayer.current?.playAsync()
@ -62,11 +65,7 @@ const AttachmentVideo: React.FC<Props> = ({
const _handleAppStateChange = async (nextAppState: AppStateStatus) => { const _handleAppStateChange = async (nextAppState: AppStateStatus) => {
if (appState.current.match(/active/) && nextAppState.match(/inactive/)) { if (appState.current.match(/active/) && nextAppState.match(/inactive/)) {
await videoPlayer.current?.pauseAsync() await videoPlayer.current?.pauseAsync()
} else if ( } else if (gifv && appState.current.match(/background/) && nextAppState.match(/active/)) {
gifv &&
appState.current.match(/background/) &&
nextAppState.match(/active/)
) {
await videoPlayer.current?.setIsMutedAsync(true) await videoPlayer.current?.setIsMutedAsync(true)
await videoPlayer.current?.playAsync() await videoPlayer.current?.playAsync()
} }
@ -99,7 +98,7 @@ const AttachmentVideo: React.FC<Props> = ({
opacity: sensitiveShown ? 0 : 1 opacity: sensitiveShown ? 0 : 1
}} }}
usePoster usePoster
resizeMode={ResizeMode.COVER} resizeMode={videoResizeMode}
{...(gifv {...(gifv
? { ? {
shouldPlay: true, shouldPlay: true,
@ -113,12 +112,9 @@ const AttachmentVideo: React.FC<Props> = ({
})} })}
useNativeControls={false} useNativeControls={false}
onFullscreenUpdate={async event => { onFullscreenUpdate={async event => {
if ( if (event.fullscreenUpdate === VideoFullscreenUpdate.PLAYER_DID_DISMISS) {
event.fullscreenUpdate === VideoFullscreenUpdate.PLAYER_DID_DISMISS Platform.OS === 'android' && setVideoResizeMode(ResizeMode.COVER)
) { if (!gifv) {
if (gifv) {
await videoPlayer.current?.pauseAsync()
} else {
await videoPlayer.current?.pauseAsync() await videoPlayer.current?.pauseAsync()
} }
} }
@ -156,10 +152,7 @@ const AttachmentVideo: React.FC<Props> = ({
loading={videoLoading} loading={videoLoading}
/> />
) : null} ) : null}
<AttachmentAltText <AttachmentAltText sensitiveShown={sensitiveShown} text={video.description} />
sensitiveShown={sensitiveShown}
text={video.description}
/>
</Pressable> </Pressable>
</View> </View>
) )