Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

animatable

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

animatable

enable react-native css transition and animation

latest
npmnpm
Version
1.2.3
Version published
Maintainers
1
Created
Source

animatable

You can enable css-animation and css-transition for react-native easily.
Also works on web.

Install

npm install animatable

Usage

Transition

Animation will be triggered when specified style prop changed.
When property option is specified behaviour is like css-transition.

import { View } from 'react-native'
import animatable from 'animatable'

const TransitionLeftView = animatable({
  property: 'left',
  duration: 400,
  timingFunction: 'ease-in-out'
})(View)

<TransitionLeftView
  onClick={() => this.setState({ on: !this.state.on })}
  style={{
    position: 'absolute',
    left: this.state.on ? 100 : 0,
    top: 0,
    width: 100,
    height: 100,
    backgroundColor: 'red'
  }}
/>

Screenshot

screenshot

Animation

When keyframes option is specified behaviour is like css-animation.

import { View } from 'react-native'
import animatable from 'animatable'

// define keyframes 
const keyframes = {
  '0%':   { marginLeft: '0%',   marginRight: '100%' },
  '50%':  { marginLeft: '25%',  marginRight: '0%' },
  '100%': { marginLeft: '100%', marginRight: '0%' }
}
const Bar = animatable({
  keyframes: keyframes,
  direction: 'alternate-reverse',
  duration: 1000,
  timingFunction: 'linear',
  iterationCount: 'infinite',
})(View)

// render
const Indicator = (props) => (
  <View style={{
    width: 100,
    height: 20,
    backgroundColor: 'lightgray'
  }}>
    <Bar
      style={{
        height: '100%',
        backgroundColor: 'black',
      }}
    />
  </View>)

Screenshot

screenshot

Examples

1) specify property values as function

const Bar = animatable({
  keyframes: {
    '0%':   { marginLeft: '0%',   marginRight: '100%' },
    '50%':  { marginLeft: '25%',  marginRight: '0%' },
    '100%': { marginLeft: '100%', marginRight: '0%' }
  },
  duration: 1000,

  // you can set `(prop) => value`
  playState: (props) => props.enabled ? 'paused' : 'running'

})(View)

<Bar
  onClick={() => this.setState({ enabled: !this.state.enabled })}
  enabled={this.state.enabled}
/>

2) Use with style-components etc.

import styled from 'styled-components'

const Bar = styled(animatable({
  keyframes: {
    '0%':   { marginLeft: '0%',   marginRight: '100%' },
    '50%':  { marginLeft: '25%',  marginRight: '0%' },
    '100%': { marginLeft: '100%', marginRight: '0%' }
  },
  duration: 1000,
  playState: (props) => props.enabled ? 'running': 'paused'
})(View))`
  height: 100%;
  background-color: black;
`

Options

You have to specify millisec value for duration and delay.

You can use property values same as described on css definitions, and default values are same as css's one of web.

Apply transition for components:

const TransitionComponent = animatable({
  // required
  property: 'transform',
  duration: 200,

  // optional
  delay: 500,
  timingFunction: 'linear'
})(Component)

Apply animation for components:

const AnimationComponent = animatable({
  // required
  keyframes: {
    '0%':   { marginLeft: '0%',   marginRight: '100%' },
    '50%':  { marginLeft: '25%',  marginRight: '0%' },
    '100%': { marginLeft: '100%', marginRight: '0%' }
  },
  duration: 200,

  // optional
  delay: 500,
  timingFunction: 'linear'
  iterationCount: 'infinite',
  direction: 'normal',
  playState: 'running',
  // TODO: fillMode: 'forwards'
})(Component)

Demo

https://yusukeshibata.github.io/animatable/

Author

Yusuke Shibata

License

MIT

FAQs

Package last updated on 23 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts