首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的Lottie动画没有显示在我的React原生应用程序中?

为什么我的Lottie动画没有显示在我的React原生应用程序中?
EN

Stack Overflow用户
提问于 2019-02-15 16:43:33
回答 1查看 3.4K关注 0票数 1

我有一个react原生视图,里面有一个Lottie动画,但动画根本没有显示,屏幕只是黄色(封闭视图的背景颜色)。

下面是我的代码:

代码语言:javascript
运行
复制
import React, { Component } from 'react';
import {
  StyleSheet,
  View, 
} from 'react-native';
import LottieView from 'lottie-react-native';

export default class Splash extends Component {
  constructor(props) {
    super(props);
  }
    
  static navigationOptions = {
    header: null,
  };
    
  render() {
    return (
      <View style={{flex: 1, backgroundColor: 'yellow'}}>
        <LottieView
          style={{flex: 1}}
          source={require('../check.json')}
          autoPlay
          loop
        />
      </View>
    );
  }
}
EN

回答 1

Stack Overflow用户

发布于 2019-02-15 17:35:53

我试用了您提供的Lottie文件,它确实起作用了。

下面是我在App.js中使用的代码,让它正常工作。

代码语言:javascript
运行
复制
import React, {Component} from 'react';
import {Platform, StyleSheet, View} from 'react-native';
import LottieView from 'lottie-react-native';

export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <LottieView
          style={{flex: 1}}
          source={require('./check.json')} {/* I think your issue is that you have the wrong path for your lottie file*/}
          autoPlay
          loop
        />
      </View>
    );
  }
}

注意:在我的项目中,我的App.js和我的check.json在同一个文件夹中。

这是一张它工作的图片

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54705445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档