Only animate the like icon when from an actual toggle (#5096)

zio/stable
Hailey 2024-09-03 10:55:53 -07:00 committed by GitHub
parent bd42f770b8
commit 0014d4363f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 9 deletions

View File

@ -91,13 +91,15 @@ export function CountWheel({
likeCount, likeCount,
big, big,
isLiked, isLiked,
isToggle,
}: { }: {
likeCount: number likeCount: number
big?: boolean big?: boolean
isLiked: boolean isLiked: boolean
isToggle: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const shouldAnimate = !useReducedMotion() const shouldAnimate = !useReducedMotion() && isToggle
const shouldRoll = decideShouldRoll(isLiked, likeCount) const shouldRoll = decideShouldRoll(isLiked, likeCount)
// Incrementing the key will cause the `Animated.View` to re-render, with the newly selected entering/exiting // Incrementing the key will cause the `Animated.View` to re-render, with the newly selected entering/exiting

View File

@ -39,13 +39,15 @@ export function CountWheel({
likeCount, likeCount,
big, big,
isLiked, isLiked,
isToggle,
}: { }: {
likeCount: number likeCount: number
big?: boolean big?: boolean
isLiked: boolean isLiked: boolean
isToggle: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const shouldAnimate = !useReducedMotion() const shouldAnimate = !useReducedMotion() && isToggle
const shouldRoll = decideShouldRoll(isLiked, likeCount) const shouldRoll = decideShouldRoll(isLiked, likeCount)
const countView = React.useRef<HTMLDivElement>(null) const countView = React.useRef<HTMLDivElement>(null)

View File

@ -71,13 +71,15 @@ const circle2Keyframe = new Keyframe({
export function AnimatedLikeIcon({ export function AnimatedLikeIcon({
isLiked, isLiked,
big, big,
isToggle,
}: { }: {
isLiked: boolean isLiked: boolean
big?: boolean big?: boolean
isToggle: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const size = big ? 22 : 18 const size = big ? 22 : 18
const shouldAnimate = !useReducedMotion() const shouldAnimate = !useReducedMotion() && isToggle
return ( return (
<View> <View>

View File

@ -41,13 +41,15 @@ const circle2Keyframe = [
export function AnimatedLikeIcon({ export function AnimatedLikeIcon({
isLiked, isLiked,
big, big,
isToggle,
}: { }: {
isLiked: boolean isLiked: boolean
big?: boolean big?: boolean
isToggle: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const size = big ? 22 : 18 const size = big ? 22 : 18
const shouldAnimate = !useReducedMotion() const shouldAnimate = !useReducedMotion() && isToggle
const prevIsLiked = React.useRef(isLiked) const prevIsLiked = React.useRef(isLiked)
const likeIconRef = React.useRef<HTMLDivElement>(null) const likeIconRef = React.useRef<HTMLDivElement>(null)

View File

@ -106,8 +106,7 @@ let PostCtrls = ({
[t], [t],
) as StyleProp<ViewStyle> ) as StyleProp<ViewStyle>
const likeValue = post.viewer?.like ? 1 : 0 const [isToggleLikeIcon, setIsToggleLikeIcon] = React.useState(false)
const nextExpectedLikeValue = React.useRef(likeValue)
const onPressToggleLike = React.useCallback(async () => { const onPressToggleLike = React.useCallback(async () => {
if (isBlocked) { if (isBlocked) {
@ -119,8 +118,8 @@ let PostCtrls = ({
} }
try { try {
setIsToggleLikeIcon(true)
if (!post.viewer?.like) { if (!post.viewer?.like) {
nextExpectedLikeValue.current = 1
playHaptic() playHaptic()
sendInteraction({ sendInteraction({
item: post.uri, item: post.uri,
@ -130,7 +129,6 @@ let PostCtrls = ({
captureAction(ProgressGuideAction.Like) captureAction(ProgressGuideAction.Like)
await queueLike() await queueLike()
} else { } else {
nextExpectedLikeValue.current = 0
await queueUnlike() await queueUnlike()
} }
} catch (e: any) { } catch (e: any) {
@ -317,11 +315,16 @@ let PostCtrls = ({
} }
accessibilityHint="" accessibilityHint=""
hitSlop={POST_CTRL_HITSLOP}> hitSlop={POST_CTRL_HITSLOP}>
<AnimatedLikeIcon isLiked={Boolean(post.viewer?.like)} big={big} /> <AnimatedLikeIcon
isLiked={Boolean(post.viewer?.like)}
big={big}
isToggle={isToggleLikeIcon}
/>
<CountWheel <CountWheel
likeCount={post.likeCount ?? 0} likeCount={post.likeCount ?? 0}
big={big} big={big}
isLiked={Boolean(post.viewer?.like)} isLiked={Boolean(post.viewer?.like)}
isToggle={isToggleLikeIcon}
/> />
</Pressable> </Pressable>
</View> </View>