Skip to content

Commit

Permalink
Only animate the like icon when from an actual toggle (#5096)
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok authored Sep 3, 2024
1 parent bd42f77 commit 0014d43
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/lib/custom-animations/CountWheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ export function CountWheel({
likeCount,
big,
isLiked,
isToggle,
}: {
likeCount: number
big?: boolean
isLiked: boolean
isToggle: boolean
}) {
const t = useTheme()
const shouldAnimate = !useReducedMotion()
const shouldAnimate = !useReducedMotion() && isToggle
const shouldRoll = decideShouldRoll(isLiked, likeCount)

// Incrementing the key will cause the `Animated.View` to re-render, with the newly selected entering/exiting
Expand Down
4 changes: 3 additions & 1 deletion src/lib/custom-animations/CountWheel.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export function CountWheel({
likeCount,
big,
isLiked,
isToggle,
}: {
likeCount: number
big?: boolean
isLiked: boolean
isToggle: boolean
}) {
const t = useTheme()
const shouldAnimate = !useReducedMotion()
const shouldAnimate = !useReducedMotion() && isToggle
const shouldRoll = decideShouldRoll(isLiked, likeCount)

const countView = React.useRef<HTMLDivElement>(null)
Expand Down
4 changes: 3 additions & 1 deletion src/lib/custom-animations/LikeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ const circle2Keyframe = new Keyframe({
export function AnimatedLikeIcon({
isLiked,
big,
isToggle,
}: {
isLiked: boolean
big?: boolean
isToggle: boolean
}) {
const t = useTheme()
const size = big ? 22 : 18
const shouldAnimate = !useReducedMotion()
const shouldAnimate = !useReducedMotion() && isToggle

return (
<View>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/custom-animations/LikeIcon.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ const circle2Keyframe = [
export function AnimatedLikeIcon({
isLiked,
big,
isToggle,
}: {
isLiked: boolean
big?: boolean
isToggle: boolean
}) {
const t = useTheme()
const size = big ? 22 : 18
const shouldAnimate = !useReducedMotion()
const shouldAnimate = !useReducedMotion() && isToggle
const prevIsLiked = React.useRef(isLiked)

const likeIconRef = React.useRef<HTMLDivElement>(null)
Expand Down
13 changes: 8 additions & 5 deletions src/view/com/util/post-ctrls/PostCtrls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ let PostCtrls = ({
[t],
) as StyleProp<ViewStyle>

const likeValue = post.viewer?.like ? 1 : 0
const nextExpectedLikeValue = React.useRef(likeValue)
const [isToggleLikeIcon, setIsToggleLikeIcon] = React.useState(false)

const onPressToggleLike = React.useCallback(async () => {
if (isBlocked) {
Expand All @@ -119,8 +118,8 @@ let PostCtrls = ({
}

try {
setIsToggleLikeIcon(true)
if (!post.viewer?.like) {
nextExpectedLikeValue.current = 1
playHaptic()
sendInteraction({
item: post.uri,
Expand All @@ -130,7 +129,6 @@ let PostCtrls = ({
captureAction(ProgressGuideAction.Like)
await queueLike()
} else {
nextExpectedLikeValue.current = 0
await queueUnlike()
}
} catch (e: any) {
Expand Down Expand Up @@ -317,11 +315,16 @@ let PostCtrls = ({
}
accessibilityHint=""
hitSlop={POST_CTRL_HITSLOP}>
<AnimatedLikeIcon isLiked={Boolean(post.viewer?.like)} big={big} />
<AnimatedLikeIcon
isLiked={Boolean(post.viewer?.like)}
big={big}
isToggle={isToggleLikeIcon}
/>
<CountWheel
likeCount={post.likeCount ?? 0}
big={big}
isLiked={Boolean(post.viewer?.like)}
isToggle={isToggleLikeIcon}
/>
</Pressable>
</View>
Expand Down

0 comments on commit 0014d43

Please sign in to comment.