1.0.4 • Published 5 years ago

rn-tween v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

rn-tween

It can help animating components by timing.

Installation

  • Using Npm
npm install rn-tween --save
  • Using Yarn
yarn add rn-tween --dev

Tween components

  • RNTween
  • RNTweenView
  • RNTweenImage
  • RNTweenText

Example

Auto start

import {RNTweenView} from 'rn-tween';

<RNTweenView
  autoStartName="transit"
  initialConfig={{
    transit: {
      mode: 'parallel',
      configs: [
        {
          from: 0,
          to: 1,
          duration: 1000,
          styleProperty: 'opacity',
          loop: true,
        },
        {
          from: 0.2,
          to: 1,
          duration: 1000,
          styleProperty: 'scale',
          loop: true,
        },
      ],
    },
  }}
  style={{
    width: 100,
    height: 100,
    backgroundColor: 'red',
  }}
/>;

Call functions

import {RNTweenView} from 'rn-tween';

<RNTweenView
  ref={ref => (_tween = ref)}
  firstUsedConfigName="transit"
  initialConfig={{
    transit: {
      mode: 'parallel',
      configs: [
        {
          from: 0,
          to: 1,
          duration: 500,
          styleProperty: 'opacity',
        },
        {
          from: 0.2,
          to: 1,
          duration: 500,
          styleProperty: 'scale',
        },
      ],
    },
  }}
  style={{
    width: 100,
    height: 100,
    backgroundColor: 'orange',
  }}
/>;

// Stop animating the tweeen with a specific configuration name
_tween.start({name: 'transit'});
_tween.start({name: 'transit', reversed: true});
_tween.start({name: 'transit', reversed: true, onComplete: () => alert('Finished')});

// Stop animating the tween
_tween.stop();

// Reprepare tween animation configurations
_tween.prepare({
  transit: {
    mode: 'sequence',
    configs: [
      {
        from: 0,
        to: 1,
        duration: 500,
        styleProperty: 'opacity',
      },
      {
        from: 0.2,
        to: 1,
        duration: 500,
        styleProperty: 'scale',
      },
    ],
  },
});

Available component props

RNTween

NameTypeDefaultDescription
autoStartNamestringnullTell which animation tween should automatically start at the first time
firstUsedConfigNamestringnullTell which animation tween configuration should be applied at the first time
initialConfigobjectnullThe initial tween configurations to be used
AnimatedComponentComponentnullThe animated component to be animated
onCompletefunctionnullThe callback invoked after the tween animation completed

RNTweenView

Also inherits ViewProps

NameTypeDefaultDescription
autoStartNamestringnullTell which animation tween should automatically start at the first time
firstUsedConfigNamestringnullTell which animation tween configuration should be applied at the first time
initialConfigobjectnullThe initial tween configurations to be used
onCompletefunctionnullThe callback invoked after the tween animation completed

RNTweenText

Also inherits TextProps

NameTypeDefaultDescription
autoStartNamestringnullTell which animation tween should automatically start at the first time
firstUsedConfigNamestringnullTell which animation tween configuration should be applied at the first time
initialConfigobjectnullThe initial tween configurations to be used
onCompletefunctionnullThe callback invoked after the tween animation completed

RNTweenImage

Also inherits ImageProps

NameTypeDefaultDescription
autoStartNamestringnullTell which animation tween should automatically start at the first time
firstUsedConfigNamestringnullTell which animation tween configuration should be applied at the first time
initialConfigobjectnullThe initial tween configurations to be used
onCompletefunctionnullThe callback invoked after the tween animation completed

initialConfig

initialConfig: {
  [name: string]: {
    mode,
    configs
  }
}
NameTypeDescription
modestringSpecify tween animation mode like parallel or sequence
configsarrayArray of tween animation configuration

initialConfigname.configsindex

NameTypeDescription
stylePropertystringSpecify any style property to be animated like opacity, scale, etc
fromnumberValue from where the animation starts
tonumberValue to where the animation must reach
durationnumberDuration of animation
delaynumberDelay before the animation starts
loopboolTell if the animation should play as loop
easingfunctionEasing function to define curve. Default is TweenEasing.linear
useNativeboolUses the native driver when true. Default is true

Available instance functions

start({ name, reversed, onComplete })

NameTypeDescription
namestringName of tween animation configuration
reversedboolTell if the animation should play in reverse
onCompletefunctionCallback invoked after the animation complete

stop()

Stop a running animation

prepare({ mode, configs })

NameTypeDescription
modestringSpecify tween animation mode like parallel or sequence
configsarrayArray of tween animation configuration

License