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-lazy-image-loader

v1.1.5

Published

A React Native library for lazy loading and caching images

Downloads

61

Readme

react-native-lazy-image-loader

Supercharge your React Native app's image loading with advanced caching, lazy loading, and prefetching capabilities.

Lazy Loading Made Easy

npm downloads npm version license

Features

  • 🚀 Lazy loading for optimal performance
  • 💾 Intelligent caching system
  • 🔄 Prefetching for seamless user experience
  • 🎨 Customizable placeholders and error images
  • 📏 Automatic image resizing
  • 🔧 Flexible cache management
  • 👁️ Visibility culling for improved performance
  • 🔍 Dynamic image quality adjustment
  • 🌟 Smooth fade-in effect
  • 🖼️ Blurred placeholder while loading

Installation

Get started with a simple npm install:

npm install react-native-lazy-image-loader

Quick Start

Here's a basic example to get you up and running:

import React from 'react';
import { View } from 'react-native';
import { LazyImage } from 'react-native-lazy-image-loader';

const MyComponent = () => (
  <View>
    <LazyImage
      source={{ uri: 'https://example.com/image.jpg' }}
      style={{ width: 300, height: 200 }}
    />
  </View>
);

export default MyComponent;

Advanced Usage

Prefetching

Preload images for a buttery-smooth UX:

import { prefetchImages } from 'react-native-lazy-image-loader';

const imageUrls = [
  'https://example.com/image1.jpg',
  'https://example.com/image2.jpg',
];

prefetchImages(imageUrls);

Custom Placeholders

Add your own flair while images load:

<LazyImage
  source={{ uri: 'https://example.com/image.jpg' }}
  style={{ width: 300, height: 200 }}
  placeholderSource={require('./assets/placeholder.png')}
/>

Cache Management

Take control of your app's image cache:

import { clearCache, getCacheSize } from 'react-native-lazy-image-loader';

// Clear all cached images
clearCache();

// Get current cache size
const size = await getCacheSize();
console.log(`Current cache size: ${size} bytes`);

Visibility Culling

Optimize performance by only loading visible images:

<LazyImage
  source={{ uri: 'https://example.com/image.jpg' }}
  style={{ width: 300, height: 200 }}
  cullingDistance={300}
  onVisibilityChange={(isVisible) => console.log('Image visibility:', isVisible)}
/>

Fade Effect

Implement a smooth fade-in effect as images come into view:

<LazyImage
  source={{ uri: 'https://example.com/image.jpg' }}
  style={{ width: 300, height: 200 }}
  fade={true}
/>

Here's how the fade effect looks in action:

Fade Effect Demo

Blur Effect

Add a blurred placeholder while the image is loading:

<LazyImage
  source={{ uri: 'https://example.com/image.jpg' }}
  style={{ width: 300, height: 200 }}
  blurRadius={5}
/>

Here's how the blur effect looks in action:

Blur Effect Demo

API Reference

LazyImage

Utility Functions

  • prefetchImages(urls: string[]): Promise<void>
  • clearCache(): Promise<void>
  • getCacheSize(): Promise<number>

Performance Tips

  • Use cullingDistance to fine-tune when images start loading based on your app's scroll behavior.
  • Implement onVisibilityChange to pause/resume other operations based on image visibility.
  • Prefetch critical images during app initialization for instant display.
  • Utilize the priority prop to manage download order for important images.

Contributing

To contribute, please visit the GitHub repository at https://github.com/Valentine8342/react-native-lazy-image-cache.

License

This project is licensed under the MIT License - see the LICENSE file for details.