原因:
android 没有安装依赖
解决:在 android/app/build.gradle 添加
dependencies {
// 如果你需要支持Android4.0(API level 14)之前的版本
implementation 'com.facebook.fresco:animated-base-support:1.10.0'
// 如果你需要支持GIF动图
implementation 'com.facebook.fresco:animated-gif:1.12.0'
// 如果你需要支持WebP格式,包括WebP动图
implementation 'com.facebook.fresco:animated-webp:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.10.0'
// 如果只需要支持WebP格式而不需要动图
implementation 'com.facebook.fresco:webpsupport:1.10.0'
}
附加:另外,如果将GIF与ProGuard一起使用,则需要在proguard-rules.pro中添加此规则
-keep class com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl {
public AnimatedFactoryImpl(com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory, com.facebook.imagepipeline.core.ExecutorSupplier);
}
版本:RN >= 0.60
//implementation 'com.facebook.fresco:animated-gif:1.12.0' //注释
implementation 'com.facebook.fresco:animated-gif:2.0.0' //使用
测试:
<Image
source={require('./../images/load.gif')}
style={{width: 100, height: 100 }}
/>
<Image
source={{uri: 'http://www.clicktorelease.com/code/gif/1.gif'}}
style={{width: 100, height:100 }}
/>
参考大佬
https://facebook.github.io/react-native/docs/0.42/image
https://stackoverflow.com/questions/35594783/how-do-i-display-an-animated-gif-in-react-native