当前位置: 首页 > 知识库问答 >
问题:

Gif不工作在React NativeiOS

祁远
2023-03-14

我正在使用反应15.2.1和反应原生0.30.0

我查看了如何在React Native中显示动画gif?并遵循指示。

<Image source={{ uri: 'http://i.giphy.com/l41YiEvBtjGKNlzby.gif'
       style={{ height: 250, width: 250 }} />

也尝试过

<Image source={require('./path/to.gif')}
       style={{ height: 250, width: 250 }} />

但gif没有显示。如果我关闭图像链接,效果会很好。

我检查了这个工作示例https://rnplay.org/apps/739mzQ但无法用0.30.0进行测试,所以我想知道从那以后是否有什么变化。

共有3个答案

文喜
2023-03-14

使用此代码:

import React, {Component} from 'react';
import { StyleSheet, Image,Text, View} from 'react-native';
const Splash = require('./images/testGif.gif')

class SplashSrceen extends Component {

  render() {
    const { container, splashgif } = styles;
    return (
      <View style={container}>
        <Image source={Splash} style={splashgif} />
        <Text>or</Text>
        <Image source={{uri:'https://media.tenor.com/images/0a1652de311806ce55820a7115993853/tenor.gif'}}style={splashgif} />
    </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  splashgif: {
    resizeMode: 'stretch',
    width: '100%',
    height: '50%'
  }
});

export default SplashSrceen ;

Android系统

为了纠正这一问题,我们包括以下库:

dependencies {
    implementation 'com.facebook.fresco:fresco:1.10.0'
    implementation 'com.facebook.fresco:animated-gif:1.10.0'
}
钱雅逸
2023-03-14

请尝试此示例


import React, {Component} from 'react';
import { StyleSheet,  View} from 'react-native';
const SplashGif = require('./images/Wallpaper.gif');

export default class App extends Component {
  render() {
    const { container, imageStyles } = styles;
    return (
      <View style={container}>
        <Image source={SplashGif} style={imageStyles} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  imageStyles: {
    resizeMode: 'stretch',
    width: '100%',
    height: '100%'
  }
});


伊羽
2023-03-14

也许可以将gif添加到您的项目并使用需求函数。

 类似资料:
  • 机器人发送嵌入消息(包含文本和gif)。然而,gif根本不加载。一切似乎都在为其他命令工作,但这个特定的命令不工作。我真的不知道,请帮帮我。我的代码: 下面是这条消息的图片:

  • bot发送嵌入消息,但仅发送文本而不发送gif。我有一个单独的gif文件。json文件,因此当有人使用该命令时,会有不同的GIF。但由于某种原因,它不起作用。也许是因为天气原因。json文件?我真的不知道,请帮帮我。我的代码: 该代码为。json文件: (我知道,它只有一个gif。) 当两个文件都在一个文件夹中时,我在控制台中出现的错误:图片:https://i.stack.imgur.com/8

  • 我需要通过耳机播放一些音频。我使用AudioTrack在设备上播放一些声音。并且音频模式被设置为流_语音_呼叫。此外,在我的活动中,免提电话是通过以下方式关闭的: 这似乎在2.3设备上运行得很完美。但在2.1上,声音仍然从扬声器播放。 为了解决这个问题,我尝试将setMode()用作: 有了这个,2.1和2.3的声音就可以通过耳机播放了,但2.3的大多数时候根本不会播放。此外,我在一些地方读到se

  • 后更新内核到4.0.3在ubuntu phpmadmin在xampp不工作 我试试这个 开始XAMPPLinux5.6.8-0...XAMPP:启动Apache...好的。XAMPP:启动MySQL...已经运行。XAMPP:开始ProFTPD...好的。 和 正在停止Linux 5.6的XAMPP。8-0... XAMPP:正在停止Apache。。。不跑。XAMPP:正在停止MySQL。。。好啊

  • 我试图让ESLint让我使用对象的Rest/传播。尽管我尽了最大努力,我还是得到了这个错误: 当我悬停在椭圆上时(<代码>...)用红色弯弯曲曲。 我的看起来像这样: 我确信prefs正在被阅读,因为规则、插件和样式指南正在按预期工作。 要启用对象rest/spread,是这里的关键(哈哈),它似乎对其他人有用。然而,它拒绝为我工作。我不知所措 更新:我使用的是Visual Studio代码v1.