Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIF image not showing animation in react-native

Tags:

react-native

I am facing the problem with gif image in react-native.How to use gif image in react native. This is my code and I have placed the image in the images.js file.

like image 463
Shivani Chauhan Avatar asked Aug 25 '17 07:08

Shivani Chauhan


People also ask

Why GIF is not working in React native?

When building your own native code, GIF and WebP are not supported by default on Android. You will need to add some optional modules in android/app/build. gradle , depending on the needs of your app.

How do I add an animated gif to React native?

If you are using a lower react-native version, check react-native documentation for gif support for that particular version. After adding the dependency restart the server once using the following command. Step 4: Inside AddGif. js we will show GIf using Image component of the react-native library.

How do I show GIFs in React?

To render an animated gif in a React component: Import the gif as import myGif from './path-to-my-gif. gif' . Add an img element that shows the gif, e.g. <img src={myGif} alt="" /> .


2 Answers

Previously I fixed the issue of gif image displaying in ReactNative. You too fix this if you follow the following steps,

By default the Gif images are not supported in android react native app. You need to set use Fresco to display the gif images. The code:

Edit your android/app/build.gradle file and add the following code:


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.+' 

}

then you need to bundle the app again, You can display the gif images in two ways like this.

For RN >= 0.60

 implementation 'com.facebook.fresco:animated-gif:1.12.0' //instead of

 implementation 'com.facebook.fresco:animated-gif:2.0.0'   //use
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 }} 
/>

I hope it is helpful to others,

like image 125
Venkatesh Somu Avatar answered Nov 15 '22 09:11

Venkatesh Somu


Just like other assets image:

<Image
  source={require('./images/loading.gif')}
  style={{height: 200, width: 200}}
  resizeMode='contain'
/>

Note: You need to turn on GIF support for Android version

like image 40
pqkluan Avatar answered Nov 15 '22 11:11

pqkluan