npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-cache-imagewrap

v1.0.1

Published

A wrapper for caching images from URIs locally and managing deletion.

Downloads

3

Readme

react-native-cache-imagewrap

Cached Image component for react native

This packages uses 2 peer dependencies :

@react-native-async-storage/async-storage

and

react-native-blob-util

Versions

Currently it supports

react-native-blob-util version 0.17.0 and react native 0.65 and up.

Installation

npm install react-native-cache-imagewrap --save
- or -
yarn add react-native-cache-imagewrap

We use react-native-blob-util and [@react-native-async-storage/async-storage] to handle file system access in this package and it requires an extra step during the installation.

Peer dependency installation

yarn add react-native-blob-util @react-native-async-storage/async-storage

Usage

CachedImage

CachedImage is a component that fetches and caches images in AsyncStorage for efficient rendering. You can use it as follows:

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

const YourComponent = () => {
  const imageUri = "https://example.com/your-image.jpg";

  return (
    <CachedImage
      uri={imageUri}
      cache={true} // Enable caching (default is true)
      imgProps={{ style: { width: 200, height: 200 } }} // ImageProps for customization
      retryCount={3} // Number of automatic retry attempts (default is 1)
    />
  );
};

| Prop Name | Type | Default Value | Description | | ----------- | ------------------------- | ------------- | --------------------------------------------------- | | uri | string | N/A | The URI of the image to be displayed. | | cache | boolean | true | Enable or disable image caching. | | headers | { [key: string]: string } | {} | HTTP headers for fetching the image. | | requestType | "GET" | "POST" | "GET" | HTTP request type for fetching the image. | | imgProps | ImageProps | {} | ImageProps for customization (e.g., width, height). | | retryCount | number | 1 | Number of automatic retry attempts. |

deleteCache

deleteCache is a function to delete a cached image from AsyncStorage. You can use it like this:

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

const imageUri = "https://example.com/your-image.jpg";

async function deleteCachedImage() {
  try {
    const result = await deleteCache(imageUri);
    console.log(result); // "cache deleted" if successful
  } catch (error) {
    console.error("Error deleting cache:", error);
  }
}

// Call the function to delete the cached image
deleteCachedImage();

prefetchImage

prefetchImage is a function for prefetching and caching images in AsyncStorage for later use. You can use it like this:

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

const imageUri = "https://example.com/your-image.jpg";

async function prefetchAndCacheImage() {
  try {
    await prefetchImage({ uri: imageUri });
    console.log("Image prefetched and cached successfully");
  } catch (error) {
    console.error("Error prefetching image:", error);
  }
}

// Call the function to prefetch and cache the image
prefetchAndCacheImage();