@@ -3,12 +3,16 @@ import { ViewStyle, TextStyle, Text } from 'react-native';
3
3
import ButtonGroup , { ButtonGroupProps } from '../ButtonGroup' ;
4
4
import Button from '../Button' ;
5
5
6
+ interface textColorType {
7
+ actived ?: string ;
8
+ unactived ?: string ;
9
+ }
6
10
export interface SegmentedControlProps < T > extends ButtonGroupProps {
7
11
value ?: string [ ] | T [ ] ;
8
12
selectedIndex ?: number ;
9
13
renderItem ?: ( label : string | T , selectedIndex : number , props : ButtonGroupProps ) => JSX . Element ;
10
14
onValueChange ?: ( label : string | T , selectedIndex : number ) => void ;
11
- textColor ?: [ string , string ] ;
15
+ textColor ?: textColorType ;
12
16
}
13
17
14
18
export interface SegmentedControlState {
@@ -40,7 +44,10 @@ export default class SegmentedControl<T> extends Component<SegmentedControlProps
40
44
value,
41
45
selectedIndex,
42
46
renderItem,
43
- textColor = [ '#fff' , this . props . color ?? '#108ee9' ] ,
47
+ textColor = {
48
+ actived : '#fff' ,
49
+ unactived : this . props . color ?? '#108ee9' ,
50
+ } ,
44
51
...otherProps
45
52
} = this . props ;
46
53
return (
@@ -49,11 +56,11 @@ export default class SegmentedControl<T> extends Component<SegmentedControlProps
49
56
( value as ( string | T ) [ ] ) . map ( ( label : string | T , key : number ) => {
50
57
const styl : ViewStyle = { } ;
51
58
const textStyle : TextStyle = { } ;
52
- let textStyleColor : string = textColor [ 0 ] ;
59
+ let textStyleColor : string = textColor . actived ! ;
53
60
if ( this . state . selectedIndex !== key + 1 ) {
54
61
styl . backgroundColor = '#fff' ;
55
62
textStyle . color = otherProps . color ;
56
- textStyleColor = textColor [ 1 ] ;
63
+ textStyleColor = textColor . unactived ! ;
57
64
}
58
65
const props : ButtonGroupProps = {
59
66
type : 'primary' ,
0 commit comments