Skip to content

Commit

Permalink
fix: segmented-control without active style in version 1.x, ref #1832
Browse files Browse the repository at this point in the history
  • Loading branch information
silentcloud committed Sep 12, 2017
1 parent cadc4b6 commit c88610e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ exports[`renders ./components/segmented-control/demo/basic.md correctly 1`] = `
>
<div
class="am-segment-item-inner"
style="background-color:#ff0000;"
/>
切换一
</div>
Expand All @@ -149,6 +150,7 @@ exports[`renders ./components/segmented-control/demo/basic.md correctly 1`] = `
>
<div
class="am-segment-item-inner"
style="background-color:#ff0000;"
/>
切换二
</div>
Expand All @@ -161,6 +163,7 @@ exports[`renders ./components/segmented-control/demo/basic.md correctly 1`] = `
>
<div
class="am-segment-item-inner"
style="background-color:#ff0000;"
/>
切换三
</div>
Expand Down
6 changes: 5 additions & 1 deletion components/segmented-control/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export default class SegmentedControl extends React.Component<SegmentedControlPr
borderColor: tintColor,
};

const activeInnerStyle: any = tintColor ? {
backgroundColor: tintColor,
} : {};

return (
<Touchable
key={idx}
Expand All @@ -77,7 +81,7 @@ export default class SegmentedControl extends React.Component<SegmentedControlPr
aria-disabled={disabled}
onClick={disabled ? undefined : (e) => this.onClick(e, idx, value)}
>
<div className={`${prefixCls}-item-inner`} />
<div className={`${prefixCls}-item-inner`} style={activeInnerStyle} />
{value}
</div>
</Touchable>
Expand Down
27 changes: 19 additions & 8 deletions components/segmented-control/segmented.android.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { View, Text, TouchableWithoutFeedback } from 'react-native';
import { View, Text, TouchableHighlight } from 'react-native';
import setNormalizedColorAlpha from 'react-native/Libraries/StyleSheet/setNormalizedColorAlpha';
import normalizeColor from 'react-native/Libraries/StyleSheet/normalizeColor';
import SegmentedControlProps from './PropsType';
import AndroidStyle, { ISegmentControlStyle } from './style/';

Expand Down Expand Up @@ -68,14 +70,23 @@ export default class SegmentedControl extends React.Component<ISegmentControlNat
borderColor: tintColor,
}];

const underlayColor = idx === selectedIndex ? tintColor : setNormalizedColorAlpha(
normalizeColor(tintColor), 0.3,
);

return (
<TouchableWithoutFeedback key={idx} onPress={(e?: any) => this.onPress(e, idx, value)}>
<View style={itemStyle} >
<Text style={[styles.itemText, { color: idx === selectedIndex ? '#fff' : tintColor }]}>
{value}
</Text>
</View>
</TouchableWithoutFeedback>
<TouchableHighlight
key={idx}
disabled={disabled}
onPress={(e?: any) => this.onPress(e, idx, value)}
underlayColor={underlayColor}
style={itemStyle}
activeOpacity={1}
>
<Text style={[styles.itemText, { color: idx === selectedIndex ? '#fff' : tintColor }]}>
{value}
</Text>
</TouchableHighlight>
);
});

Expand Down
1 change: 1 addition & 0 deletions components/segmented-control/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
width: 100%;
opacity: 0.1;
transition: background .2s;
background-color: @segmented-control-color;
}
}
}
Expand Down

0 comments on commit c88610e

Please sign in to comment.