https://github.com/sponk-eu/react-native-realm-cache-image
https://github.com/sponk-eu/react-native-realm-cache-image
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sponk-eu/react-native-realm-cache-image
- Owner: sponk-eu
- License: mit
- Created: 2016-10-18T23:21:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-13T01:12:50.000Z (over 7 years ago)
- Last Synced: 2025-03-28T15:46:42.649Z (about 1 month ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# React Native Realm CacheImage (forked from remobile)
A cache-image for react-native
* When use web image, this module will find the web image's url corresponding image file is exist or not, if exist, it will use local exist file, and check this CacheImage's old url and new url, if old url is the same as new url, do noting. if not, sub old url's ref and add new url's ref, if old url's ref is 0, delete old url corresponding image file.
* it also will check total storage, total storage is 1024*1024*50, when local file total size is above total storage, it will delete the oldest local file and clear corresponding record.## Installation
1) FS: https://github.com/johanneslumpe/react-native-fs
2) Realm: https://realm.io/docs/react-native/latest/#installation
3) Command:
```sh
npm install --save react-native-realm-cache-image
```
## Usage### Example
```js
'use strict';var Realm = require('realm');
var React = require('react-native');var {
StyleSheet,
View,
} = React;var CacheImage = require('react-native-realm-cache-image');
// You can push schema wrote by self into this array.
var _realm = new Realm({schema: CacheImage.getSchemaRealm()});
CacheImage.setup(_realm);var CacheImageIdMgr = {
CACHE_ID_USER_HEAD: 0,
CACHE_ID_USER_HEAD1: 1,
CACHE_ID_USER_HEAD2: 2,
};var SERVER = 'http://192.168.1.117:3000/';
module.exports = React.createClass({
render: function() {
return (
);
}
});var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
image: {
width:200,
height:200,
}
});
```#### Props
This module supports react-native Image's props all.
- `defaultImage : PropTypes.string.isRequired` - local image for default image
- `url : PropTypes.string.isRequired` - the url of web image
* format: 'http://{server}/{name}.png' or 'http://{server}/{name}.jpg'
* must have jpg or png suffix
* {name} must have version. e.g: first version is verison1.jpg, when you want to update image, you can use verison2.jpg, otherwise this module will not download image
- `cacheId : PropTypes.number.isRequired` - the unique image id for a CacheImage
* make sure every CacheImage's cacheId is unique
* like
* ``` var CacheImageIdMgr = {
CACHE_ID_USER_HEAD: 0,
CACHE_ID_USER_HEAD1: 1,
CACHE_ID_USER_HEAD2: 2,
}; ```