I'm building an app using React Native with Expo. Everything works fine except the images, they load correctly but it takes about 2 seconds to load, and it's weird because all the images are local images and they are light too, so they should load instantly. This problem occurs also after I build and get the .apk on my android device so the images are always stored locally.
This is a portion of the main page of my app:
...
<View style={styles.bottomItem}>
<View style={styles.bottomItemInnerFirst}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('SecondPage')}>
<Image
source={require('../assets/images/iconT.jpg')}
style={{width: '100%', height: '100%'}}
resizeMode='contain'
/>
</TouchableOpacity>
</View>
</View>
...
The problem occurs not only with the Image tag but also with ImageBackground. I've looked at this doc too https://docs.expo.io/versions/latest/guides/preloading-and-caching-assets/ but I'm using local images and I don't know what to do to make it work.
React Native FastImage is a quick way to load images in React Native. All loaded pictures are aggressively cached by FastImage. You may add your own auth headers and preload pictures to your requests. GIF caching is also supported by react-native-fast-image.
React Native application are really slow most of the times. Large sets of the list, images, assets, API responses and multiple rendering, profiling, memorization, lazy-loading, I was thrown this many terms during the process of improving our application performance.
A view component for react-native with pinch to zoom, tap to move and double tap to zoom capability. You can zoom everything, from normal images, text and more complex nested views.
you can install new dependencies
npm install react-native-fast-image
and change Image into FastImage
for reference, you can visit this website:- https://www.npmjs.com/package/react-native-fast-image
this dependency will increase the loading of your Image
Asset Optimisation can also help you in expo. You can try the below commands to optimize assets in your project.
npm install -g sharp-cli
npx expo-optimize
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With