1
1
import React , { useCallback , useMemo } from 'react' ;
2
- import { LayoutChangeEvent , ImageSourcePropType , ImageStyle , StyleProp , ViewStyle } from 'react-native' ;
2
+ import { LayoutChangeEvent , ImageStyle , StyleProp , ViewStyle } from 'react-native' ;
3
3
import Reanimated , { useAnimatedStyle } from 'react-native-reanimated' ;
4
4
import { Spacings , Typography } from '../../style' ;
5
5
import { asBaseComponent } from '../../commons/new' ;
6
6
import TouchableOpacity from '../touchableOpacity' ;
7
7
import { SegmentedControlProps } from './index' ;
8
+ import Icon , { IconProps } from '../icon' ;
8
9
9
10
export type SegmentedControlItemProps = Pick < SegmentedControlProps , 'segmentLabelStyle' > & {
10
11
/**
@@ -14,7 +15,7 @@ export type SegmentedControlItemProps = Pick<SegmentedControlProps, 'segmentLabe
14
15
/**
15
16
* An icon for the segment.
16
17
*/
17
- iconSource ?: ImageSourcePropType ;
18
+ iconSource ?: IconProps [ 'source' ] ;
18
19
/**
19
20
* An icon for the segment.
20
21
*/
@@ -82,6 +83,8 @@ const Segment = React.memo((props: SegmentProps) => {
82
83
iconTintColor
83
84
} = props ;
84
85
86
+ const AnimatedUIIcon = Reanimated . createAnimatedComponent ( Icon ) ;
87
+
85
88
const animatedTextStyle = useAnimatedStyle ( ( ) => {
86
89
const color = selectedIndex ?. value === index ? activeColor : inactiveColor ;
87
90
return { color} ;
@@ -97,8 +100,7 @@ const Segment = React.memo((props: SegmentProps) => {
97
100
} , [ style ] ) ;
98
101
99
102
const renderIcon = useCallback ( ( ) => {
100
- return iconSource && < Reanimated . Image source = { iconSource } style = { [ animatedIconStyle , iconStyle ] } /> ;
101
- // eslint-disable-next-line react-hooks/exhaustive-deps
103
+ return iconSource && < AnimatedUIIcon source = { iconSource } style = { [ animatedIconStyle , iconStyle ] } /> ;
102
104
} , [ iconSource , iconStyle ] ) ;
103
105
104
106
const onSegmentPress = useCallback ( ( ) => {
0 commit comments