({
mode = 'flat',
children,
icon,
avatar,
selected = false,
disabled = false,
background,
accessibilityLabel,
accessibilityRole = 'button',
closeIconAccessibilityLabel = 'Close',
onPress,
onLongPress,
onPressOut,
onPressIn,
delayLongPress,
onClose,
closeIcon,
textStyle,
style,
theme: themeOverrides,
testID = 'chip',
selectedColor,
rippleColor: customRippleColor,
showSelectedOverlay = false,
showSelectedCheck = true,
ellipsizeMode,
compact,
elevated = false,
maxFontSizeMultiplier,
hitSlop,
...rest
}: Props)
| 179 | * ``` |
| 180 | */ |
| 181 | const Chip = ({ |
| 182 | mode = 'flat', |
| 183 | children, |
| 184 | icon, |
| 185 | avatar, |
| 186 | selected = false, |
| 187 | disabled = false, |
| 188 | background, |
| 189 | accessibilityLabel, |
| 190 | accessibilityRole = 'button', |
| 191 | closeIconAccessibilityLabel = 'Close', |
| 192 | onPress, |
| 193 | onLongPress, |
| 194 | onPressOut, |
| 195 | onPressIn, |
| 196 | delayLongPress, |
| 197 | onClose, |
| 198 | closeIcon, |
| 199 | textStyle, |
| 200 | style, |
| 201 | theme: themeOverrides, |
| 202 | testID = 'chip', |
| 203 | selectedColor, |
| 204 | rippleColor: customRippleColor, |
| 205 | showSelectedOverlay = false, |
| 206 | showSelectedCheck = true, |
| 207 | ellipsizeMode, |
| 208 | compact, |
| 209 | elevated = false, |
| 210 | maxFontSizeMultiplier, |
| 211 | hitSlop, |
| 212 | ...rest |
| 213 | }: Props) => { |
| 214 | const theme = useInternalTheme(themeOverrides); |
| 215 | const { isV3, roundness } = theme; |
| 216 | const isWeb = Platform.OS === 'web'; |
| 217 | |
| 218 | const { current: elevation } = React.useRef<Animated.Value>( |
| 219 | new Animated.Value(isV3 && elevated ? 1 : 0) |
| 220 | ); |
| 221 | |
| 222 | const hasPassedTouchHandler = hasTouchHandler({ |
| 223 | onPress, |
| 224 | onLongPress, |
| 225 | onPressIn, |
| 226 | onPressOut, |
| 227 | }); |
| 228 | |
| 229 | const isOutlined = mode === 'outlined'; |
| 230 | |
| 231 | const handlePressIn = useLatestCallback((e: GestureResponderEvent) => { |
| 232 | const { scale } = theme.animation; |
| 233 | onPressIn?.(e); |
| 234 | Animated.timing(elevation, { |
| 235 | toValue: isV3 ? (elevated ? 2 : 0) : 4, |
| 236 | duration: 200 * scale, |
| 237 | useNativeDriver: |
| 238 | isWeb || Platform.constants.reactNativeVersion.minor <= 72, |
nothing calls this directly
no test coverage detected
searching dependent graphs…