Skip to content

Commit

Permalink
Fix thin red circle around Like button on iOS (#6123)
Browse files Browse the repository at this point in the history
* remove animation UI from DOM tree when not animated

* improve naming of vars

* more var changes

---------

Co-authored-by: Hailey <[email protected]>
  • Loading branch information
khuddite and haileyok authored Nov 6, 2024
1 parent 206df2a commit f95acdc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/lib/custom-animations/CountWheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export function CountWheel({
likeCount,
big,
isLiked,
isToggle,
hasBeenToggled,
}: {
likeCount: number
big?: boolean
isLiked: boolean
isToggle: boolean
hasBeenToggled: boolean
}) {
const t = useTheme()
const shouldAnimate = !useReducedMotion() && isToggle
const shouldAnimate = !useReducedMotion() && hasBeenToggled
const shouldRoll = decideShouldRoll(isLiked, likeCount)

// Incrementing the key will cause the `Animated.View` to re-render, with the newly selected entering/exiting
Expand Down
16 changes: 6 additions & 10 deletions src/lib/custom-animations/LikeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ const circle2Keyframe = new Keyframe({
export function AnimatedLikeIcon({
isLiked,
big,
isToggle,
hasBeenToggled,
}: {
isLiked: boolean
big?: boolean
isToggle: boolean
hasBeenToggled: boolean
}) {
const t = useTheme()
const size = big ? 22 : 18
const shouldAnimate = !useReducedMotion() && isToggle
const shouldAnimate = !useReducedMotion() && hasBeenToggled

return (
<View>
Expand All @@ -95,12 +95,10 @@ export function AnimatedLikeIcon({
width={size}
/>
)}
{isLiked ? (
{isLiked && shouldAnimate ? (
<>
<Animated.View
entering={
shouldAnimate ? circle1Keyframe.duration(300) : undefined
}
entering={circle1Keyframe.duration(300)}
style={{
position: 'absolute',
backgroundColor: s.likeColor.color,
Expand All @@ -114,9 +112,7 @@ export function AnimatedLikeIcon({
}}
/>
<Animated.View
entering={
shouldAnimate ? circle2Keyframe.duration(300) : undefined
}
entering={circle2Keyframe.duration(300)}
style={{
position: 'absolute',
backgroundColor: t.atoms.bg.backgroundColor,
Expand Down
9 changes: 5 additions & 4 deletions src/view/com/util/post-ctrls/PostCtrls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ let PostCtrls = ({
[t],
) as StyleProp<ViewStyle>

const [isToggleLikeIcon, setIsToggleLikeIcon] = React.useState(false)
const [hasLikeIconBeenToggled, setHasLikeIconBeenToggled] =
React.useState(false)

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

try {
setIsToggleLikeIcon(true)
setHasLikeIconBeenToggled(true)
if (!post.viewer?.like) {
playHaptic('Light')
sendInteraction({
Expand Down Expand Up @@ -311,13 +312,13 @@ let PostCtrls = ({
<AnimatedLikeIcon
isLiked={Boolean(post.viewer?.like)}
big={big}
isToggle={isToggleLikeIcon}
hasBeenToggled={hasLikeIconBeenToggled}
/>
<CountWheel
likeCount={post.likeCount ?? 0}
big={big}
isLiked={Boolean(post.viewer?.like)}
isToggle={isToggleLikeIcon}
hasBeenToggled={hasLikeIconBeenToggled}
/>
</Pressable>
</View>
Expand Down

0 comments on commit f95acdc

Please sign in to comment.