npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-parallax-swiper

v1.1.7

Published

Full Screen Parallax Swiper Allowing Arbitrary UI Injection

Downloads

137

Readme

React Native Parallax Swiper

npm npm styled with prettier

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.
  • Progress Bar. Horizontal or vertical progress bar.

Twitter Moments Demo
Vevo Demo
Lightbox Demo

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 React from "react";
import {
  Animated,
  Text,
  View,
  Image,
  StyleSheet,
  Dimensions
} from "react-native";

import {
  ParallaxSwiper,
  ParallaxSwiperPage
} from "react-native-parallax-swiper";

const { width, height } = Dimensions.get("window");

export default class App extends React.Component {
  myCustomAnimatedValue = new Animated.Value(0);

  getPageTransformStyle = index => ({
    transform: [
      {
        scale: this.myCustomAnimatedValue.interpolate({
          inputRange: [
            (index - 1) * (width + 8), // Add 8 for dividerWidth
            index * (width + 8),
            (index + 1) * (width + 8)
          ],
          outputRange: [0, 1, 0],
          extrapolate: "clamp"
        })
      },
      {
        rotate: this.myCustomAnimatedValue.interpolate({
          inputRange: [
            (index - 1) * (width + 8),
            index * (width + 8),
            (index + 1) * (width + 8)
          ],
          outputRange: ["180deg", "0deg", "-180deg"],
          extrapolate: "clamp"
        })
      }
    ]
  });

  render() {
    return (
      <ParallaxSwiper
        speed={0.5}
        animatedValue={this.myCustomAnimatedValue}
        dividerWidth={8}
        dividerColor="black"
        backgroundColor="black"
        onMomentumScrollEnd={activePageIndex => console.log(activePageIndex)}
        showProgressBar={true}
        progressBarBackgroundColor="rgba(0,0,0,0.25)"
        progressBarValueBackgroundColor="white"
      >
        <ParallaxSwiperPage
          BackgroundComponent={
            <Image
              style={styles.backgroundImage}
              source={{ uri: "https://goo.gl/wtHtxG" }}
            />
          }
          ForegroundComponent={
            <View style={styles.foregroundTextContainer}>
              <Animated.Text
                style={[styles.foregroundText, this.getPageTransformStyle(0)]}
              >
                Page 1
              </Animated.Text>
            </View>
          }
        />
        <ParallaxSwiperPage
          BackgroundComponent={
            <Image
              style={styles.backgroundImage}
              source={{ uri: "https://goo.gl/gt4rWa" }}
            />
          }
          ForegroundComponent={
            <View style={styles.foregroundTextContainer}>
              <Animated.Text
                style={[styles.foregroundText, this.getPageTransformStyle(1)]}
              >
                Page 2
              </Animated.Text>
            </View>
          }
        />
        <ParallaxSwiperPage
          BackgroundComponent={
            <Image
              style={styles.backgroundImage}
              source={{ uri: "https://goo.gl/KAaVXt" }}
            />
          }
          ForegroundComponent={
            <View style={styles.foregroundTextContainer}>
              <Animated.Text
                style={[styles.foregroundText, this.getPageTransformStyle(2)]}
              >
                Page 3
              </Animated.Text>
            </View>
          }
        />
      </ParallaxSwiper>
    );
  }
}

const styles = StyleSheet.create({
  backgroundImage: {
    width,
    height
  },
  foregroundTextContainer: {
    flex: 1,
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: "transparent"
  },
  foregroundText: {
    fontSize: 34,
    fontWeight: "700",
    letterSpacing: 0.41,
    color: "white"
  }
});

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 | Number | 0 | Scroll to page with a smooth animation. Note: You need to use state if you want to change index any other time than when component is rendered. | | 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. | | showProgressBar | Boolean | false | When true, a progress bar will render on bottom for horizontal and left on vertical. | | progressBarThickness | Number | 4 | Thickness translates to height for horizontal and width for vertical progress bar. | | progressBarBackgroundColor | String | rgba(255,255,255,0.25) | Background color of progress bar background. | | progressBarValueBackgroundColor | String | white | Background color of progress bar value background. |

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

  • [x] Create Expo demos
  • [x] Create examples
  • [x] Expose current index
  • [x] Support scrollToIndex
  • [x] Fix Android
  • [x] Expose Animated.Value for animation outside of ParallaxSwiper
  • [ ] Add drag effects e.g. zoom, blur, darken
  • [ ] Expose rest of ScrollView props
  • [ ] Use FlatList instead of ScrollView

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

| Chris LeBlanc[💻] | | :-----------------------------------------------------------------------------------------------------------------------------------------------------------: |

Questions or suggestions?

Hit me up on Twitter, or create an issue.

Copyright

Copyright (c) 2017 Zachary Gibson Licensed under the MIT license.