leecade / leecade/react-native-swiper
Dynamic slides - working on Ios but not on Android
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
Thank you for your great job, leecade!
I tested the dynamic slides option. It's working perfectly on Ios but not really on Android.
Here an example for your reproduction: swipe to the right is possible only 4 times, left is also restricted.
import React, { Component } from 'react';
import ReactNative, { AppRegistry, StyleSheet, Text, View} from 'react-native';
import Swiper from 'react-native-swiper';
var test = React.createClass({
getInitialState: function() {
return {
// on android swiper starts with last view
index: (ReactNative.Platform.OS === 'ios') ? 0 : 2,
// the last active index
lastIndex: 0,
// 3 virtual slides
items: [{},{},{}],
};
},
render: function() {
return (
<Swiper
showsButtons={false}
showsPagination={false}
onMomentumScrollEnd={this.onMomentumScrollEnd}>
{this.state.items.map((item, key) => this.getVirtualView(item, key))}
</Swiper>
);
},
// gives the direction from last to current slide: prev=-1, next=2, same=0
diff: function(curIndex, newIndex) {
var diff=(newIndex-curIndex+3)%3;
if (diff==2) diff=-1;
return diff;
},
// calc of the new virtual slide index and save last index
onMomentumScrollEnd: function(e, state, context) {
var diff = this.diff(this.state.lastIndex, state.index);
this.setState({lastIndex: state.index});
this.setState({index: this.state.index+diff});
},
// the virtual views only for showing the virtual slide number
getVirtualView: function(item, key) {
return (
<View style={styles.container} key={key}>
<Text style={styles.welcome}>outerIndex = {this.state.index}</Text>
</View>
);
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
AppRegistry.registerComponent('test', () => test);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Swiper component and trace the Android path around dynamic slide rendering and the onMomentumScrollEnd callback, using the supplied reproduction as the test case. Done means the virtual slides can continue swiping in both directions on Android, with behavior matching iOS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100