Gathering detailed insights and metrics for react-native-animatable
Gathering detailed insights and metrics for react-native-animatable
Gathering detailed insights and metrics for react-native-animatable
Gathering detailed insights and metrics for react-native-animatable
ignite-animatable
An Ignite plugin which installs react-native-animatable.
react-native-animatable-unmountable
Declarative transitions and animations for React Native (with unmount effect)
react-table
Hooks for building lightweight, fast and extendable datagrids for React
react-native-smooth-pincode-input
A cross-platform, smooth, lightweight, customizable PIN code input component for React Native.
Standard set of easy to use animations and declarative transitions for React Native
npm install react-native-animatable
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
9,846 Stars
187 Commits
700 Forks
113 Watching
2 Branches
31 Contributors
Updated on 26 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
4.6%
84,394
Compared to previous day
Last week
5.1%
421,921
Compared to previous week
Last month
3.4%
1,792,347
Compared to previous month
Last year
22.1%
19,044,650
Compared to previous year
1
Declarative transitions and animations for React Native
$ npm install react-native-animatable --save
To animate things you must use the createAnimatableComponent
composer similar to the Animated.createAnimatedComponent
. The common components View
, Text
and Image
are precomposed and exposed under the Animatable
namespace. If you have your own component that you wish to animate, simply wrap it with a Animatable.View
or compose it with:
1import * as Animatable from 'react-native-animatable'; 2MyCustomComponent = Animatable.createAnimatableComponent(MyCustomComponent);
1<Animatable.Text animation="zoomInUp">Zoom me up, Scotty</Animatable.Text>
To make looping animations simply set the iterationCount
to infinite
. Most animations except the attention seekers work best when setting direction
to alternate
.
1<Animatable.Text animation="slideInDown" iterationCount={5} direction="alternate">Up and down you go</Animatable.Text> 2<Animatable.Text animation="pulse" easing="ease-out" iterationCount="infinite" style={{ textAlign: 'center' }}>❤️</Animatable.Text>
You can create your own simple transitions of a style property of your own choosing. The following example will increase the font size by 5 for every tap – all animated, all declarative! If you don't supply a duration
property, a spring animation will be used.
Note: If you are using colors, please use rgba()
syntax.
Note: Transitions require StyleSheet.flatten
available in React Native 0.15 or later. If you are running on anything lower, please polyfill as described under imperative usage.
1<TouchableOpacity onPress={() => this.setState({fontSize: (this.state.fontSize || 10) + 5 })}> 2 <Animatable.Text transition="fontSize" style={{fontSize: this.state.fontSize || 10}}>Size me up, Scotty</Animatable.Text> 3</TouchableOpacity>
Note: Other properties will be passed down to underlying component.
Prop | Description | Default |
---|---|---|
animation | Name of the animation, see below for available animations. | None |
duration | For how long the animation will run (milliseconds). | 1000 |
delay | Optionally delay animation (milliseconds). | 0 |
direction | Direction of animation, especially useful for repeating animations. Valid values: normal , reverse , alternate , alternate-reverse . | normal |
easing | Timing function for the animation. Valid values: custom function or linear , ease , ease-in , ease-out , ease-in-out , ease-in-cubic , ease-out-cubic , ease-in-out-cubic , ease-in-circ , ease-out-circ , ease-in-out-circ , ease-in-expo , ease-out-expo , ease-in-out-expo , ease-in-quad , ease-out-quad , ease-in-out-quad , ease-in-quart , ease-out-quart , ease-in-out-quart , ease-in-quint , ease-out-quint , ease-in-out-quint , ease-in-sine , ease-out-sine , ease-in-out-sine , ease-in-back , ease-out-back , ease-in-out-back . | ease |
iterationCount | How many times to run the animation, use infinite for looped animations. | 1 |
iterationDelay | For how long to pause between animation iterations (milliseconds). | 0 |
transition | What style property to transition, for example opacity , rotate or fontSize . Use array for multiple properties. | None |
onAnimationBegin | A function that is called when the animation has been started. | None |
onAnimationEnd | A function that is called when the animation has been completed successfully or cancelled. Function is called with an endState argument, refer to endState.finished to see if the animation completed or not. | None |
onTransitionBegin | A function that is called when the transition of a style has been started. The function is called with a property argument to differentiate between styles. | None |
onTransitionEnd | A function that is called when the transition of a style has been completed successfully or cancelled. The function is called with a property argument to differentiate between styles. | None |
useNativeDriver | Whether to use native or JavaScript animation driver. Native driver can help with performance but cannot handle all types of styling. | false |
isInteraction | Whether or not this animation creates an "interaction handle" on the InteractionManager. | false if iterationCount is less than or equal to one |
All animations are exposed as functions on Animatable elements, they take an optional duration
argument. They return a promise that is resolved when animation completes successfully or is cancelled.
1import * as Animatable from 'react-native-animatable'; 2 3class ExampleView extends Component { 4 handleViewRef = ref => this.view = ref; 5 6 bounce = () => this.view.bounce(800).then(endState => console.log(endState.finished ? 'bounce finished' : 'bounce cancelled')); 7 8 render() { 9 return ( 10 <TouchableWithoutFeedback onPress={this.bounce}> 11 <Animatable.View ref={this.handleViewRef}> 12 <Text>Bounce me!</Text> 13 </Animatable.View> 14 </TouchableWithoutFeedback> 15 ); 16 } 17}
To stop any ongoing animations, just invoke stopAnimation()
on that element.
You can also animate imperatively by using the animate()
function on the element for custom animations, for example:
this.view.animate({ 0: { opacity: 0 }, 1: { opacity: 1 } });
transition(fromValues, toValues[[, duration], easing])
Will transition between given styles. If no duration
or easing
is passed a spring animation will be used.
transitionTo(toValues[[, duration], easing])
This function will try to determine the current styles and pass it along to transition()
as fromValues
.
1import * as Animatable from 'react-native-animatable'; 2 3class ExampleView extends Component { 4 handleTextRef = ref => this.text = ref; 5 6 render() { 7 return ( 8 <TouchableWithoutFeedback onPress={() => this.text.transitionTo({ opacity: 0.2 })}> 9 <Animatable.Text ref={this.handleTextRef}>Fade me!</Animatable.Text> 10 </TouchableWithoutFeedback> 11 ); 12 } 13}
Animations can be referred to by a global name or a definition object.
An animation definition is a plain object that contains an optional easing
property, an optional style
property for static non-animated styles (useful for perspective
, backfaceVisibility
, zIndex
etc) and a list of keyframes. The keyframes are refered to by a number between 0 to 1 or from
and to
. Inspect the source in the definitions
folder to see more in depth examples.
A simple fade in animation:
1const fadeIn = { 2 from: { 3 opacity: 0, 4 }, 5 to: { 6 opacity: 1, 7 }, 8};
1<Animatable.Text animation={fadeIn} >Fade me in</Animatable.Text>
Combining multiple styles to create a zoom out animation:
1const zoomOut = { 2 0: { 3 opacity: 1, 4 scale: 1, 5 }, 6 0.5: { 7 opacity: 1, 8 scale: 0.3, 9 }, 10 1: { 11 opacity: 0, 12 scale: 0, 13 }, 14};
1<Animatable.Text animation={zoomOut} >Zoom me out</Animatable.Text>
To make your animations globally available by referring to them by a name, you can register them with initializeRegistryWithDefinitions
. This function can also be used to replace built in animations in case you want to tweak some value.
1Animatable.initializeRegistryWithDefinitions({ 2 myFancyAnimation: { 3 from: { ... }, 4 to: { ... }, 5 } 6});
The talk A Novel Approach to Declarative Animations in React Native from React Europe 2017 about this library and animations/transitions in general is available on YouTube.
MakeItRain
exampleSee Examples/MakeItRain
folder for the example project from the talk.
AnimatableExplorer
exampleSee Examples/AnimatableExplorer
folder for an example project demoing animations available out of the box and more.
Animations are heavily inspired by Animated.css.
bounce
flash
jello
pulse
rotate
rubberBand
shake
swing
tada
wobble
bounceIn
bounceInDown
bounceInUp
bounceInLeft
bounceInRight
bounceOut
bounceOutDown
bounceOutUp
bounceOutLeft
bounceOutRight
fadeIn
fadeInDown
fadeInDownBig
fadeInUp
fadeInUpBig
fadeInLeft
fadeInLeftBig
fadeInRight
fadeInRightBig
fadeOut
fadeOutDown
fadeOutDownBig
fadeOutUp
fadeOutUpBig
fadeOutLeft
fadeOutLeftBig
fadeOutRight
fadeOutRightBig
flipInX
flipInY
flipOutX
flipOutY
lightSpeedIn
lightSpeedOut
slideInDown
slideInUp
slideInLeft
slideInRight
slideOutDown
slideOutUp
slideOutLeft
slideOutRight
zoomIn
zoomInDown
zoomInUp
zoomInLeft
zoomInRight
zoomOut
zoomOutDown
zoomOutUp
zoomOutLeft
zoomOutRight
MIT License. © Joel Arvidsson 2015
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 15/30 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
14 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More