Easily add React Native animations with hooks
npm install react-native-animation-hooksyarn add react-native-animation-hooks
The most convenient way to add little animations to your ReactNative application.
``jsx
const Comp = () => {
const [bool, setBool] = useState(false)
const toggle = () => setBool(!bool);
const animatedOpacity = useAnimation({
toValue: bool ? 1 : 0.5,
})
return (
)
}
`
- Tiny interface using hooks and Animated framework
- Compatible with Expo
- Reduce Animated.Value management boilerplate
- Full support for spring and timing animations
- Typescript definitions
This repo is an Expo app that you can run with yarn start.
`tsx
import React, { useState } from 'react'
import { Animated, Switch, View, StyleProp, ViewStyle } from 'react-native'
import { useAnimation } from 'AnimationHooks'
const AnimatedShape = ({ style }: { style?: StyleProp
/>
)
const ExampleScreen = () => {
const [bool, setBool] = useState(false)
const animatedValue = useAnimation({
type: 'timing',
initialValue: 1,
toValue: bool ? 1 : 0,
duration: bool ? 1000 : 300,
useNativeDriver: true,
})
return (
flex: 1,
padding: 10,
justifyContent: 'space-around',
alignItems: 'center',
}}
>
opacity: animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0.3, 1],
}) as any,
}}
/>
transform: [
{
scale: animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0.5, 1],
}) as any,
},
],
}}
/>
transform: [
{
translateX: animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [-100, 100],
}) as any,
},
],
}}
/>
)
}
export default ExampleScreen
``
- Animated XY values
- Tests
MIT