Giter Site home page Giter Site logo

dacastro4 / react-native-expo-image-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wcandillon/react-native-expo-image-cache

0.0 2.0 0.0 353 KB

React Native Image Cache and Progressive Loading based on Expo

License: MIT License

JavaScript 100.00%

react-native-expo-image-cache's Introduction

React Native Image Cache and Progressive Loading

CircleCI npm version

React Native image cache and progressive loading for iOS and Android. Based on Expo Kit.

This is a component used in the React Native Elements and the React Native Fiber starter kits.

Checkout this medium story about react-native-expo-image-cache.

Installation

This package has a peer dependency with React, React Native, and Expo.

yarn add react-native-expo-image-cache

Usage

Props

Props Default Options
tint dark light, dark, default
transitionDuration 300 custom in ms

import {Image} from "react-native-expo-image-cache";

// preview can be a local image or a data uri
const preview = { uri: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" };
const uri = "https://firebasestorage.googleapis.com/v0/b/react-native-e.appspot.com/o/b47b03a1e22e3f1fd884b5252de1e64a06a14126.png?alt=media&token=d636c423-3d94-440f-90c1-57c4de921641";
<Image style={{ height: 100, width: 100 }} {...{preview, uri}} />

CacheManager

Get the local image from a remote URI

import {CacheManager} from "react-native-expo-image-cache";

const {uri} = this.props;
const path = await CacheManager.get(uri).getPath();
// if path is undefined, the image download has failed 

You can also clear the local cache:

import {CacheManager} from "react-native-expo-image-cache";

await CacheManager.clearCache();

Set the cache directory

If you want to work in another cache directory, you can setup the cache directory.

import * as FileSystem from 'expo-file-system';
import {CacheManager, setBaseDir} from "react-native-expo-image-cache";
const uri = "https://www.google.com/favicon.ico"
setBaseDir(`${FileSystem.cacheDirectory}custom-cache-directoy`);
await CacheManager.get(uri).getPath(); // Cache the image.

Remove an entry from the cache

You can remove a file from cache with it's url like this :

import {CacheManager, removeCacheEntry} from "react-native-expo-image-cache";
const uri = "https://www.google.com/favicon.ico"
// Cache the image & get the images.
const localUri = await CacheManager.get(uri).getPath();
// Destroy the cached image
await removeCacheEntry(uri);

react-native-expo-image-cache's People

Contributors

animawolf avatar dacastro4 avatar fenghengzhi avatar louisjs avatar vkedwardli avatar wcandillon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.