({
children,
size = defaultSize,
style,
theme: themeOverrides,
visible = true,
...rest
}: Props)
| 52 | * ``` |
| 53 | */ |
| 54 | const Badge = ({ |
| 55 | children, |
| 56 | size = defaultSize, |
| 57 | style, |
| 58 | theme: themeOverrides, |
| 59 | visible = true, |
| 60 | ...rest |
| 61 | }: Props) => { |
| 62 | const theme = useInternalTheme(themeOverrides); |
| 63 | const { current: opacity } = React.useRef<Animated.Value>( |
| 64 | new Animated.Value(visible ? 1 : 0) |
| 65 | ); |
| 66 | const { fontScale } = useWindowDimensions(); |
| 67 | |
| 68 | const isFirstRendering = React.useRef<boolean>(true); |
| 69 | |
| 70 | const { |
| 71 | animation: { scale }, |
| 72 | } = theme; |
| 73 | |
| 74 | React.useEffect(() => { |
| 75 | // Do not run animation on very first rendering |
| 76 | if (isFirstRendering.current) { |
| 77 | isFirstRendering.current = false; |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | Animated.timing(opacity, { |
| 82 | toValue: visible ? 1 : 0, |
| 83 | duration: 150 * scale, |
| 84 | useNativeDriver: true, |
| 85 | }).start(); |
| 86 | }, [visible, opacity, scale]); |
| 87 | |
| 88 | const { |
| 89 | backgroundColor = theme.isV3 |
| 90 | ? theme.colors.error |
| 91 | : theme.colors?.notification, |
| 92 | ...restStyle |
| 93 | } = (StyleSheet.flatten(style) || {}) as TextStyle; |
| 94 | |
| 95 | const textColor = theme.isV3 |
| 96 | ? theme.colors.onError |
| 97 | : getContrastingColor(backgroundColor, white, black); |
| 98 | |
| 99 | const borderRadius = size / 2; |
| 100 | |
| 101 | const paddingHorizontal = theme.isV3 ? 3 : 4; |
| 102 | |
| 103 | return ( |
| 104 | <Animated.Text |
| 105 | numberOfLines={1} |
| 106 | style={[ |
| 107 | { |
| 108 | opacity, |
| 109 | backgroundColor, |
| 110 | color: textColor, |
| 111 | fontSize: size * 0.5, |
nothing calls this directly
no test coverage detected
searching dependent graphs…