From 22fa3befcf46ee9a916433cee5ea023f6404a759 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Fri, 13 Nov 2015 08:03:54 -0800 Subject: [PATCH] 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 --- .../ViewPagerAndroidExample.android.js | 39 +++++++++-- .../ViewPager/ViewPagerAndroid.android.js | 68 +++++++++++-------- .../react/views/viewpager/ReactViewPager.java | 12 ++-- .../viewpager/ReactViewPagerManager.java | 47 +++++++++++-- 4 files changed, 121 insertions(+), 45 deletions(-) diff --git a/Examples/UIExplorer/ViewPagerAndroidExample.android.js b/Examples/UIExplorer/ViewPagerAndroidExample.android.js index 8dcbbb06ec67bc..e4f33458e95b36 100644 --- a/Examples/UIExplorer/ViewPagerAndroidExample.android.js +++ b/Examples/UIExplorer/ViewPagerAndroidExample.android.js @@ -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({ ); } - var page = this.state.page; + var { page, animationsAreEnabled } = this.state; return ( { this.viewPager = viewPager; }}> {pages} + + { animationsAreEnabled ? +