rni
react-native-image-with-placeholder
npm i react-native-image-with-placeholder
rni

react-native-image-with-placeholder

Load images incrementally to provide a better UX

by Crisoforo Gaspar Hernández

0.1.1 (see all)License:MITTypeScript:Not Found
npm i react-native-image-with-placeholder
Readme

React Native Image Placeholder

Load images incrementally to provide a better User Experience.

If you want to download larger images but provide with a nice transition while the users are waiting for the image you can provide with a smaller version of the image (as you can see on the examples).

This is inspired on how medium loads the articles and the iron-image component from the polymer library works by providing the option to present the larger image and give to the user a hint of the presence of an image, specially on slower connections.

It basically fetchs an image an tracks the progress of the image once is ready it shows the user the requeested image but during the period of loading the user can show a spinner or at least a hint of the image in a smaller version.

Examples

Multiple Images.

Single Image.

Installation

npm install --save react-native-image-with-placeholder

Getting started

Import the file as specified on the installation steps. Then import the Component where you have plans to use it, for example:

import ImagePlaceholder from 'react-native-image-with-placeholder'

And inside of the render method of your component add the component with the properties you require.

Basic usage

<ImagePlaceholder 
  style={{ flex: 1 }}
  duration={1000}
  activityIndicatorProps={{
    size: 'large',
    color: 'green',
  }}
  src='https://s3.amazonaws.com/crisoforo.com/flowers.jpg' 
  placeholder='https://s3.amazonaws.com/crisoforo.com/flowers-small.jpg'
  />
);

Multiple images with different transition speed

render() {
  return (
    <View style={styles.container}>
      <ImagePlaceholder 
        style={styles.item}
        src='https://s3.amazonaws.com/crisoforo.com/airplane.jpg' 
        placeholder='https://s3.amazonaws.com/crisoforo.com/airplane-mini.jpg'
      />
      <ImagePlaceholder 
        style={styles.item}
        duration={3000}
        src='https://s3.amazonaws.com/crisoforo.com/flowers.jpg' 
        placeholder='https://s3.amazonaws.com/crisoforo.com/flowers-small.jpg'
      />
      <ImagePlaceholder 
        style={styles.item}
        duration={1000}
        src='https://s3.amazonaws.com/crisoforo.com/sun.jpg' 
        placeholder='https://s3.amazonaws.com/crisoforo.com/sun-small.jpg'
      />
    </View>
    )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    flexWrap: 'wrap',
  },
  item: {
    flex: 1,
  }
});

API

PropsTypeOptionalDefaultDescription
srcStringfalsenullThe url of the main image to be fetched.
placeholderStringtruenullThe smaller image present before the main image is ready if is not present it will show an ActivityIndicator component instead.
styleView.propTypes.styletrueContainer StyleStyle applied to the image container
imageStyleObjecttruenullThe styles appliead to the main image.
placeholderStyleObjecttruenullThe styles applied to the placeholder image.
placeholderContainerStyleObjecttruenullThe styles applied to the container View of the placeholder image.
durationIntegertrue750Time in miliseconds used to transition to the original image once is ready.
showActivityIndicatorBooleantruetrueIf true an ActivityIndicator should be displayed while the placeholder image is being fetch or if is not present.
activityIndicatorPropsObjecttruenullOptions to pass to the ActivityIndicator component such as size, color or style.
ActivityIndicatorComponenttruenullIf present it will render this instead of the ActivityIndicator component and activityIndicatorProps is no longer used and valid.

Downloads/wk

15

GitHub Stars

30

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

3

OPEN ISSUES

3

OPEN PRs

1
VersionTagPublished
0.1.1
latest
5yrs ago
No alternatives found
No tutorials found
Add a tutorial