Gathering detailed insights and metrics for react-native-image-offline
Gathering detailed insights and metrics for react-native-image-offline
npm install react-native-image-offline
Typescript
Module System
Node Version
NPM Version
43.4
Supply Chain
64.6
Quality
69.5
Maintenance
25
Vulnerability
93.6
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
163,311
Last Day
17
Last Week
168
Last Month
786
Last Year
10,119
MIT License
82 Stars
58 Commits
26 Forks
6 Watchers
11 Branches
6 Contributors
Updated on Sep 12, 2023
Latest Version
0.1.9
Package Id
react-native-image-offline@0.1.9
Unpacked Size
334.34 MB
Size
137.87 MB
File Count
5,684
NPM Version
6.1.0
Node Version
10.4.1
Cumulative downloads
Total Downloads
Last Day
-59.5%
17
Compared to previous day
Last Week
-10.6%
168
Compared to previous week
Last Month
9.6%
786
Compared to previous month
Last Year
-68%
10,119
Compared to previous year
1
3
React Native library for iOS and Android offline image storage. This library provides most of the capabilities for an application to display pre-loaded images when offline. (This library has a dependency on rn-fetch-blob. Refer here for more details about the library.)
reloadImage={true}
irrespective of the image already being stored offline, this way you can refresh/load the most recently updated images.This library has a dependency on rn-fetch-blob
, please refer to their installation instructions
Using yarn
$ yarn add react-native-image-offline
Note: Do not forget to run react-native link
after adding rn-fetch-blob
dependency.
Using npm
$ npm install react-native-image-offline --save
restore
First and foremeost, to use this library it is important to call the restore
function so that you can get the completion status back. See the basic example usage.
OfflineImageStore.restore({}, () => {})
First argument is configuration object, example
{
name: 'My_Image_gallery',
imageRemoveTimeout: 120, // expire image after 120 seconds, default is 3 days if you don't provide this property.
debugMode: true,
}
Second argument is the callback function
const restoreCompletion = () => { // Callback function
console.log('Restore completed !');
// Restore completed!!
this.setState({ reStoreCompleted: true });
}
name
configuration property used to define the application offline store directory name
imageRemoveTimeout
is to provide image expiry time in seconds
debugMode
set to true
to view the debug logs
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
reStoreCompleted: false,
};
}
componentWillMount() {
OfflineImageStore.restore({
name: 'My_Image_gallery',
imageRemoveTimeout: 120, // expire image after 120 seconds, default is 3 days if you don't provide this property.
debugMode: true,
}, () => { // Callback function
console.log('Restore completed and callback called !');
// Restore completed!!
this.setState({ reStoreCompleted: true });
// Preload images
// Note: We recommend call this method on `restore` completion!
OfflineImageStore.preLoad([
'https://wallpaperbrowse.com/media/images/mobileswall-047.jpg',
'https://wallpaperbrowse.com/media/images/wallpaper-for-mobile-13.jpg',
'https://wallpaperbrowse.com/media/images/tvrcnkbcgeirbxcmsbfz.jpg',
'https://wallpaperbrowse.com/media/images/hd-wallpapers-1080p-for-mobile-2015.jpg',
'https://wallpaperbrowse.com/media/images/mobileswall-043.jpg',
'https://wallpaperbrowse.com/media/images/hd-wallpapers-for-mobile-2015.png',
'https://wallpaperbrowse.com/media/images/download_ZNNDLIt.jpg'
]);
});
}
render() {
if (!this.state.reStoreCompleted) {
return (
<ActivityIndicator
animating={ true }
style={ [{
alignItems: 'center',
justifyContent: 'center',
padding: 8,
}, { height: 80 }] }
size='large'
color={ '#A7A7A7' }
/>
);
}
return (
<View style={styles.container}>
<Text>React native offline image</Text>
<OfflineImage
key={'https://wrong-url/noImageExist.jpg'}
resizeMode={'center'}
style={ { width: '99%', height: 110, margin: 5 } }
fallbackSource={ Images.fallbackSource }
source={ { uri: 'https://wrong-url/noImageExist.jpg' } }/>
<OfflineImage
key={'https://wallpaperbrowse.com/media/images/wallpaper-for-mobile-13.jpg'}
onLoadEnd={(sourceUri) => {
console.log('Loading finished for image with path: ', sourceUri)
}}
reloadImage = { true }
resizeMode={'cover'}
fallbackSource={ Images.fallbackSource }
style={ { width: '99%', height: 110, margin: 5 } }
source={ { uri: 'https://wallpaperbrowse.com/media/images/wallpaper-for-mobile-13.jpg' } }/>
<OfflineImage
key={'https://wallpaperbrowse.com/media/images/tvrcnkbcgeirbxcmsbfz.jpg'}
onLoadEnd={(sourceUri) => {
console.log('Loading finished for image with path: ', sourceUri)
}}
resizeMode={'cover'}
style={ { width: '99%', height: 110, margin: 5 } }
source={ { uri: 'https://wallpaperbrowse.com/media/images/tvrcnkbcgeirbxcmsbfz.jpg' } }/>
<OfflineImage
key={'https://wallpaperbrowse.com/media/images/mobileswall-043.jpg'}
onLoadEnd={(sourceUri) => {
console.log('Loading finished for image with path: ', sourceUri)
}}
resizeMode={'cover'}
style={ { width: '99%', height: 110, margin: 5 } }
source={ { uri: 'https://wallpaperbrowse.com/media/images/mobileswall-043.jpg' } }/>
<OfflineImage
key={'https://wallpaperbrowse.com/media/images/butterfly-wallpaper_SzlKJB8.jpeg'}
onLoadEnd={(sourceUri) => {
console.log('Loading finished for image with path: ', sourceUri)
}}
resizeMode={'cover'}
fallbackSource={ Images.fallbackSource }
style={ { width: '99%', height: 110, margin: 5 } }
source={ { uri: 'https://wallpaperbrowse.com/media/images/butterfly-wallpaper_SzlKJB8.jpeg' } }/>
</View>
);
}
}
preload
The recommended approach to preload images is to call after restore
. You could call this method anywhere from the code. For instance, this library can be used with redux-observable
, here is the code snippet!
const loadShoppingCartEpic = (action$, store, { getJSON }) =>
action$.ofType(LOAD_SHOPPING_CART)
.flatMap(action => {
return getJSON(`${API_BASE_URL}/api/cart`)
.map(res => {
if (res.metadata.code === 200) {
// Preload image after successful response
// These images download and persist offline.
OfflineImageStore.preLoad([
'res.content.image1.link',
'res.content.image2.link',
]);
return loadShoppingCartSuccess(res.content);
} else {
return loadShoppingCartFailure();
}
})
._catch(error => Observable.of(loadShoppingCartFailure));
})
<OfflineImage component={ ImageBackground }
style={ [styles.swiperBackgroundImg, { width: this.props.width }] }
resizeMode="cover"
source={ require('../../../assets/images/placeholder/placeholder.png') }>
<View>...</View>
</OfflineImage>
You can use a fallback image as a default image to show when unable to download the image or if the image not available in the offline storage.
<OfflineImage component={ ImageBackground }
style={ [styles.swiperBackgroundImg, { width: this.props.width }] }
resizeMode="cover"
fallbackSource={ require('../../../assets/images/placeholder/placeholder.png') }
source={ { uri: this.props.shoppingCartItem.image.link } }>
<View>...</View>
</OfflineImage>
You can clear complete offline store at any point of time using
// Clean all the images
OfflineImageStore.clearStore((err) => {
if (!err) {
console.log('Hurray!! clearStore completed callback called');
}
});
Thanks to https://wallpaperbrowse.com/. These image uris are only used in a sample example application.
No vulnerabilities found.
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 4/20 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
95 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More