【发布时间】:2018-11-04 12:01:36
【问题描述】:
动画在 android 的 gif 图像中不起作用
【问题讨论】:
标签: android react-native
动画在 android 的 gif 图像中不起作用
【问题讨论】:
标签: android react-native
对于反应原生版本>=0.60:
在构建自己的原生代码时,Android 默认不支持 GIF 和 WebP。
您需要在android/app/build.gradle 中添加一些可选模块,具体取决于您应用的需要。
implementation 'com.facebook.fresco:fresco:2.0.0'
implementation 'com.facebook.fresco:animated-gif:2.0.0'
最新的 react native 版本 0.66:
implementation 'com.facebook.fresco:animated-gif:2.6.0'
【讨论】:
更新:react-native@0.57.0
// For animated GIF support
// ./android/app/build.gradle
implementation 'com.facebook.fresco:fresco:1.10.0'
implementation 'com.facebook.fresco:animated-gif:1.10.0'
【讨论】:
请遵循FB docs 中的详细信息,它将指定您需要的所需物品。
您需要在 android/app/build.gradle 中添加一些可选模块,具体取决于您的应用程序的需要。
dependencies {
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
compile 'com.facebook.fresco:animated-base-support:1.3.0'
// For animated GIF support
compile 'com.facebook.fresco:animated-gif:1.3.0'
// For WebP support, including animated WebP
compile 'com.facebook.fresco:animated-webp:1.3.0'
compile 'com.facebook.fresco:webpsupport:1.3.0'
// For WebP support, without animations
compile 'com.facebook.fresco:webpsupport:1.3.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);
}
【讨论】:
对于 React Native 版本:0.66.4
在 android/app/build.gradle 文件中添加以下这些行,
implementation 'com.facebook.fresco:fresco:2.0.0'
// For animated GIF support
implementation 'com.facebook.fresco:animated-gif:2.6.0'
// For WebP support, including animated WebP
implementation 'com.facebook.fresco:animated-webp:2.0.0'
implementation 'com.facebook.fresco:webpsupport:2.0.0'
并像这样使用它:
<Image
source={require('../assets/splah.gif')}
style={{ width: '100%',height:'100%' }}
/>
【讨论】: