All Projects → wcandillon → React Native Img Cache

wcandillon / React Native Img Cache

Licence: apache-2.0
Image Cache for React Native

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Native Img Cache

Ffimageloading
Image loading, caching & transforming library for Xamarin and Windows
Stars: ✭ 1,288 (+77.9%)
Mutual labels:  cache, image
Rximagepicker
Android图片相册预览选择器、支持AndroidX,支持图片的单选、多选、图片预览、图片文件夹切换、在选择图片时调用相机拍照
Stars: ✭ 85 (-88.26%)
Mutual labels:  cache, image
React Native Cached Image
CachedImage component for react-native
Stars: ✭ 890 (+22.93%)
Mutual labels:  cache, image
Kingfisher
A lightweight, pure-Swift library for downloading and caching images from the web.
Stars: ✭ 19,512 (+2595.03%)
Mutual labels:  cache, image
Sjnetwork
SJNetwork is a high level network request tool based on AFNetworking and inspired on YTKNetwork.
Stars: ✭ 231 (-68.09%)
Mutual labels:  cache, image
Bbwebimage
A high performance Swift library for downloading, caching and editing web images asynchronously.
Stars: ✭ 128 (-82.32%)
Mutual labels:  cache, image
Extended image
A powerful official extension library of image, which support placeholder(loading)/ failed state, cache network, zoom pan image, photo view, slide out page, editor(crop,rotate,flip), paint custom etc.
Stars: ✭ 1,021 (+41.02%)
Mutual labels:  cache, image
Recent Images
Do you noticed the new feature of Telegram or Instagram?! They show your latest images when you try to attach or post a picture. So I developed this library the same with lots of customization. Simple way to get all images of device based on date taken, name, id and other customization
Stars: ✭ 182 (-74.86%)
Mutual labels:  cache, image
Easystash
🗳Easy data persistence in Swift
Stars: ✭ 303 (-58.15%)
Mutual labels:  cache, image
Sdwebimage
Asynchronous image downloader with cache support as a UIImageView category
Stars: ✭ 23,928 (+3204.97%)
Mutual labels:  cache, image
React Native Fast Image
🚩 FastImage, performant React Native image component.
Stars: ✭ 6,500 (+797.79%)
Mutual labels:  image
Bbmetalimage
A high performance Swift library for GPU-accelerated image/video processing based on Metal.
Stars: ✭ 677 (-6.49%)
Mutual labels:  image
Dataloader
Implementation of Facebook's DataLoader in Golang
Stars: ✭ 703 (-2.9%)
Mutual labels:  cache
React Zmage
一个基于 React 的可缩放图片控件 | A scalable image wrapper power by react
Stars: ✭ 713 (-1.52%)
Mutual labels:  image
Viewerjs
JavaScript image viewer.
Stars: ✭ 6,270 (+766.02%)
Mutual labels:  image
Offix
GraphQL Offline Client and Server
Stars: ✭ 694 (-4.14%)
Mutual labels:  cache
Layzr.js
A modern lazy loading library for images.
Stars: ✭ 5,646 (+679.83%)
Mutual labels:  image
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs.
Stars: ✭ 674 (-6.91%)
Mutual labels:  cache
Mediumlightbox
Nice and elegant way to add zooming functionality for images, inspired by medium.com
Stars: ✭ 671 (-7.32%)
Mutual labels:  image
Nuxt Optimized Images
🌅🚀 Automatically optimizes images used in Nuxt.js projects (JPEG, PNG, SVG, WebP and GIF).
Stars: ✭ 717 (-0.97%)
Mutual labels:  image

React Native Image Cache

CircleCI npm version

CachedImage component and Cache image manager for React Native.

Deprecated

I am no longer maintaining this library but react-native-expo-image-cache which depends on ExpoKit.

Checkout 5 things to know about Images in React Native

Why do I need this?

Starting version 0.43, the React Native Image component has now a cache property: cache: force-cache (iOS only). This is a major improvement but only for iOS and at this time, I wasn't able to use it in a way that provides a user experience as smooth as this module.

Installation

rn-fetch-blob

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

npm install react-native-img-cache --save

Usage

CachedImage

The CachedImage component assumes that the image URI will never change. The image is stored and served from the application cache. This component accepts the same properties than Image except for a few difference:

  • source doesn't accept an array of image URIs like Image does. Please file an issue if that's something you would like to see supported.
  • The uri property in source is mandatory.
  • The body property in source is not supported. Please file an issue if that's something you would like to see supported.
import {CachedImage} from "react-native-img-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-img-cache";

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

Custom Image Component

By default, the CachedImage component is using the standard RN Image component. It is possible however to use a different component via CustomCachedImage. In the example below, we use the Image component from react-native-image-progress.

import {CustomCachedImage} from "react-native-img-cache";

import Image from 'react-native-image-progress';
import ProgressBar from 'react-native-progress/Bar';

<CustomCachedImage
  component={Image}
  source={{ uri: 'http://loremflickr.com/640/480/dog' }} 
  indicator={ProgressBar} 
  style={{
    width: 320, 
    height: 240, 
  }}/>

ImageCache

clear()

Remove cache entries and all physical files.

ImageCache.get().clear();

bust(uri)

ImageCache can be used to bust an image from the local cache. This removes the cache entry but it does not remove any physical files.

ImageCache.get().bust("https://i.ytimg.com/vi/yaqe1qesQ8c/maxresdefault.jpg");

cancel(uri)

It can also be used to cancel the download of an image. This can be very useful when scrolling through images.

ImageCache.get().cancel("https://i.ytimg.com/vi/yaqe1qesQ8c/maxresdefault.jpg");

on(uri, observer, immutable)

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.get().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.

dispose(uri, observer)

Observers can be deregistered using dispose:

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

Testing with jest

Mocking CachedImage

With jest, testing a snapshot can generate errors. Jest doesn't know how to generate the component CachedImage. For fix this, you have to mock CachedImage with Image component.

jest.mock('react-native-img-cache', () => {
  const mockComponent = require('react-native/jest/mockComponent')
  return {
    CustomCachedImage: mockComponent('Image'),
    CachedImage: mockComponent('Image'),
  }
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].