最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native ScrollView with pagination + showing part of the next page - Stack Overflow

programmeradmin4浏览0评论

I'm trying to create an interface where cards are presented one at a time to the user. The user can scroll left and right in a paged fashion. I also want to view a small amount of the card to the left and the right of the current card, as a hint that there is more to see. A very rough example of this would be:

Current code is:

<ScrollView
   style={{width: Dimensions.get('window').width, height: 300}}
   horizontal={true}
   pagingEnabled={true}
   showsHorizontalScrollIndicator={false}
   alwaysBounceHorizontal={false}
   automaticallyAdjustContentInsets={false}>
    <View style={{width: 200, height: 300}}></View>
    <View style={{width: 200, height: 300}}></View>
    <View style={{width: 200, height: 300}}></View>
 </ScrollView>

I'm trying to create an interface where cards are presented one at a time to the user. The user can scroll left and right in a paged fashion. I also want to view a small amount of the card to the left and the right of the current card, as a hint that there is more to see. A very rough example of this would be:

Current code is:

<ScrollView
   style={{width: Dimensions.get('window').width, height: 300}}
   horizontal={true}
   pagingEnabled={true}
   showsHorizontalScrollIndicator={false}
   alwaysBounceHorizontal={false}
   automaticallyAdjustContentInsets={false}>
    <View style={{width: 200, height: 300}}></View>
    <View style={{width: 200, height: 300}}></View>
    <View style={{width: 200, height: 300}}></View>
 </ScrollView>
Share Improve this question edited Apr 13, 2018 at 8:48 Phonolog 6,5313 gold badges39 silver badges65 bronze badges asked Aug 10, 2017 at 16:19 GiffoGiffo 4,2313 gold badges17 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I think that my answer to this SO question might help you.

To sum up, you absolutely can create this kind of layout with ScrollView or, even better, FlatList. However, there are two tricky parts:

  • The snapping effect, for which you can use props snapToInterval and snapToAlignment. Unfortunately, these are iOS-only.

  • The animation of the inactive slides, which needs a lot of custom logic.

A co-worker and I created a plugin that answers this particular need. We ended up open-sourcing it, so it's all yours to try: react-native-snap-carousel.

The plugin is now built on top of FlatList (versions >= 3.0.0), which is great to handle huge numbers of items. It provides previews (the effect you're after), snapping effect for iOS and Android, parallax images, RTL support, and more.

You can take a look at the showcase to get a grasp of what can be achieved with it. Do not hesitate to share your experience with the plugin since we're always trying to improve it.


Edit : two new layouts have been introduced in version 3.6.0 (one with a stack of cards effect and the other with a tinder-like effect). Enjoy!

发布评论

评论列表(0)

  1. 暂无评论