mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-02 09:08:58 +08:00
Add setPageWithoutAnimation
Summary: In some cases it's desirable to set the page in the ViewPager without animating it -- we have this in ScrollView with `scrollWithoutAnimationTo`. This PR adds `setPageWithoutAnimation` on ViewPager. cc ide kmagiera Closes https://github.com/facebook/react-native/pull/3621 Reviewed By: svcscm Differential Revision: D2652056 Pulled By: mkonicek fb-gh-sync-id: 6f1f38558c41ffdd863c0ebb2f046c75b5c0392c
This commit is contained in:
committed by
facebook-github-bot-3
parent
88a92f8f52
commit
50b8b00768
@@ -96,23 +96,39 @@ var ViewPagerAndroidExample = React.createClass({
|
||||
description: 'Container that allows to flip left and right between child views.'
|
||||
},
|
||||
getInitialState: function() {
|
||||
return {page: 0, progress: {position: 0, offset: 0}};
|
||||
return {
|
||||
page: 0,
|
||||
animationsAreEnabled: true,
|
||||
progress: {
|
||||
position: 0,
|
||||
offset: 0,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
onPageSelected: function(e) {
|
||||
this.setState({page: e.nativeEvent.position});
|
||||
},
|
||||
|
||||
onPageScroll: function(e) {
|
||||
this.setState({progress: e.nativeEvent});
|
||||
},
|
||||
|
||||
move: function(delta) {
|
||||
var page = this.state.page + delta;
|
||||
this.viewPager && this.viewPager.setPage(page);
|
||||
this.setState({page});
|
||||
this.go(page);
|
||||
},
|
||||
|
||||
go: function(page) {
|
||||
this.viewPager && this.viewPager.setPage(page);
|
||||
if (this.state.animationsAreEnabled) {
|
||||
this.viewPager.setPage(page);
|
||||
} else {
|
||||
this.viewPager.setPageWithoutAnimation(page);
|
||||
}
|
||||
|
||||
this.setState({page});
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var pages = [];
|
||||
for (var i = 0; i < PAGES; i++) {
|
||||
@@ -131,7 +147,7 @@ var ViewPagerAndroidExample = React.createClass({
|
||||
</View>
|
||||
);
|
||||
}
|
||||
var page = this.state.page;
|
||||
var { page, animationsAreEnabled } = this.state;
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<ViewPagerAndroid
|
||||
@@ -142,6 +158,19 @@ var ViewPagerAndroidExample = React.createClass({
|
||||
ref={viewPager => { this.viewPager = viewPager; }}>
|
||||
{pages}
|
||||
</ViewPagerAndroid>
|
||||
<View style={styles.buttons}>
|
||||
{ animationsAreEnabled ?
|
||||
<Button
|
||||
text="Turn off animations"
|
||||
enabled={true}
|
||||
onPress={() => this.setState({animationsAreEnabled: false})}
|
||||
/> :
|
||||
<Button
|
||||
text="Turn animations back on"
|
||||
enabled={true}
|
||||
onPress={() => this.setState({animationsAreEnabled: true})}
|
||||
/> }
|
||||
</View>
|
||||
<View style={styles.buttons}>
|
||||
<Button text="Start" enabled={page > 0} onPress={() => this.go(0)}/>
|
||||
<Button text="Prev" enabled={page > 0} onPress={() => this.move(-1)}/>
|
||||
|
||||
Reference in New Issue
Block a user