MCPcopy
hub / github.com/callstack/react-native-paper / Badge

Function Badge

src/components/Badge.tsx:54–127  ·  view source on GitHub ↗
({
  children,
  size = defaultSize,
  style,
  theme: themeOverrides,
  visible = true,
  ...rest
}: Props)

Source from the content-addressed store, hash-verified

52 * ```
53 */
54const 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,

Callers

nothing calls this directly

Calls 2

useInternalThemeFunction · 0.90
getContrastingColorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…