Animate profile avis on open too

This commit is contained in:
Dan Abramov
2024-11-02 12:05:33 +00:00
parent 092494f891
commit 77e71cf353
+30 -9
View File
@@ -1,5 +1,12 @@
import React, {memo} from 'react' import React, {memo} from 'react'
import {StyleSheet, TouchableWithoutFeedback, View} from 'react-native' import {StyleSheet, TouchableWithoutFeedback, View} from 'react-native'
import Animated, {
measure,
MeasuredDimensions,
runOnJS,
runOnUI,
useAnimatedRef,
} from 'react-native-reanimated'
import {AppBskyActorDefs, ModerationDecision} from '@atproto/api' import {AppBskyActorDefs, ModerationDecision} from '@atproto/api'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
@@ -42,6 +49,7 @@ let ProfileHeaderShell = ({
const {openLightbox} = useLightboxControls() const {openLightbox} = useLightboxControls()
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const {isDesktop} = useWebMediaQueries() const {isDesktop} = useWebMediaQueries()
const aviRef = useAnimatedRef()
const onPressBack = React.useCallback(() => { const onPressBack = React.useCallback(() => {
if (navigation.canGoBack()) { if (navigation.canGoBack()) {
@@ -51,15 +59,14 @@ let ProfileHeaderShell = ({
} }
}, [navigation]) }, [navigation])
const onPressAvi = React.useCallback(() => { const _openLightbox = React.useCallback(
const modui = moderation.ui('avatar') (uri: string, thumbRect: MeasuredDimensions | null) => {
if (profile.avatar && !(modui.blur && modui.noOverride)) {
openLightbox({ openLightbox({
images: [ images: [
{ {
uri: profile.avatar, uri,
thumbUri: profile.avatar, thumbUri: uri,
thumbRect: null, thumbRect,
dimensions: { dimensions: {
// It's fine if it's actually smaller but we know it's 1:1. // It's fine if it's actually smaller but we know it's 1:1.
height: 1000, height: 1000,
@@ -69,8 +76,21 @@ let ProfileHeaderShell = ({
], ],
index: 0, index: 0,
}) })
},
[openLightbox],
)
const onPressAvi = React.useCallback(() => {
const modui = moderation.ui('avatar')
const avatar = profile.avatar
if (avatar && !(modui.blur && modui.noOverride)) {
runOnUI(() => {
'worklet'
const rect = measure(aviRef)
runOnJS(_openLightbox)(avatar, rect)
})()
} }
}, [openLightbox, profile, moderation]) }, [profile, moderation, _openLightbox, aviRef])
const isMe = React.useMemo( const isMe = React.useMemo(
() => currentAccount?.did === profile.did, () => currentAccount?.did === profile.did,
@@ -141,7 +161,8 @@ let ProfileHeaderShell = ({
accessibilityRole="image" accessibilityRole="image"
accessibilityLabel={_(msg`View ${profile.handle}'s avatar`)} accessibilityLabel={_(msg`View ${profile.handle}'s avatar`)}
accessibilityHint=""> accessibilityHint="">
<View <Animated.View
ref={aviRef}
style={[ style={[
t.atoms.bg, t.atoms.bg,
{borderColor: t.atoms.bg.backgroundColor}, {borderColor: t.atoms.bg.backgroundColor},
@@ -154,7 +175,7 @@ let ProfileHeaderShell = ({
avatar={profile.avatar} avatar={profile.avatar}
moderation={moderation.ui('avatar')} moderation={moderation.ui('avatar')}
/> />
</View> </Animated.View>
</TouchableWithoutFeedback> </TouchableWithoutFeedback>
</GrowableAvatar> </GrowableAvatar>
</View> </View>