Skip to content

Commit

Permalink
Attempted video perf improvements (#6519)
Browse files Browse the repository at this point in the history
* remove layout animations from video

* only show button/spinner when necessary

* use native activityindicator rather than loader
  • Loading branch information
mozzius authored Nov 19, 2024
1 parent 9a57d2a commit ea3fe93
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
54 changes: 26 additions & 28 deletions src/view/com/util/post-embeds/VideoEmbed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useState} from 'react'
import {View} from 'react-native'
import {ActivityIndicator, View} from 'react-native'
import {ImageBackground} from 'expo-image'
import {AppBskyEmbedVideo} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
Expand All @@ -10,7 +10,6 @@ import {VideoEmbedInnerNative} from '#/view/com/util/post-embeds/VideoEmbedInner
import {atoms as a} from '#/alf'
import {Button} from '#/components/Button'
import {useThrottledValue} from '#/components/hooks/useThrottledValue'
import {Loader} from '#/components/Loader'
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
import {ErrorBoundary} from '../ErrorBoundary'
import * as VideoFallback from './VideoEmbedInner/VideoFallback'
Expand Down Expand Up @@ -89,40 +88,39 @@ function InnerWrapper({embed}: Props) {
source={{uri: embed.thumbnail}}
accessibilityIgnoresInvertColors
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,
// the play button won't show up on the first render on android 🥴😮‍💨
display: showOverlay ? 'flex' : 'none',
},
]}
cachePolicy="memory-disk" // Preferring memory cache helps to avoid flicker when re-displaying on android
>
<Button
style={[a.flex_1, a.align_center, a.justify_center]}
onPress={() => {
ref.current?.togglePlayback()
}}
label={_(msg`Play video`)}
color="secondary">
{showSpinner ? (
<View
style={[
a.rounded_full,
a.p_xs,
a.align_center,
a.justify_center,
]}>
<Loader size="2xl" style={{color: 'white'}} />
</View>
) : (
<PlayButtonIcon />
)}
</Button>
{showOverlay && (
<Button
style={[a.flex_1, a.align_center, a.justify_center]}
onPress={() => {
ref.current?.togglePlayback()
}}
label={_(msg`Play video`)}
color="secondary">
{showSpinner ? (
<View
style={[
a.rounded_full,
a.p_xs,
a.align_center,
a.justify_center,
]}>
<ActivityIndicator size="large" color="white" />
</View>
) : (
<PlayButtonIcon />
)}
</Button>
)}
</ImageBackground>
</>
)
Expand Down
10 changes: 4 additions & 6 deletions src/view/com/util/post-embeds/VideoEmbedInner/TimeIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
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'

/**
Expand All @@ -26,9 +26,7 @@ export function TimeIndicator({
const seconds = String(time % 60).padStart(2, '0')

return (
<Animated.View
entering={native(FadeInDown.duration(300))}
exiting={native(FadeOutDown.duration(500))}
<View
pointerEvents="none"
style={[
{
Expand All @@ -52,6 +50,6 @@ export function TimeIndicator({
]}>
{`${minutes}:${seconds}`}
</Text>
</Animated.View>
</View>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {useRef} from 'react'
import {Pressable, StyleProp, View, ViewStyle} from 'react-native'
import Animated, {FadeInDown} from 'react-native-reanimated'
import {AppBskyEmbedVideo} from '@atproto/api'
import {BlueskyVideoView} from '@haileyok/bluesky-video'
import {msg} from '@lingui/macro'
Expand Down Expand Up @@ -182,8 +181,7 @@ function ControlButton({
style?: StyleProp<ViewStyle>
}) {
return (
<Animated.View
entering={FadeInDown.duration(300)}
<View
style={[
a.absolute,
a.rounded_full,
Expand All @@ -207,6 +205,6 @@ function ControlButton({
hitSlop={HITSLOP_30}>
{children}
</Pressable>
</Animated.View>
</View>
)
}

0 comments on commit ea3fe93

Please sign in to comment.