|
1 | 1 | import React, {useMemo} from 'react'; |
2 | | -import Animated, {FadeIn, FadeOut, LinearTransition} from 'react-native-reanimated'; |
| 2 | +import Animated, {LinearTransition} from 'react-native-reanimated'; |
3 | 3 |
|
4 | | -import {DoneIcon} from '../../icons'; |
5 | 4 | import {useTheme} from '../../theme/useTheme.hook'; |
6 | 5 | import {type IconProps} from '../../icons/icon-props'; |
7 | 6 | import {getDynamicStyles, styles} from './filter-chip.styles'; |
8 | 7 | import {BaseChip, type BaseChipProps} from '../base-chip/BaseChip.component'; |
9 | 8 | import {CircularActivityIndicator} from '../../activity-indicators/circular-activity-indicator/CircularActivityIndicator.component'; |
| 9 | +import {FilterChipLeadingIcon} from './leading-icon/FilterChipLeadingIcon.component'; |
10 | 10 |
|
11 | 11 | export interface FilterChipProps<T extends IconProps> extends Omit<BaseChipProps, 'leadingIcon' | 'trailingIcon'> { |
12 | 12 | elevated?: boolean; |
@@ -38,30 +38,25 @@ export const FilterChip = <T extends IconProps>({ |
38 | 38 | const theme = useTheme(); |
39 | 39 | const dynamicStyles = useMemo(() => getDynamicStyles(selected, elevated, disabled, theme), [disabled, elevated, selected, theme]); |
40 | 40 |
|
41 | | - const renerCustomLeadingIcon = () => |
42 | | - LeadingIcon ? ( |
43 | | - <Animated.View entering={FadeIn} exiting={FadeOut}> |
44 | | - <LeadingIcon size={iconSize} color={dynamicStyles.icon.color} {...leadingIconProps} /> |
45 | | - </Animated.View> |
46 | | - ) : null; |
47 | | - |
48 | | - const renderLeadingIcon = () => |
49 | | - selected ? ( |
50 | | - <Animated.View entering={FadeIn} exiting={FadeOut}> |
51 | | - <DoneIcon size={iconSize} color={dynamicStyles.selectedIcon.color} /> |
52 | | - </Animated.View> |
53 | | - ) : ( |
54 | | - renerCustomLeadingIcon() |
55 | | - ); |
| 41 | + const leadingIcon = loading ? ( |
| 42 | + <CircularActivityIndicator size={activityIndicatorSize} style={{height: iconSize, width: iconSize}} /> |
| 43 | + ) : ( |
| 44 | + <FilterChipLeadingIcon |
| 45 | + size={iconSize} |
| 46 | + selected={selected} |
| 47 | + customLeadingIcon={LeadingIcon} |
| 48 | + color={dynamicStyles.icon.color} |
| 49 | + selectedColor={dynamicStyles.selectedIcon.color} |
| 50 | + leadingIconProps={leadingIconProps} |
| 51 | + /> |
| 52 | + ); |
56 | 53 |
|
57 | 54 | return ( |
58 | 55 | <Animated.View layout={LinearTransition}> |
59 | 56 | <BaseChip |
60 | 57 | style={[elevated && !disabled ? styles.elevatedContainer : styles.outlinedContainer, dynamicStyles.container, style]} |
61 | 58 | labelStyle={[dynamicStyles.label, labelStyle]} |
62 | | - leadingIcon={ |
63 | | - loading ? <CircularActivityIndicator size={activityIndicatorSize} style={{height: iconSize, width: iconSize}} /> : renderLeadingIcon() |
64 | | - } |
| 59 | + leadingIcon={leadingIcon} |
65 | 60 | trailingIcon={TrailingIcon ? <TrailingIcon size={18} color={dynamicStyles.icon.color} {...trailingIconProps} /> : null} |
66 | 61 | disabled={disabled} |
67 | 62 | {...props} |
|
0 commit comments