如何在react-native android app中显示GIF? [英] How to display GIF in react-native android app?

查看:970
本文介绍了如何在react-native android app中显示GIF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的android react-native应用程序的我的Image标签中通过URL显示一个简单的gif但是当我启动它时没有显示图像。
docs 中提供的代码确实有效仅适用于iOS但不适用于Android:

I want to display a simple gif via URL in my Image tag in my android react-native app but when I start it no image is shown. The code as provided in the docs does work only for iOS but not for android:

<Image
  style={styles.gif}
  source={{uri: 'http://38.media.tumblr.com/9e9bd08c6e2d10561dd1fb4197df4c4e/tumblr_mfqekpMktw1rn90umo1_500.gif'}}
/>

这里有一个类似的问题但是已经说过这只适用于iOS:
< a href =https://stackoverflow.com/questions/35594783/how-do-i-display-an-animated-gif-in-react-native>如何在React Native中显示动画gif?

关于此提交它应该可以工作:
https://github.com/facebook/react-native/commit/fcd7de5301655b39832d49908e5ca72ddaf91f7e

There was a similar question here but as already said this only works for iOS: How do I display an animated gif in React Native?
Regarding this commit it should work though: https://github.com/facebook/react-native/commit/fcd7de5301655b39832d49908e5ca72ddaf91f7e

推荐答案


我们通过使GIF支持可选的方式使核心库更小。

We made the core library smaller by making things like GIF support optional.

因为我们必须手动选择加入Android中的gif支持
将以下行添加到依赖项下的android / app / build.gradle文件中:

Because of that we have to manually opt-in for gif support in Android. Add the following line to your android/app/build.gradle file under dependencies:

compile 'com.facebook.fresco:animated-gif:0.12.0'  // For animated GIF support'

所以你的依赖section可能如下所示:

So your dependencies section might look like this:

dependencies {
  compile fileTree(dir: "libs", include: ["*.jar"])
  compile "com.android.support:appcompat-v7:23.0.1"
  compile "com.facebook.react:react-native:+"  // From node_modules
  compile 'com.facebook.fresco:animated-gif:0.10.0'  // For animated GIF support

这解决了你的调试版本的问题,但如果你想在你的发布版本中解决它,你必须在你的proguard规则文件中添加以下行:

This solves the problem for your debug build but if you want to solve it also in your release build at them moment you have to add the following line to your proguard-rules file:

-keep class com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl { public AnimatedFactoryImpl(com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory, com.facebook.imagepipeline.core.ExecutorSupplier); }

更多相关信息:https://github.com/facebook/fresco/issues/1177

这是用提交,并将包含在下一版本中。

This was fixed with this commit and will be included in the next release.

这篇关于如何在react-native android app中显示GIF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆