React Native Parallax Swiper
Configurable parallax swiper based on an iOS pattern.
Features
- Flexible. Pass your own Animated.Value and use that value for both ParallaxSwiper and your own UI.
- Performant. Leverages useNativeDriver for 60FPS and no latency.
- Cross-platform. Implement your parallax on both iOS and Android.
Examples
Check out the GIF examples above via Expo. Or clone this repo and:
$ cd examples/ParallaxSwiperExample
$ npm install
$ react-native link
$ react-native run-ios
Installation
$ npm install react-native-parallax-swiper --save
Usage
import { ParallaxSwiper, ParallaxSwiperPage } from 'react-native-parallax-swiper';
constructor() {
super();
this.myCustomAnimatedValue = new Animated.Value(0);
}
<ParallaxSwiper
speed={0.25}
animatedValue={this.myCustomAnimatedValue}
dividerWidth={8}
dividerColor="black"
backgroundColor="#fff"
onMomentumScrollEnd={activePageIndex => console.log(activePageIndex)}
>
<ParallaxSwiperPage
BackgroundComponent={<FireVideoComponent />}
ForegroundComponent={<SickUI />}
/>
<ParallaxSwiperPage
BackgroundComponent={<FireVideoComponent />}
ForegroundComponent={<SickUI />}
/>
<ParallaxSwiperPage
BackgroundComponent={<FireVideoComponent />}
ForegroundComponent={<SickUI />}
/>
</ParallaxSwiper>
ParallaxSwiper Props
Prop | Type | Default | Description |
---|
speed | Number | 0.25 | This number determines how fast BackgroundComponent moves. Set to 0 for no movement at all, set to 1 and background will move as fast as the scroll. |
dividerWidth | Number | 8 | The width of the divider between each page. (horizontal only) |
dividerColor | String | black | Color of divider. |
backgroundColor | String | black | ParallaxSwiper’s background color. |
scrollToIndex | Function | 0 | Scrolls to index with a smooth animation. If used onComponentDidMount scroll is immediate with no animation. |
onMomentumScrollEnd | Function | N/A | Fired when ScrollView stops scrolling and is passed the current page index. |
animatedValue | Number (Animated.Value) | 0 | Optionally pass a new instance of Animated.Value to access the animated value outside of ParallaxSwiper. |
vertical | Boolean | false | When true, ParallaxSwiper’s children are arranged vertically in a column instead of horizontally in a row. For now only iOS supports this. |
showsHorizontalScrollIndicator | Boolean | false | When true, shows a horizontal scroll indicator. The default value is false. |
showsVerticalScrollIndicator | Boolean | false | When true, shows a vertical scroll indicator. The default value is false. |
children | React component (ParallaxSwiperPage) | N/A | Each top-level ParallaxSwiperPage child. |
ParallaxSwiperPage Props
Prop | Type | Default | Description |
---|
BackgroundComponent | React element | N/A | This component will render in the background of the page and will be animated based on scroll. |
ForegroundComponent | React element | N/A | This component will render in the foreground of the page. |
TODO
Why another parallax component? 😒
This component is inspired by an iOS pattern that no react-native-parallax-whatever previously delivered. It emulates this pattern by using the ScrollView component which has features like velocity, paging, and platform specific easing curves; It also has optional dividers to split up each page. You can see this pattern in apps like iOS Camera Roll, Twitter Moments, Kylie Jenner’s app, Vevo’s app, and more.
Contributors
Questions or suggestions?
Hit me up on Twitter, or create an issue.
Copyright
Copyright (c) 2017 Zachary Gibson Licensed under the MIT license.