【问题标题】:Gif image is not working in android in react nativeGif 图像在反应原生的 android 中不起作用
【发布时间】:2018-11-04 12:01:36
【问题描述】:

动画在 android 的 gif 图像中不起作用

【问题讨论】:

标签: android react-native


【解决方案1】:

对于反应原生版本>=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'

【讨论】:

  • 你应该把这个放在哪里?你首先需要安装一个包吗?
  • 把它放在YourProject/android/app/build.gradle的dependencies下
  • 这适用于我使用 react native 0.64.2
  • 更新后不起作用反应原生 0.65 任何更新?
  • 谢谢@AnnieTan 我已经在我的回答中添加了这个。
【解决方案2】:

更新: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'

【讨论】:

【解决方案3】:

请遵循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);
}

【讨论】:

  • 此链接已损坏。
【解决方案4】:

对于 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%' }}
/> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-23
    • 2023-03-11
    • 1970-01-01
    • 2016-03-03
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2021-10-16
    相关资源
    最近更新 更多