dont render 0
This commit is contained in:
@@ -106,6 +106,8 @@ export function CountWheel({
|
|||||||
const [key, setKey] = React.useState(0)
|
const [key, setKey] = React.useState(0)
|
||||||
const [prevCount, setPrevCount] = React.useState(likeCount)
|
const [prevCount, setPrevCount] = React.useState(likeCount)
|
||||||
const prevIsLiked = React.useRef(isLiked)
|
const prevIsLiked = React.useRef(isLiked)
|
||||||
|
const formattedCount = formatCount(likeCount)
|
||||||
|
const formattedPrevCount = formatCount(prevCount)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isLiked === prevIsLiked.current) {
|
if (isLiked === prevIsLiked.current) {
|
||||||
@@ -118,9 +120,6 @@ export function CountWheel({
|
|||||||
prevIsLiked.current = isLiked
|
prevIsLiked.current = isLiked
|
||||||
}, [isLiked, likeCount])
|
}, [isLiked, likeCount])
|
||||||
|
|
||||||
const formattedCount = formatCount(likeCount)
|
|
||||||
const formattedPrevCount = formatCount(prevCount)
|
|
||||||
|
|
||||||
const enteringAnimation =
|
const enteringAnimation =
|
||||||
shouldAnimate && shouldRoll
|
shouldAnimate && shouldRoll
|
||||||
? isLiked
|
? isLiked
|
||||||
@@ -136,8 +135,8 @@ export function CountWheel({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<LayoutAnimationConfig skipEntering skipExiting>
|
<LayoutAnimationConfig skipEntering skipExiting>
|
||||||
<View style={[a.justify_center]}>
|
{likeCount > 0 ? (
|
||||||
{likeCount > 0 ? (
|
<View style={[a.justify_center]}>
|
||||||
<Animated.View
|
<Animated.View
|
||||||
entering={enteringAnimation}
|
entering={enteringAnimation}
|
||||||
key={key}
|
key={key}
|
||||||
@@ -154,25 +153,25 @@ export function CountWheel({
|
|||||||
{formattedCount}
|
{formattedCount}
|
||||||
</Text>
|
</Text>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
) : null}
|
<Animated.View
|
||||||
{/* Add 2 to the key so there are never duplicates */}
|
entering={exitingAnimation}
|
||||||
<Animated.View
|
// Add 2 to the key so there are never duplicates
|
||||||
entering={exitingAnimation}
|
key={key + 2}
|
||||||
key={key + 2}
|
style={[a.absolute]}
|
||||||
style={[a.absolute]}
|
aria-disabled={true}>
|
||||||
aria-disabled={true}>
|
<Text
|
||||||
<Text
|
style={[
|
||||||
style={[
|
big ? a.text_md : {fontSize: 15},
|
||||||
big ? a.text_md : {fontSize: 15},
|
a.user_select_none,
|
||||||
a.user_select_none,
|
isLiked
|
||||||
isLiked
|
? [a.font_bold, s.likeColor]
|
||||||
? [a.font_bold, s.likeColor]
|
: {color: t.palette.contrast_500},
|
||||||
: {color: t.palette.contrast_500},
|
]}>
|
||||||
]}>
|
{formattedPrevCount}
|
||||||
{formattedPrevCount}
|
</Text>
|
||||||
</Text>
|
</Animated.View>
|
||||||
</Animated.View>
|
</View>
|
||||||
</View>
|
) : null}
|
||||||
</LayoutAnimationConfig>
|
</LayoutAnimationConfig>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user