Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support WebP images in react native?

I have to show .WebP image extension images in my react-native app. I'm running on iOS and it's not displaying any image. I googled and found some information saying that webP images won't support on iOS and need to use a library or have to write an extension to support that. I used this react-native library to support webP. Still, I'm not getting. Can someone please advice on this? How to do that?

Note: Please don't mark this as a duplicate. I already checked StackOverflow and didn't find the answer. The issue might similar to webp images problem-stackoverflow

like image 761
Sivajee Battina Avatar asked Jul 13 '17 10:07

Sivajee Battina


People also ask

Are WebP images supported?

Image format (based on the VP8 video format) that supports lossy and lossless compression, as well as animation and alpha transparency. WebP generally has better compression than JPEG, PNG and GIF and is designed to supersede them. AVIF and JPEG XL are designed to supersede WebP.

How do I import an image into react-native?

Adding Image Let us create a new folder img inside the src folder. We will add our image (myImage. png) inside this folder. We will show images on the home screen.

How well supported is WebP?

WebP image format on Android Browser is fully supported on 4.4-103, partially supported on 4.1-4, and not supported on 2.3-3 Android Browser versions. WebP image format on Opera Mobile is fully supported on 11.5-64, partially supported on 11-11, and not supported on 10-10 Opera Mobile versions.


1 Answers

Use https://github.com/DylanVann/react-native-fast-image this package . I too was having issue loading .webp images on IOS I used this which has added support for .webp images which solved my issue.

According to the repo you must be using React Native 0.60.0 or higher to use the most recent version of react-native-fast-image.

If the image still doesn't load try making this changes on you AppDelegate.m as suggested on this issue https://github.com/DylanVann/react-native-fast-image/issues/522:

#import "SDImageCodersManager.h"
#import <SDWebImageWebPCoder/SDImageWebPCoder.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // . . .

    [SDImageCodersManager.sharedManager addCoder:SDImageWebPCoder.sharedCoder];

    // . . .
}
like image 136
Mandip Giri Avatar answered Oct 07 '22 07:10

Mandip Giri