Webp在React-Native上 [英] Webp on React-Native
问题描述
React-Native文档提到Android上不支持webp,但没有提及IOS.开箱即用似乎无法使用,但是在安装此插件后 https://libraries. io/npm/react-native-webp 我可以使用从互联网下载的图像.
React-Native documentation mentions that webp is not supported on Android, but says nothing about IOS. Out of the box it does not seem to work, but after installing this plugin https://libraries.io/npm/react-native-webp I can use images downloaded from internet.
问题是本地文件给我一个错误
Problem is that local files give me an error
:"{" type":InternalError","message":"react-packager遇到了 内部错误,请检查您的终端错误输出以获取更多信息 详细信息"}
: "{"type":InternalError","message":"react-packager has encountered an internal error, please check your terminal error output for more details"}
不幸的是,"react-native log-ios"命令仅在此处显示相同的错误.
Unfortunately "react-native log-ios" command merely shows the same error there.
这是我在安装插件后使用webp文件的方式.
This is how I use the webp file after installing the plugin.
<Image
source={require('../../assets/icon.webp')}
/>
如何在React-native iOS上使用本地.webp图像?
How can I use local .webp images on React-native iOS?
推荐答案
我建议使用: https://github.com/Aleksefo/react-native-webp-format
在iOS和Android上均可使用.不需要单独导入,您可以将其与标准Image/ImageBackground组件一起使用,例如:
Works on both iOS and Android. Doesn't need a separate import, you can just use it with standard Image/ImageBackground component like:
<Image source={require('../../assets/example.webp')} />
这篇关于Webp在React-Native上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!