react-native-anime v0.0.47
React Native Anime
(Inspired by Cheetah for Swift: https://github.com/suguru/Cheetah)
Anime is an animation utility for React Native. It's built on top of the Animated module, and provides a much simpler API for handling animations.
The library is still in early development. I also need to add a proper API documentation. Open issues if you find any bugs, and contributions are also welcomed!
Features
- Animations with durations and delays
- Parallel/Serial executions
- Easings
- Springs
Installation
$ npm i react-native-animeOR
$ yarn add react-native-animeCode Example
- Import Anime
import Anime from 'react-native-anime';- Wrap your view with Anime component and save its reference
render () {
return (
<Anime.View ref={ ref => this.box = ref }>
<View style={ styles.box }/>
</Anime.View>
)
}- Use the reference to animate your component
onClick() {
this.box.moveX(100, { duration: 1500 }).start();
}
// You can also stop an animation with a .stop() method, and reset the component's styling with .reset()
stopAndReset() {
this.box.stop();
this.box.reset();
}
Available methods
Translate:
translateX
translateY
moveX // Relative to last X translation
moveY // Relative to last Y translationSkew:
skewX
skewYPrespective:
perspectiveScale:
scaleRotate:
rotateZ OR rotate
rotateX
rotateYBorders:
borderRadius
borderWidth
borderColorText:
fontSize
colorLayout:
height
width
opacity
backgroundColor
zIndexParallel execution
Anime groups animation properties and executes them at once.
this.box
.moveX(50)
.moveY(50)
.rotate(180)
.start()
Sequence execution
wait will wait until all animations placed before it completed. It can also receive milliseconds to wait to start next animation
this.box
// first animation
.moveX(50)
.scale(1.5)
// wait 1s before starting second animation
.wait(1000)
// second animation
.moveX(-50)
.scale(0.5)
.start()
Duration, delay, easing
Just like with Animated, you can specify durations, delays and easings for your animations
import { Easing } from 'react-native';
animate() {
this.box
.skewX(50, { duration: 2000, easing: Easing.bounce })
.rotateY(-100, { delay: 2000 })
.start();
}
Spring
You can also use Animated's spring animations, together with all its options (http://browniefed.com/react-native-animation-book/api/SPRING.html)
this.box
.height(100, { spring: { friction: 1, velocity: 100 } })
.borderRadius(100)
.start()
// or simply use `spring: true` for default spring behaviour
this.box
.moveX(50, { spring: true })
.start()
Also supports Image, Text and ScrollView
Like with Animated module, you can also animate Text, Image and ScrollView components
render() {
return (
<Anime.Image ref={ ref => this.image = ref }
source={{ require('pikachu.gif') }} />
)
}
animate() {
this.image
.skewX(5, { spring: true })
.skewY(5, { spring: true })
.wait()
.rotate(360*20, { duration: 2000 })
.start()
}![]()
Parallel animation of numerous components
render() {
return (
<View>
<Anime.View ref={ ref => this.box = ref }
style={{ width: 50, height: 50, backgroundColor: 'blue' }}/>
<Anime.Text ref={ ref => this.text = ref }
style={{ color: 'blue', fontSize: 12 }}>
Very easy
</Anime.Text>
</View>
)
}
animateComponents() {
const box = this.box.rotate(90);
const text = this.text.color('red');
const parallel = new Anime.Parallel([box, text]);
// Start parallel animation for both components, and reset them both when it ends
parallel.start(() => parallel.reset())
}