import { StyleProp, TextStyle, View, ViewStyle } from 'react-native'; import { useColors } from '../../hook'; import { SingleLineText } from '../../ui/Text'; export const gMaxCount = 99; export type BadgesProps = { /** * @description unread count. * - `undefined` means is disturb. * - `0` means no unread count. * - `others` means unread count. */ count?: number; /** * Set the maximum value. Default value is 99. */ maxCount?: number; /** * Text style properties. */ textStyle?: StyleProp; /** * Component container style properties. */ containerStyle?: StyleProp; }; /** * Unread components. */ export function Badges(props: BadgesProps) { const { count, maxCount = gMaxCount, containerStyle, textStyle } = props; const { getColor } = useColors(); const getCount = () => { if (count === undefined || count === 0) { return null; } return count > maxCount ? `${maxCount}+` : count; }; const getSize = (type: 'width' | 'height') => { if (count === 0) { return 0; } else if (count === undefined) { return 8; } else if (count < 10) { return 18; } else { return type === 'width' ? undefined : 18; } }; return ( {getCount()} ); }