Socket
Socket
Sign inDemoInstall

react-native-img-cache

Package Overview
Dependencies
9
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-img-cache

CachedImage component for React native


Version published
Weekly downloads
277
decreased by-7.36%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

React Native Image Cache

CircleCI

CachedImage component and Cache image manager for React Native. Based on this article.

Installation

npm install react-native-image-cache --save

react-native-fetch-blob

This package has a dependency with react-native-fetch-blob. If your project doesn't have a dependency with this package already, please refer to their installation instructions.

Usage

CachedImage

The CachedImage component assumes that the image URI will never change. The image is stored and served from the application cache.

import {CachedImage} from "react-native-image-cache";

<CachedImage source={{ uri: "https://i.ytimg.com/vi/yaqe1qesQ8c/maxresdefault.jpg" }} />

The mutable property implies assumes that the image URI can change over time. The lifetime of this cache is the one of the running application and it can be manually busted using ImageCache.

import {CachedImage} from "react-native-image-cache";

<CachedImage source={{ uri: "https://i.ytimg.com/vi/yaqe1qesQ8c/maxresdefault.jpg" }} mutable />

ImageCache

The ImageCache class can register observers to the cache.

const immutable = true;
const observer = (path: string) => {
    console.log(`path of the image in the cache: ${path}`);
};
ImageCache.getCache().on(uri, observer, immutable);

We use the observer pattern instead of a promise because a mutable image might have different version with different paths in the cache.

Observers can be deregistered using dispose:

ImageCache.getCache().dispose(uri, observer);

Keywords

FAQs

Last updated on 14 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc