Fix thin red circle around Like button on iOS (#6123)

* remove animation UI from DOM tree when not animated

* improve naming of vars

* more var changes

---------

Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
khuddite
2024-11-06 07:36:31 -05:00
committed by GitHub
parent 206df2ab80
commit f95acdc836
3 changed files with 14 additions and 17 deletions
+3 -3
View File
@@ -91,15 +91,15 @@ export function CountWheel({
likeCount, likeCount,
big, big,
isLiked, isLiked,
isToggle, hasBeenToggled,
}: { }: {
likeCount: number likeCount: number
big?: boolean big?: boolean
isLiked: boolean isLiked: boolean
isToggle: boolean hasBeenToggled: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const shouldAnimate = !useReducedMotion() && isToggle const shouldAnimate = !useReducedMotion() && hasBeenToggled
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
+6 -10
View File
@@ -71,15 +71,15 @@ const circle2Keyframe = new Keyframe({
export function AnimatedLikeIcon({ export function AnimatedLikeIcon({
isLiked, isLiked,
big, big,
isToggle, hasBeenToggled,
}: { }: {
isLiked: boolean isLiked: boolean
big?: boolean big?: boolean
isToggle: boolean hasBeenToggled: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const size = big ? 22 : 18 const size = big ? 22 : 18
const shouldAnimate = !useReducedMotion() && isToggle const shouldAnimate = !useReducedMotion() && hasBeenToggled
return ( return (
<View> <View>
@@ -95,12 +95,10 @@ export function AnimatedLikeIcon({
width={size} width={size}
/> />
)} )}
{isLiked ? ( {isLiked && shouldAnimate ? (
<> <>
<Animated.View <Animated.View
entering={ entering={circle1Keyframe.duration(300)}
shouldAnimate ? circle1Keyframe.duration(300) : undefined
}
style={{ style={{
position: 'absolute', position: 'absolute',
backgroundColor: s.likeColor.color, backgroundColor: s.likeColor.color,
@@ -114,9 +112,7 @@ export function AnimatedLikeIcon({
}} }}
/> />
<Animated.View <Animated.View
entering={ entering={circle2Keyframe.duration(300)}
shouldAnimate ? circle2Keyframe.duration(300) : undefined
}
style={{ style={{
position: 'absolute', position: 'absolute',
backgroundColor: t.atoms.bg.backgroundColor, backgroundColor: t.atoms.bg.backgroundColor,
+5 -4
View File
@@ -107,7 +107,8 @@ let PostCtrls = ({
[t], [t],
) as StyleProp<ViewStyle> ) as StyleProp<ViewStyle>
const [isToggleLikeIcon, setIsToggleLikeIcon] = React.useState(false) const [hasLikeIconBeenToggled, setHasLikeIconBeenToggled] =
React.useState(false)
const onPressToggleLike = React.useCallback(async () => { const onPressToggleLike = React.useCallback(async () => {
if (isBlocked) { if (isBlocked) {
@@ -119,7 +120,7 @@ let PostCtrls = ({
} }
try { try {
setIsToggleLikeIcon(true) setHasLikeIconBeenToggled(true)
if (!post.viewer?.like) { if (!post.viewer?.like) {
playHaptic('Light') playHaptic('Light')
sendInteraction({ sendInteraction({
@@ -311,13 +312,13 @@ let PostCtrls = ({
<AnimatedLikeIcon <AnimatedLikeIcon
isLiked={Boolean(post.viewer?.like)} isLiked={Boolean(post.viewer?.like)}
big={big} big={big}
isToggle={isToggleLikeIcon} hasBeenToggled={hasLikeIconBeenToggled}
/> />
<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} hasBeenToggled={hasLikeIconBeenToggled}
/> />
</Pressable> </Pressable>
</View> </View>