Attempted video perf improvements (#6519)

* remove layout animations from video

* only show button/spinner when necessary

* use native activityindicator rather than loader
This commit is contained in:
Samuel Newman
2024-11-19 12:50:06 +00:00
committed by GitHub
parent 9a57d2a538
commit ea3fe93be9
3 changed files with 32 additions and 38 deletions
+26 -28
View File
@@ -1,5 +1,5 @@
import React, {useCallback, useState} from 'react' import React, {useCallback, useState} from 'react'
import {View} from 'react-native' import {ActivityIndicator, View} from 'react-native'
import {ImageBackground} from 'expo-image' import {ImageBackground} from 'expo-image'
import {AppBskyEmbedVideo} from '@atproto/api' import {AppBskyEmbedVideo} from '@atproto/api'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
@@ -10,7 +10,6 @@ import {VideoEmbedInnerNative} from '#/view/com/util/post-embeds/VideoEmbedInner
import {atoms as a} from '#/alf' import {atoms as a} from '#/alf'
import {Button} from '#/components/Button' import {Button} from '#/components/Button'
import {useThrottledValue} from '#/components/hooks/useThrottledValue' import {useThrottledValue} from '#/components/hooks/useThrottledValue'
import {Loader} from '#/components/Loader'
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
import {ErrorBoundary} from '../ErrorBoundary' import {ErrorBoundary} from '../ErrorBoundary'
import * as VideoFallback from './VideoEmbedInner/VideoFallback' import * as VideoFallback from './VideoEmbedInner/VideoFallback'
@@ -89,12 +88,9 @@ function InnerWrapper({embed}: Props) {
source={{uri: embed.thumbnail}} source={{uri: embed.thumbnail}}
accessibilityIgnoresInvertColors accessibilityIgnoresInvertColors
style={[ style={[
a.absolute,
a.inset_0,
{ {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'transparent', // If you don't add `backgroundColor` to the styles here, backgroundColor: 'transparent', // If you don't add `backgroundColor` to the styles here,
// the play button won't show up on the first render on android 🥴😮‍💨 // the play button won't show up on the first render on android 🥴😮‍💨
display: showOverlay ? 'flex' : 'none', display: showOverlay ? 'flex' : 'none',
@@ -102,27 +98,29 @@ function InnerWrapper({embed}: Props) {
]} ]}
cachePolicy="memory-disk" // Preferring memory cache helps to avoid flicker when re-displaying on android cachePolicy="memory-disk" // Preferring memory cache helps to avoid flicker when re-displaying on android
> >
<Button {showOverlay && (
style={[a.flex_1, a.align_center, a.justify_center]} <Button
onPress={() => { style={[a.flex_1, a.align_center, a.justify_center]}
ref.current?.togglePlayback() onPress={() => {
}} ref.current?.togglePlayback()
label={_(msg`Play video`)} }}
color="secondary"> label={_(msg`Play video`)}
{showSpinner ? ( color="secondary">
<View {showSpinner ? (
style={[ <View
a.rounded_full, style={[
a.p_xs, a.rounded_full,
a.align_center, a.p_xs,
a.justify_center, a.align_center,
]}> a.justify_center,
<Loader size="2xl" style={{color: 'white'}} /> ]}>
</View> <ActivityIndicator size="large" color="white" />
) : ( </View>
<PlayButtonIcon /> ) : (
)} <PlayButtonIcon />
</Button> )}
</Button>
)}
</ImageBackground> </ImageBackground>
</> </>
) )
@@ -1,8 +1,8 @@
import React from 'react' import React from 'react'
import {StyleProp, ViewStyle} from 'react-native' import {StyleProp, ViewStyle} from 'react-native'
import Animated, {FadeInDown, FadeOutDown} from 'react-native-reanimated' import {View} from 'react-native'
import {atoms as a, native, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
/** /**
@@ -26,9 +26,7 @@ export function TimeIndicator({
const seconds = String(time % 60).padStart(2, '0') const seconds = String(time % 60).padStart(2, '0')
return ( return (
<Animated.View <View
entering={native(FadeInDown.duration(300))}
exiting={native(FadeOutDown.duration(500))}
pointerEvents="none" pointerEvents="none"
style={[ style={[
{ {
@@ -52,6 +50,6 @@ export function TimeIndicator({
]}> ]}>
{`${minutes}:${seconds}`} {`${minutes}:${seconds}`}
</Text> </Text>
</Animated.View> </View>
) )
} }
@@ -1,6 +1,5 @@
import React, {useRef} from 'react' import React, {useRef} from 'react'
import {Pressable, StyleProp, View, ViewStyle} from 'react-native' import {Pressable, StyleProp, View, ViewStyle} from 'react-native'
import Animated, {FadeInDown} from 'react-native-reanimated'
import {AppBskyEmbedVideo} from '@atproto/api' import {AppBskyEmbedVideo} from '@atproto/api'
import {BlueskyVideoView} from '@haileyok/bluesky-video' import {BlueskyVideoView} from '@haileyok/bluesky-video'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
@@ -182,8 +181,7 @@ function ControlButton({
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
}) { }) {
return ( return (
<Animated.View <View
entering={FadeInDown.duration(300)}
style={[ style={[
a.absolute, a.absolute,
a.rounded_full, a.rounded_full,
@@ -207,6 +205,6 @@ function ControlButton({
hitSlop={HITSLOP_30}> hitSlop={HITSLOP_30}>
{children} {children}
</Pressable> </Pressable>
</Animated.View> </View>
) )
} }