All Projects → wix-incubator → react-sequence-animator

wix-incubator / react-sequence-animator

Licence: MIT license
A React library for sequence animations

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects

Projects that are alternatives of or similar to react-sequence-animator

Tsai
Time series Timeseries Deep Learning Pytorch fastai - State-of-the-art Deep Learning with Time Series and Sequences in Pytorch / fastai
Stars: ✭ 407 (+1669.57%)
Mutual labels:  sequence
Fill Range
Fill in a range of numbers or letters, positive or negative, optionally passing an increment or multiplier to use.
Stars: ✭ 41 (+78.26%)
Mutual labels:  sequence
Seqsvr
序列号生成器--《万亿级调用系统:微信序列号生成器架构设计及演变》开源实现
Stars: ✭ 109 (+373.91%)
Mutual labels:  sequence
Gomonkey
gomonkey is a library to make monkey patching in unit tests easy
Stars: ✭ 473 (+1956.52%)
Mutual labels:  sequence
Restez
😴 📂 Create and Query a Local Copy of GenBank in R
Stars: ✭ 22 (-4.35%)
Mutual labels:  sequence
Seqsvr
High performance unique number generator powered by Go
Stars: ✭ 58 (+152.17%)
Mutual labels:  sequence
Sars tutorial
Repository for the tutorial on Sequence-Aware Recommender Systems held at TheWebConf 2019 and ACM RecSys 2018
Stars: ✭ 320 (+1291.3%)
Mutual labels:  sequence
Easysequence
EasySequence is a powerful fundamental library to process sequcence type, such as array, set, dictionary. All type object which conforms to NSFastEnumeration protocol can be initialzed to an EZSequence instance, then you can operation with them. Finally, you can transfer them back to the original type.
Stars: ✭ 150 (+552.17%)
Mutual labels:  sequence
Nunit cshaprp cheatsheet
Example implementations of each attribute available in Nunit2 unit Testing Framework using C# .NET.
Stars: ✭ 14 (-39.13%)
Mutual labels:  sequence
Monster
The Art of Template MetaProgramming (TMP) in Modern C++♦️
Stars: ✭ 90 (+291.3%)
Mutual labels:  sequence
Seqkit
A cross-platform and ultrafast toolkit for FASTA/Q file manipulation in Golang
Stars: ✭ 607 (+2539.13%)
Mutual labels:  sequence
Numgen
Creates objects that generate number sequences
Stars: ✭ 5 (-78.26%)
Mutual labels:  sequence
Iter
Simple iterator abstract datatype, intended to iterate efficiently on collections while performing some transformations.
Stars: ✭ 71 (+208.7%)
Mutual labels:  sequence
Fromfrom
A JS library written in TS to transform sequences of data from format to another
Stars: ✭ 462 (+1908.7%)
Mutual labels:  sequence
Bioconvert
Bioconvert is a collaborative project to facilitate the interconversion of life science data from one format to another.
Stars: ✭ 112 (+386.96%)
Mutual labels:  sequence
Smile
😄 Emoji in Swift
Stars: ✭ 359 (+1460.87%)
Mutual labels:  sequence
Yacrd
Yet Another Chimeric Read Detector
Stars: ✭ 49 (+113.04%)
Mutual labels:  sequence
Sequitur
Library of autoencoders for sequential data
Stars: ✭ 162 (+604.35%)
Mutual labels:  sequence
Snowflake
java edition of [Twitter Snowflake](https://github.com/twitter/snowflake), a network service for generating unique ID numbers at high scale with some simple guarantees.
Stars: ✭ 114 (+395.65%)
Mutual labels:  sequence
Swarm
A robust and fast clustering method for amplicon-based studies
Stars: ✭ 88 (+282.61%)
Mutual labels:  sequence

react-sequence-animator

This is a supper simple React library that lets us create animations in an easy and straight forward manner.

The idea behind this library was to create animations that can be controlled very easily.

For example, a loader that has smooth transitions to a success and fail mode:

Advanced Sequence Animation

How to Install

npm install --save react-sequence-animator

or

yarn add react-sequence-animator

What You Get

The library has two components: SpriteAnimator and SequenceAnimator.

SpriteAnimator

The SpriteAnimator receives one child, which it respects as a sprite image, a getPosition function, which for every frame number should return a position object of the form: {top: 0, left: 0, width: 100, height: 100}, and the number of frames in the sequence.

In order to use this component you should know where each frame is located in the sprite image.

import { SpriteAnimator } from 'react-sequence-animator';
import sprite from './sprites-cat-running.png';

const WIDTH = 512;
const HEIGHT = 256;

class SpriteAnimatorStory extends React.Component {
  constructor() {
    super();
    this._getPosition = this._getPosition.bind(this);
  }

  render() {
    return (
      <SpriteAnimator autoplay numOfFrames={8} getPosition={this._getPosition}>
        <img src={sprite} alt="my-sprite" width={WIDTH * 4} height={HEIGHT * 2}/>
      </SpriteAnimator>
    );
  }

  _getPosition(frame) {
    return {
      width: WIDTH,
      height: HEIGHT,
      top: (frame < 4) ? 0 : HEIGHT,
      left: (frame % 4) * WIDTH
    };
  }
}

The SpriteAnimator receives several props:

Name Type default Description
children a single node --- the sprite to be "played"
getPosition function () => {top: 0, left: 0, width: '100%', height: '100%'} a function that is called for each frame and should return the position of the frame in the sprite
numOfFrames number 0 the number of frames in the animation
autoplay bool true should play automatically or not
duration number 1000 the duration in milliseconds of the animation
loop bool true should play in a loop
easing string 'linear' the easing of the animation (read more about this here)
onSequenceEnd func () => {} a callback function that is called each time the sequence reached its end
onAnimationStop func () => {} a callback function that is called when the animation stops completely
Notice: There's no restriction on the type of element the child should be. It can also be an SVG or even a react component or a div

API

play - Plays the animation (from the current frame)

stop - Stops the animation

reset - Resets the animation to the first frame (0)

SequenceAnimator

The SequenceAnimator receives a sequence of images as its children, and "plays" them one after the other.

import { SequenceAnimator } from 'react-sequence-animator';
import cat1 from './statics/cat1.png';
import cat2 from './statics/cat2.png';
import cat3 from './statics/cat3.png';
import cat4 from './statics/cat4.png';
import cat5 from './statics/cat5.png';
import cat6 from './statics/cat6.png';
import cat7 from './statics/cat7.png';
import cat8 from './statics/cat8.png';

class SequenceAnimatorExample extends React.Component {
  render() {
    return (
      <SequenceAnimator>
        <img src={cat1} alt="cat1"/>
        <img src={cat2} alt="cat2"/>
        <img src={cat3} alt="cat3"/>
        <img src={cat4} alt="cat4"/>
        <img src={cat5} alt="cat5"/>
        <img src={cat6} alt="cat6"/>
        <img src={cat7} alt="cat7"/>
        <img src={cat8} alt="cat8"/>
      </SequenceAnimator>
    );
  }
}

The SequenceAnimator receives several props:

Name Type default Description
children node or array of nodes [] the nodes to be "played"
autoplay bool true should play automatically or not
duration number 1000 the duration in milliseconds of the animation
loop bool true should play in a loop
easing string 'linear' the easing of the animation (read more about this here)
onSequenceEnd func () => {} a callback function that is called each time the sequence reached its end
onAnimationStop func () => {} a callback function that is called when the animation stops completely
Notice: There's no restriction on the types of elements the children should be. They can also be SVG's or even react components or divs

API

play - Plays the animation (from the current frame)

stop - Stops the animation

reset - Resets the animation to the first frame (0)

Easing

The components can apply to the animations, easings as described in the library easing-utils.

It was initially introduced in order to allow control of the animation's duration (using the linear easing), but other easings may be applied.

It is recommended to use easings only on linear animations.

Notice: When using easings other than linear, we cannot be assured that all frames will be played

Example:

Ball Easing Example

Both of the basketball animations above use the same sequence of images.

The right animation is played with a linear easing; A ball falling in a constant velocity.

Adding the easing easeOutBounce gives us the feeling of a ball in free fall, and bouncing after hitting the ground (left animation).

Notice how the eased animation (on the left) isn't as smooth as the linear animation.

That happens because the easeOutBounce skips some frames at the end.

In order to achieve a smoother animation, we would have needed much more frames (which really isn't cost effective).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].