Skip to content

Commit f317cf4

Browse files
committed
v1.0.8
1 parent b73cfdd commit f317cf4

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Example/AnimatedSegmentControl/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class App extends Component {
1111
return (
1212
<View style={styles.container}>
1313
<SegmentControl
14-
values={['Segment1', 'Segment2', 'Segment3']}
15-
selectedIndex={0}
14+
values={['Segment1', 'Segment2', 'Segment3', 'Segment4',]}
15+
selectedIndex={1}
1616
onChange={this.onSegmentValueChange}
1717
/>
1818
</View>

Example/AnimatedSegmentControl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"react": "16.8.3",
1111
"react-native": "0.59.10",
12-
"react-native-animated-segment-control": "^1.0.7"
12+
"react-native-animated-segment-control": "^1.0.8"
1313
},
1414
"devDependencies": {
1515
"@babel/core": "^7.5.4",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-animated-segment-control",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "A custom `SegmentControl` component, pretty much similar to native's SegmentControl but with animation",
55
"main": "index.js",
66
"scripts": {

src/SegmentControl/index.android.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SegmentControl extends React.Component {
3939
this.setState(
4040
prevState => ({
4141
selectedIndex: index,
42-
activeSegmentPosition: { x: prevState.segmentDimension.width * (index - 1), y: 0 }
42+
activeSegmentPosition: { x: -(this.state.segmentDimension.width * (this.props.values.length / 2 - 0.5)) + this.state.segmentDimension.width * index, y: prevState.activeSegmentPosition.y }
4343
}),
4444
animate
4545
)
@@ -56,7 +56,7 @@ class SegmentControl extends React.Component {
5656

5757
const animate = () => {
5858
Animated.timing(this.state.positionAnimationValue, {
59-
toValue: segmentWidth * (this.state.selectedIndex - 1),
59+
toValue: -(segmentWidth * (this.props.values.length / 2 - 0.5)) + segmentWidth * this.state.selectedIndex,
6060
duration: 100
6161
}).start()
6262
}

0 commit comments

Comments
 (0)