lottie-react-native
允许渲染 After Effects 动画的库。
Android
iOS
tvOS
Web
Bundled version:
7.2.2
Lottie 实时渲染 After Effects 动画,使应用可以像使用静态图片一样轻松地使用动画。
¥Lottie renders After Effects animations in real time, allowing apps to use animations as easily as they use static images.
安装
¥Installation
Terminal
-
npx expo install lottie-react-native
If you are installing this in an existing React Native app, make sure to install expo
in your project. Then, follow the installation instructions provided in the library's README or documentation.
示例
¥Example
Lottie
import { useRef, useEffect } from 'react';
import { Button, StyleSheet, View } from 'react-native';
import LottieView from 'lottie-react-native';
export default function App() {
const animation = useRef<LottieView>(null);
useEffect(() => {
// You can control the ref programmatically, rather than using autoPlay
// animation.current?.play();
}, []);
return (
<View style={styles.animationContainer}>
<LottieView
autoPlay
ref={animation}
style={{
width: 200,
height: 200,
backgroundColor: '#eee',
}}
// Find more Lottie files at https://lottiefiles.com/featured
source={require('./assets/gradientBall.json')}
/>
<View style={styles.buttonContainer}>
<Button
title="Restart Animation"
onPress={() => {
animation.current?.reset();
animation.current?.play();
}}
/>
</View>
</View>
);
}
const styles = StyleSheet.create({
animationContainer: {
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
flex: 1,
},
buttonContainer: {
paddingTop: 20,
},
});
了解更多
¥Learn more
访问官方文档
获取有关 API 及其用法的完整信息。