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-router-native-animate-stack

v1.3.2

Published

custom animatable stack design from react router native

Downloads

28

Readme

react-router-native-animate-stack

npm version downloads

A latest React version react router native animate stack

purpose of this component

React Router Native v5 with your desired customization transition style! It's design with Animated.View

This package only useable with React Router Native. Use it like a React router native's Switch

Snack Demo

Installation

Install react-router-native and this package:

npm install react-router-native react-router-native-animate-stack --save

OR

yarn add react-router-native react-router-native-animate-stack

Usage

Here's a simple working example of using it.

// When no customization, it is just like a stack
<AnimatedStack
    swipeCancelSpeed={50}
    swipeable={true}>
    <Route exact path='/'>
        <Home />
    </Route>
    <Route path='/about'>
        <About />
    </Route>
    <Route path='/topics' component={Topics} />
</AnimatedStack>

This is what the above code looks like running on iOS simulator:

Default Behaviour

The stack component will trigger gesture swipe forward and backward when passing swipeable true.

If you are familiar with Switch, you will know how to use this.

Customizing Animation your desire animation style

onMountAnimate

when the component mounted, you can defined how you going to animate

onTransitionAnimate

when the component swap between 2 screen, you can animating the view!

activedViewStyleHandler

Enter animation style is the ViewStyle for Enter Screen, which is acive screen

deactivedViewStyleHandler

Exit animation style is the ViewStyle for Exit Screen, which is deactive screen

Below example you will be more clear:


const App = () => {
  const enterAnimKit = new Animated.Value(0);
  const exitAnimKit = new Animated.Value(0);
  const width = useWindowDimensions().width;
  return (
    <SafeAreaView>
      <NativeRouter>
        <View style={styles.container}>
          <Navigator />
          <AnimatedStack
            swipeCancelSpeed={50}
            swipeable={true}
            onMountAnimate={() => {
              Animated.timing(enterAnimKit, {
                toValue: 1,
                duration: 100
              }).start();
            }}
            onTransitionAnimate={({ location, action, isNestedRoute }) => {
              if (isNestedRoute) return;
              // Enter and exit or one only
              enterAnimKit.setValue(0);
              exitAnimKit.setValue(0);

              Animated.timing(enterAnimKit, {
                toValue: 1,
                duration: 500,
                delay: 200
              }).start();

              Animated.timing(exitAnimKit, {
                toValue: 1,
                duration: 500
              }).start();
            }}
            activedViewStyleHandler={({ location, action, isNestedRoute }) => {
              return {
                transform: [
                  {
                    translateX: enterAnimKit.interpolate({
                      inputRange: [0, 1],
                      outputRange: [width, 0]
                    })
                  }
                ]
              };
            }}
            deactivedViewStyleHandler={({ location, action, isNestedRoute }) => {
              return {
                transform: [
                  {
                    translateX: exitAnimKit.interpolate({
                      inputRange: [0, 1],
                      outputRange: [0, -width]
                    })
                  }
                ]
              };
            }}
          >
            <Route exact path='/'>
              <Home />
            </Route>
            <Route path='/about'>
              <About />
            </Route>
            <Route path='/topics' component={Topics} />
          </AnimatedStack>
        </View>
      </NativeRouter>
    </SafeAreaView>
  );
};

With this code given, the transition will be shown as below

Customize Transiction Animation

transition like butterfly

Butterfly Transiction Animation

activedViewStyleHandler={({ location, action, isNestedRoute }) => {
  return {
    transform: [
      {
        translateX: enterAnimKit.interpolate({
          inputRange: [0, 1],
          outputRange: [width, 0]
        })
      },
      {
        rotateX: enterAnimKit.interpolate({
          inputRange: [0, 0.5, 1],
          outputRange: ['0deg', '180deg', '0deg']
      })
    }
    ]
  };
}}
deactivedViewStyleHandler={({ location, action, isNestedRoute }) => {
  return {
    transform: [
      {    
        translateX: exitAnimKit.interpolate({
          inputRange: [0, 1],
          outputRange: [0, -width]
        })
      },
      {
        rotateX: exitAnimKit.interpolate({
          inputRange: [0, 0.5, 1],
          outputRange: ['0deg', '180deg', '0deg']
      })
    }
    ]
  };
}}

transition like Scaling

Scaling Transiction Animation

activedViewStyleHandler={({ location, action, isNestedRoute }) => {
  return {
    transform: [
      {
        translateX: enterAnimKit.interpolate({
          inputRange: [0, 1],
          outputRange: [width, 0]
        })
      },
      {
        scale: enterAnimKit.interpolate({
          inputRange: [0, 0.5, 1],
          outputRange: [1, 0.2, 1]
      })
    }
    ]
  };
}}
deactivedViewStyleHandler={({ location, action, isNestedRoute }) => {
  return {
    transform: [
      {    
        translateX: exitAnimKit.interpolate({
          inputRange: [0, 1],
          outputRange: [0, -width]
        })
      },
      {
        scale: exitAnimKit.interpolate({
          inputRange: [0, 0.5, 1],
          outputRange: [1, 0.2, 1]
      })
    }
    ]
  };
}}

Vertical Swipe and Navigation

Scaling Transiction Up Animation


<NativeRouter>
    <View style={styles.container}>
      <View style={{ flex: 9, height: '100%' }}>
        <AnimatedStack
          swipeMethod={SwipeMethod.SWIPE_VERTICAL}
          onMountAnimate={() => {
            Animated.timing(enterAnimKit, {
              toValue: 1,
              duration: 100,
            }).start();
          }}
          onTransitionAnimate={({ location, action, isNestedRoute }) => {
            if (isNestedRoute) return;
            // Enter and exit or one only
            enterAnimKit.setValue(0);
            exitAnimKit.setValue(0);

            Animated.timing(enterAnimKit, {
              toValue: 1,
              duration: 500,
              delay: 200,
            }).start();

            Animated.timing(exitAnimKit, {
              toValue: 1,
              duration: 500,
            }).start();
          }}
          activedViewStyleHandler={({ location, action, isNestedRoute }) => {
            return {
              paddingLeft: 40,
              transform: [
                {
                  translateY: enterAnimKit.interpolate({
                    inputRange: [0, 1],
                    outputRange: [height, 0],
                  }),
                },
                {
                  scale: enterAnimKit.interpolate({
                    inputRange: [0, 0.5, 1],
                    outputRange: [1, 0.2, 1],
                  }),
                },
              ],
            };
          }}
          deactivedViewStyleHandler={({ location, action, isNestedRoute }) => {
            return {
              transform: [
                {
                  translateY: exitAnimKit.interpolate({
                    inputRange: [0, 1],
                    outputRange: [0, -height],
                  }),
                },
                {
                  scale: exitAnimKit.interpolate({
                    inputRange: [0, 0.5, 1],
                    outputRange: [1, 0.2, 1],
                  }),
                },
              ],
            };
          }}
        >
          <Route exact path="/">
            <Home />
          </Route>
          <Route path="/about">
            <About />
          </Route>
          <Route path="/topics" component={Topics} />
        </AnimatedStack>
      </View>
      <View style={{ flex: 1 }}>
        <Navigator />
      </View>
    </View>
  </NativeRouter>

Reason of created this

React Router Native still a popular routing engine which native, clean(no other UI kit dependencies) and powerful for routing but no animation.

Now added on animate stack, you can animate the view on run time, changing the animation style on runtime!

React router for routing, let the drawer, menu bar, tab bar and other fancy UI kits bar for other Ui Library control without any breakage.

Design for latest React Version.

This package is using getDerivedStateFromProps function which going to replace componentWillReceiveProps