Skip to content

Commit

Permalink
Release 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ngnclht1102 committed Sep 21, 2021
1 parent 8f0b072 commit 06c5718
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 23 deletions.
Binary file added demo/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/error-placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default class RnCachedImage extends Component {
}),
sources: PropTypes.objectOf(Image.propTypes.source),
preferredPixelRatio: PropTypes.number,
renderImageElement: PropTypes.func,
onLoad: PropTypes.func,
onError: PropTypes.func,
placeholderSource: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
Expand Down
28 changes: 6 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ngnclht1102/rn-cached-image",
"version": "1.0.0",
"version": "1.0.1",
"description": "React native cached image component",
"main": "index.js",
"scripts": {
Expand All @@ -11,29 +11,13 @@
"url": "git+https://github.com/ngnclht1102/rn-cached-image.git"
},
"keywords": [
"fast",
"image",
"react",
"native",
"image",
"cached",
"image",
"react",
"native",
"fast",
"image",
"image",
"component",
"react",
"native",
"rn",
"cached",
"image",
"rn",
"images"
"fast image",
"react native image",
"cached image",
"rn cached image"
],
"author": "ngnclht1102 Brian",
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/ngnclht1102/rn-cached-image/issues"
},
Expand Down
72 changes: 72 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# A react native cached, animated and auto chooses the best-resolution image for the current screen.
#### This is a simple react native image component that
- enable image caching (save to cache directory).
- add loading animation while the image is loading.
- add error placeholder if image loading has any errors.
- also wrap the https://github.com/expo/react-native-responsive-image so it can choose the correct image size for loading

## Installation
```
yarn add @ngnclht/rn-cached-image
```

Import it with:

```js
import RNCachedImage from ' @ngnclht/rn-cached-image';
```

## Demo: Loading animation and caching

![Loading animation and caching](demo/demo.gif)

## Demo: Loading failed:

![Error placeholder](demo/error-placeholder.png)

## Usage

RNCachedImage accepts the same props as Image, and some new props.
For multiple sources, we have a new prop called `sources`. The `sources` prop is
an object whose keys are pixel ratios (that is, screen scales like "2" or "3").
Its values are Image sources to display on screens with the respective pixel ratio.

#### Multiple sources:

```js
<RNCachedImage
sources={{
1: { uri: 'https://example.com/icon-1x.png' },
2: { uri: 'https://example.com/icon-2x.png' },
3: { uri: 'https://example.com/icon-3x.png' },
}}
// (optional) force ResponsiveImage to load a specified pixel ratio
preferredPixelRatio={2}
/>
```
#### Caching

```js
<RNCachedImage
style={{
// some style
}}
animationOnLoadEndType='fade' // we support 'shrink', 'explode' and 'fade'
shouldCachedImage={true} // to enable caching or not
maxAgeInHours={72} // max age of the cache file, by default it is 72 hours (3 days)
source={{ uri: localSource }} // if you don't like the multiple sources, just use this prop as usual
sources={{
1: { uri: 'https://example.com/icon-1x.png' },
2: { uri: 'https://example.com/icon-2x.png' },
3: { uri: 'https://example.com/icon-3x.png' },
}}
animationWhileLoading={true} // enable animation while loading
reuseView={true} // allow update the view
placeholderColor={"#e0e5e5"} // animation's color for using while it is loading
errorPlaceholderSource={require('./your-image.png')} // the image will be used to show user when image loading failed
/>
```




0 comments on commit 06c5718

Please sign in to comment.