From c22a092b4184b3cfa1b7bc136c999c74c8c06edc Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Tue, 19 Jan 2016 21:29:28 +0100 Subject: [PATCH] Fixes #81 * Added .idea directory to gitignore WebStorm files * Issue #81 was related to missing prop `onPageSelected` on `ViewPagerAndroid` --- .gitignore | 3 +++ dist/index.js | 10 ++++++++++ src/index.js | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/.gitignore b/.gitignore index dafc246..662faa4 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ build/Release *.xcuserstate examples/swiper.xcodeproj/project.xcworkspace/ examples/swiper.xcodeproj/xcuserdata + +# IntelliJ +.idea/ diff --git a/dist/index.js b/dist/index.js index 4fd13fa..118a963 100644 --- a/dist/index.js +++ b/dist/index.js @@ -250,6 +250,15 @@ module.exports = _reactNative2.default.createClass({ isScrolling: false }); + // making our events coming from android compatible to updateIndex logic + if (!e.nativeEvent.contentOffset) { + if (this.state.dir == 'x') { + e.nativeEvent.contentOffset = { x: e.nativeEvent.position * this.state.width }; + } else { + e.nativeEvent.contentOffset = { y: e.nativeEvent.position * this.state.height }; + } + } + this.updateIndex(e.nativeEvent.contentOffset, this.state.dir); // Note: `this.setState` is async, so I call the `onMomentumScrollEnd` @@ -439,6 +448,7 @@ module.exports = _reactNative2.default.createClass({ return _reactNative2.default.createElement( _reactNative.ViewPagerAndroid, { ref: 'scrollView', + onPageSelected: this.onScrollEnd, style: { flex: 1 } }, pages ); diff --git a/src/index.js b/src/index.js index 92fa652..7d8ec3f 100644 --- a/src/index.js +++ b/src/index.js @@ -249,6 +249,15 @@ module.exports = React.createClass({ isScrolling: false }) + // making our events coming from android compatible to updateIndex logic + if (!e.nativeEvent.contentOffset) { + if (this.state.dir == 'x') { + e.nativeEvent.contentOffset = {x: e.nativeEvent.position * this.state.width} + } else { + e.nativeEvent.contentOffset = {y: e.nativeEvent.position * this.state.height} + } + } + this.updateIndex(e.nativeEvent.contentOffset, this.state.dir) // Note: `this.setState` is async, so I call the `onMomentumScrollEnd` @@ -430,6 +439,7 @@ module.exports = React.createClass({ ); return ( {pages}