React Native Fast Image Cache Package – Android iOS Example

React native fast image NPM package is one of the best image caching library available for react native. As we all know from now on application speed dose matter and if your application has a lot’s of images then speed dose matter. On a basic android iOS application when we start the application and seeing images on it then it will load each application content like logo, app images or wallpapers each time when use starts the application again and again. This would make our application slower and hard to surf every time. It also usages lot’s of internet to load heavy images every time. But using the React Native Fast Image NPM package we can manage which content we want to load again or which content we want to save in mobile as cache. So when app run again then it will simply call the content from cache. So in this tutorial we would learn about React Native Fast Image Cache Package Android iOS Example.

Contents in this project React Native Fast Image Cache Package – Android iOS Example:-

1. The first step is to download and install the React Native Fast Image NPM package in our react native project. So open your react native project Root directory in Command prompt or Terminal and execute below command to install the package.

Screenshot of CMD:-


Screenshot of CMD after done installation :-

2. Next step is start coding for your app. Now open your project’s main App.js file and import View, StyleSheet, Text and FastImage component .

3. Creating our main export default function App. This is our main functional component.

4. Creating Return block and here we would make our FastImage component with its different props.

1. uri : Image URI or HTTP Image path.

2. headers : To load images with header source.

3. priority : To set image loading priority. Supported parameter is listed below.

FastImage.priority.low – Low Priority.
FastImage.priority.normal (Default) – Normal Priority.
FastImage.priority.high – High Priority.

4. cache : To cache images in application storage. Supported parameter is listed below.

FastImage.cacheControl.immutable – (Default) – Only updates if URL changes.
FastImage.cacheControl.web – Use headers and follow normal caching procedures.
FastImage.cacheControl.cacheOnly – Only show images from cache, do not make any network requests.

5. resizeMode :- To scale the image. Supported formats is listed below.

FastImage.resizeMode.contain – Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
FastImage.resizeMode.cover (Default) – Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
FastImage.resizeMode.stretch – Scale width and height independently, This may change the aspect ratio of the src.
FastImage.resizeMode.center – Do not scale the image, keep centered.

5. Creating Style.

6. Complete Source Code for App.js file:

Screenshot:-