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-animated-container

v1.0.1

Published

A container component for creating PPT-like animations in react-native

Downloads

5

Readme

AnimatedContainer

A container component for creating PPT-like animations in react-native

Introduction

In RN, Animated provides the ability to create animations. However, when we need to create some complex animations just like in PPT, it is rather hard for us. Fortunately, you can use AnimatedContainer to solve this problem.

How to use

Installation

npm install react-native-animated-container --save

Usage

It only needs two steps:

  1. Get the ref of AnimatedContainer and set the initial config for it. Just like this:
<View style={{flex: 1}}>
  <AnimatedContainer
    ref={_ => this._animationRef = _}
    initialConfig={{opacity: 0, x: 0, y: 0}}
    >
    {/*put your components here*/}
  </AnimatedContainer>
</View>
  1. Use promise to control the animation flow. Just like this:
playAnimation() {
  this._animationRef
    .show()                                                                  // appear
    .then(() => this._animationRef.sleep(1000))                              // sleep 1s
    .then(() => this._animationRef.moveTo({x: 200, y: 0, duration: 1000}))   // move to (200, 0)
    .then(() => this._animationRef.moveTo({x: 0, y: 200, duration: 500}))    // move to (0, 200)
    .then(() => this._animationRef.hide());                                  // disappear
}

Demo

class Demo extends Component {

  constructor(props) {
    super(props);
    this._animationRefs = {};
  }

  componentDidMount() {
    this._playAnimation();
  }

  _playAnimation() {
    // here is to control the animation flow
    this._animationRefs[1]
      .moveTo({x: 200, y: 0})
      .then(() => this._animationRefs[2].moveTo({x: 0, y: 200}))
      .then(() => this._animationRefs[4].moveTo({x: 200, y: 200}))
      .then(() => this._animationRefs[3].moveTo({x: 0, y: 0}));
  }

  _renderAnimationElement(text, index, position) {
    return (
      <AnimatedContainer
        ref={_ => this._animationRefs[index] = _}
        initialConfig={{opacity: 1, x: position.x, y: position.y}}
      >
        <Text>put your {text} here</Text>
      </AnimatedContainer>
    );
  }

  render() {
    return (
      <View style={{width: 200, height: 200}}>
        {this._renderAnimationElement('1st element', 1, {x: 0, y: 0})}
        {this._renderAnimationElement('2nd element', 2, {x: 200, y: 0})}
        {this._renderAnimationElement('3rd element', 3, {x: 200, y: 200})}
        {this._renderAnimationElement('4th element', 4, {x: 0, y: 200})}
      </View>
    );
  }
}

To see more detailed example, you can open the file: examples/src/pages/Demo2/index.js

More Details

initialConfig

AnimatedContainer needs the initialConfig to set initial values when first rendering. initialConfig is an object, including the following attributes:

|attribute|type|default value|description| |---------|----|-------------|-----------| |opacity|number|1|the opacity of element| |scale|number|1|by changing the scale, the element's size will change| |rotate|number|0|the rotated angle of element| |x|number|0|the x position of element| |y|number|0|the y position of element|

Note: as animated container uses absolute position, you should put all of them in a wrapper. In addition, you should set the x, y value for each animatedContainer. Or all of elements will be at the left top corner.

animation playing functions

AnimatedContainer provides two kinds of animation: cyclic and not cyclic.

cyclic animations

In the period, the element's opacity grows to 1, and then decay to 0.
blink({period: 1000})
stopBlink()

In the period, the elements will keep rolling.
roll({period: 1000})
stopRoll()

not cyclic animations

By passing the value of duration, you can control the speed of show/hide animation.
show({duration: 1000})
hide({duration: 1000})

By passing the value of scale, you can control the size of element.
scaleTo({scale: 1, duration: 1000})

By passing the value of x and y, you can control the position of element.
movaTo({x: 100, y: 100, duration: 1000})

By passing the value of rotate, you can control the rotated angle of element.
rotateTo({rotate: Math.PI, duration: 1000})

sequent and parallel playing

As each animation provided by AnimatedContainer is a promise, so it is easy to realize sequent and parallel playing.

sequent playing:

this._animationRef
  .show()
  .then(() => this._animationRef.moveTo({x: 100, y: 100}))
  .then(() => this._animationRef.scaleTo({scale: .5, duartion: 2000}))
  .then(() => this._animationRef.moveTo({x: 0, y: 100}))
  .then(() => this._animationRef.hide())

parallel playing:

Promise.all([
  this._animationRef.scaleTo({scale: 1.5}),
  this._animationRef.moveTo({x: 100, y: 100})
]).then(() => Promise.all([
  this._animationRef.opacityTo({opacity: .5}),
  this._animationRef.moveTo({x: 0, y: 0})
)).then(() => this._animationRef.hide());