Reactjs 如何在React Native中播放乐透动画(.json文件)的片段

Reactjs 如何在React Native中播放乐透动画(.json文件)的片段,reactjs,react-native,react-native-android,react-native-ios,lottie,Reactjs,React Native,React Native Android,React Native Ios,Lottie,我只想使用lottie view在react native中播放动画的一部分 长度约为5秒,而速度={1}我只想播放前3秒,然后转到下一个屏幕 代码在下面 LogoScreen.js: import React from 'react'; import { StyleSheet, View, Image, TextInput, StatusBar, Text } from "react-native"; import Icons from 'react-native-vector-icons/I

我只想使用lottie view在react native中播放动画的一部分 长度约为5秒,而速度={1}我只想播放前3秒,然后转到下一个屏幕 代码在下面

LogoScreen.js:

import React from 'react';
import { StyleSheet, View, Image, TextInput, StatusBar, Text } from "react-native";
import Icons from 'react-native-vector-icons/Ionicons';
import LottieView from "lottie-react-native";

export default class ChatScreen extends React.Component {

  onAnimationFinish = () => {
    this.props.navigation.navigate("Login")
  }
  render () {
    return (
      <View style={styles.container}>
        <StatusBar barStyle="light-content" backgroundColor="#161f3d" />
        <View>
          <LottieView
            source={require('../assets/animations/lottie/MotionCorpse-Jrcanest.json')}
            style={{ justifyContent: "center", alignSelf: "center", height: "100%", width: "100%" }}
            autoPlay
            loop={false}
            speed={1}
            onAnimationFinish={this.onAnimationFinish}
          />
        </View>
      </View>
    )
  }
从“React”导入React;
从“react native”导入{样式表、视图、图像、文本输入、状态栏、文本};
从“反应本机矢量图标/离子图标”导入图标;
从“lottie react native”导入LottieView;
导出默认类ChatScreen扩展React.Component{
onAnimationFinish=()=>{
this.props.navigation.navigate(“登录”)
}
渲染(){
返回(
)
}

好吧,你可以用几种方法来做,其中一种方法如下

您可以使用ref手动播放,然后在3秒钟后重定向到下一个屏幕

import React from 'react';
import { StyleSheet, View, Image, TextInput, StatusBar, Text } from "react-native";
import Icons from 'react-native-vector-icons/Ionicons';
import LottieView from "lottie-react-native";

export default class ChatScreen extends React.Component {

    componentDidMount() {
        this.anim.play();

        setTimeout(() => {
            this.props.navigation.navigate("Login")
        }, 3000);
    }

    render() {
        return (
            <View style={styles.container}>
                <StatusBar barStyle="light-content" backgroundColor="#161f3d" />
                <View>
                    <LottieView
                        source={require('../assets/animations/lottie/MotionCorpse-Jrcanest.json')}
                        style={{ justifyContent: "center", alignSelf: "center", height: "100%", width: "100%" }}
                        autoPlay={false}
                        loop={false}
                        speed={1}
                        ref={animation => { this.anim = animation; }} 
                    />
                </View>
            </View>
        )
    }
}

@NeetinSolanki是否有办法在循环中播放某些帧?比如添加
循环
道具,但仅限于某些帧范围?
this.animation.play(30, 120);