|
1 |
| -import _ from 'lodash'; |
2 |
| -import React, {useCallback} from 'react'; |
| 1 | +import React, {useCallback, useMemo} from 'react'; |
3 | 2 | import {StyleSheet, StyleProp, ViewStyle, ViewProps, ImageStyle, TextStyle, ImageSourcePropType} from 'react-native';
|
4 | 3 | import Assets from '../../assets';
|
5 | 4 | import {asBaseComponent} from '../../commons/new';
|
@@ -198,7 +197,7 @@ const Chip = ({
|
198 | 197 | <TouchableOpacity
|
199 | 198 | style={[getMargins('dismiss'), dismissContainerStyle]}
|
200 | 199 | onPress={onDismiss}
|
201 |
| - hitSlop={{top: 10, bottom: 10, left: 10, right: 10}} |
| 200 | + hitSlop={{top: 16, bottom: 16, left: 10, right: 10}} |
202 | 201 | testID={`${testID}.dismiss`}
|
203 | 202 | >
|
204 | 203 | <Icon
|
@@ -302,23 +301,37 @@ const Chip = ({
|
302 | 301 | },
|
303 | 302 | [avatarProps, badgeProps, iconSource, rightIconSource, onDismiss]);
|
304 | 303 |
|
305 |
| - const getContainerSize = useCallback(() => { |
306 |
| - const width = useSizeAsMinimum ? 'minWidth' : 'width'; |
307 |
| - const height = useSizeAsMinimum ? 'minHeight' : 'height'; |
308 |
| - |
309 |
| - return typeof size === 'object' |
310 |
| - ? {[width]: _.get(size, 'width'), [height]: _.get(size, 'height')} |
311 |
| - : {[width]: size, [height]: size}; |
| 304 | + const chipSize = useMemo(() => { |
| 305 | + const width = typeof size === 'object' ? size.width : size; |
| 306 | + const height = typeof size === 'object' ? size.height : size; |
| 307 | + return {width, height}; |
312 | 308 | }, [size]);
|
313 | 309 |
|
| 310 | + const containerSizeStyle = useMemo(() => { |
| 311 | + const {width, height} = chipSize; |
| 312 | + return useSizeAsMinimum ? {minWidth: width, minHeight: height} : {width, height}; |
| 313 | + }, [chipSize]); |
| 314 | + |
314 | 315 | const Container = onPress ? TouchableOpacity : View;
|
| 316 | + const hitSlop = useMemo(() => { |
| 317 | + const {width = 48, height = 48} = chipSize; |
| 318 | + const verticalHitSlop = Math.max(0, (48 - height) / 2); |
| 319 | + const horizontalHitSlop = Math.max(0, (48 - width) / 2); |
| 320 | + return { |
| 321 | + top: verticalHitSlop, |
| 322 | + bottom: verticalHitSlop, |
| 323 | + left: horizontalHitSlop, |
| 324 | + right: horizontalHitSlop |
| 325 | + }; |
| 326 | + }, [chipSize]); |
315 | 327 |
|
316 | 328 | return (
|
317 | 329 | <Container
|
318 | 330 | activeOpacity={1}
|
319 | 331 | onPress={onPress}
|
320 |
| - style={[styles.container, {backgroundColor}, {borderRadius}, containerStyle, getContainerSize()]} |
| 332 | + style={[styles.container, {backgroundColor}, {borderRadius}, containerStyle, containerSizeStyle]} |
321 | 333 | testID={testID}
|
| 334 | + hitSlop={hitSlop} |
322 | 335 | {...others}
|
323 | 336 | >
|
324 | 337 | {avatarProps && renderAvatar()}
|
|
0 commit comments