视差反应原生滑动

时间:2018-06-22 11:32:35

标签: reactjs react-native parallax react-native-swiper

有没有一种方法可以将react-native-swiperreact-naitve-parallax-scroll-view组合在一起。我想在视差滚动的前景组件中呈现滑动组件的分页。默认情况下,react native swiper的分页位置固定,当我滚动时,分页停留在屏幕上。我想在向下滚动以隐藏时具有分页的视差效果。分页应位于视差滚动视图的renderForeground中。

<Swiper 
    showsButtons={false}
    loop={false}
    showsPagination={true}
 >

    <ParallaxScrollView
           backgroundColor="transparent"
           contentBackgroundColor="#fff"
           parallaxHeaderHeight={250}
           renderBackground={() => (
                <ImageBackground 
                                source={require('../assets/images/image1.png')}
                                style={{width: '100%', height: 250}}
                            />
                        )}
           renderForeground={() => (
                  <View style={{flex: 1,alignItems: 'center', justifyContent: 'flex-end' }}>
                      <Text>Hello world</Text>     
                   </View>
                    )}>

                   <View style={{ height: 500 }}>
                       <Text>Scroll me</Text>
                    </View>
       </ParallaxScrollView>  
       <ParallaxScrollView
           backgroundColor="transparent"
           contentBackgroundColor="#fff"
           parallaxHeaderHeight={250}
           renderBackground={() => (
                <ImageBackground 
                                source={require('../assets/images/image1.png')}
                                style={{width: '100%', height: 250}}
                            />
                        )}
           renderForeground={() => (
                  <View style={{flex: 1,alignItems: 'center', justifyContent: 'flex-end' }}>
                      <Text>Hello world</Text>     
                   </View>
                    )}>

                   <View style={{ height: 500 }}>
                       <Text>Scroll me</Text>
                    </View>
       </ParallaxScrollView>  
</Swiper>

我找到了react-native-pagination,但不知道在这种情况下如何实现。

2 个答案:

答案 0 :(得分:0)

我认为您应该使用

https://github.com/archriss/react-native-snap-carousel

此轮播在单个组件中同时提供了视差和整页滑动器。最好,对我有帮助

答案 1 :(得分:-1)

尝试了两个组件。你想要这样的东西。 https://snack.expo.io/r1NOE_q-Q