如何在react native中显示动画gif?这就是我尝试过的。
<Image source={{uri: "loading"}} />
.png文件可以正常工作,但是当我使用.gif文件时,它为空白。我在某处阅读过,尝试将.gif重命名为.png,但这仅显示了动画gif的一帧而没有动画。有任何想法吗?
对于RN <0.60
默认情况下,android react native应用程序不支持Gif图像。您需要设置使用Fresco显示gif图像。代码:
编辑android/app/build.gradle
文件并添加以下代码:
dependencies: {
...
compile 'com.facebook.fresco:fresco:1.+'
// For animated GIF support
compile 'com.facebook.fresco:animated-gif:1.+'
// For WebP support, including animated WebP
compile 'com.facebook.fresco:animated-webp:1.+'
compile 'com.facebook.fresco:webpsupport:1.+'
}
那么您需要再次捆绑该应用。您可以通过两种方式显示gif图像。
1-> <Image
source={require('./../images/load.gif')}
style={{width: 100, height: 100 }}
/>
2-> <Image
source={{uri: 'http://www.clicktorelease.com/code/gif/1.gif'}}
style={{width: 100, height:100 }}
/>
对于RN> = 0.60
implementation 'com.facebook.fresco:animated-gif:1.12.0' //instead of
implementation 'com.facebook.fresco:animated-gif:2.0.0' //use
我希望它对其他人有帮助,
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句