$ git show badge-bounce
Notification badge
When the unread count goes up, the badge pops and the bell gives a little wiggle.
🔔3
// Reanimated 4: keying on count remounts both views, so their CSS keyframes replay on every change
const pop = {
'0%': { transform: [{ scale: 1 }] },
'30%': { transform: [{ scale: 1.45 }] },
'60%': { transform: [{ scale: 0.88 }] },
'100%': { transform: [{ scale: 1 }] },
};
const wiggle = {
'0%': { transform: [{ rotate: '0deg' }] },
'20%': { transform: [{ rotate: '14deg' }] },
'45%': { transform: [{ rotate: '-12deg' }] },
'70%': { transform: [{ rotate: '8deg' }] },
'100%': { transform: [{ rotate: '0deg' }] },
};
<View>
<Animated.View
key={'bell-' + count}
style={{ transformOrigin: 'top', animationName: wiggle, animationDuration: '400ms' }}>
<BellIcon />
</Animated.View>
{count > 0 && (
<Animated.View
key={count}
style={[styles.badge, styles.badgePosition, {
animationName: pop,
animationDuration: '400ms',
animationTimingFunction: 'ease-out',
}]}>
<Text style={styles.badgeText}>{count > 99 ? '99+' : count}</Text>
</Animated.View>
)}
</View>