Support snapToInterval for horizontal scrollview on Android

Summary:
`snapToInterval` is available on iOS but on android yet. This PR is to add support for `snapToInterval` on android.

Example:

![android_snap](https://cloud.githubusercontent.com/assets/1699429/19086983/39d3ee1c-8a25-11e6-9c84-20f25a751f32.gif)

TO: lelandrichardson spikebrehm
Closes https://github.com/facebook/react-native/pull/10242

Differential Revision: D4168527

fbshipit-source-id: de3dd9ac5d9e0fddfce5e5bc0aa6a4f33f1e30b3
This commit is contained in:
Jimmy Zhuang
2018-01-03 10:26:56 -08:00
committed by Facebook Github Bot
parent a8391bde7d
commit ddd65f1ba9
4 changed files with 42 additions and 5 deletions

View File

@@ -46,6 +46,20 @@ class ScrollViewSimpleExample extends React.Component<{}> {
{this.makeItems(NUM_ITEMS, [styles.itemWrapper, styles.horizontalItemWrapper])}
</ScrollView>
);
items.push(
<ScrollView
key={'scrollViewSnap'}
horizontal
snapToInterval={210}
pagingEnabled
>
{this.makeItems(NUM_ITEMS, [
styles.itemWrapper,
styles.horizontalItemWrapper,
styles.horizontalPagingItemWrapper,
])}
</ScrollView>
);
var verticalScrollView = (
<ScrollView style={styles.verticalScrollView}>
@@ -72,7 +86,10 @@ var styles = StyleSheet.create({
},
horizontalItemWrapper: {
padding: 50
}
},
horizontalPagingItemWrapper: {
width: 200,
},
});
module.exports = ScrollViewSimpleExample;