Skip to content

Commit

Permalink
Patch v0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
xerdnu committed Oct 19, 2023
1 parent 12420d8 commit 7a0c961
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [0.0.9] (2023-10-18)

#### Improvements

- Added the possiblity to pass both `single objects` and `arrays` to `BlastedImage.preload`.
- Added `promise` for `BlastedImage.preload` to indicate when the image has been processed.

#### Changes

- Updated documentation.

## [0.0.8] (2023-10-17)

#### Improvements
Expand Down Expand Up @@ -66,6 +77,7 @@

- Initial release.

[0.0.9]: https://github.com/xerdnu/react-native-blasted-image/compare/v0.0.8...v0.0.9
[0.0.8]: https://github.com/xerdnu/react-native-blasted-image/compare/v0.0.7...v0.0.8
[0.0.7]: https://github.com/xerdnu/react-native-blasted-image/compare/v0.0.6...v0.0.7
[0.0.6]: https://github.com/xerdnu/react-native-blasted-image/compare/v0.0.5...v0.0.6
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ BlastedImage.preload([
```jsx
import { NativeEventEmitter, NativeModules } from 'react-native';

const BlastedImageEvents = new NativeEventEmitter(NativeModules.BlastedImage);

useEffect(() => {
const subscription = BlastedImageEvents.addListener('BlastedEventLoaded', (data) => {
console.log(data.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable>
}

sendEvent(getReactApplicationContext(), "BlastedEventLoaded", message);

promise.resolve(true);

return false;
}
Expand Down
46 changes: 39 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const NativeBlastedImage = NativeModules.BlastedImage
);

export const loadImage = (imageUrl, headers = {}, skipMemoryCache = false) => {
return NativeBlastedImage.loadImage(imageUrl, headers, skipMemoryCache);
};
return NativeBlastedImage.loadImage(imageUrl, headers, skipMemoryCache)
.catch((error) => {
console.error("Error loading image:", error);
});
};

const BlastedImageView = requireNativeComponent('BlastedImageView');

Expand Down Expand Up @@ -134,12 +137,41 @@ BlastedImage.clearAllCaches = () => {
return NativeBlastedImage.clearAllCaches();
};

BlastedImage.preload = (images) => {
images.forEach(image => {
loadImage(image.uri, image.headers, image.skipMemoryCache).catch(() => {
// Log errors later if necessary
});
BlastedImage.preload = (input) => {
return new Promise((resolve) => {
// single object
if (typeof input === 'object' && input !== null && !Array.isArray(input)) {
loadImage(input.uri, input.headers, input.skipMemoryCache)
.then(() => {
resolve();
})
.catch((err) => {
console.error("Error preloading single image:", err);
resolve(); // Count as handled even if failed to continue processing
});
}
// array
else if (Array.isArray(input)) {
let loadedCount = 0;
input.forEach(image => {
loadImage(image.uri, image.headers, image.skipMemoryCache)
.then(() => {
loadedCount++;
if (loadedCount === input.length) {
resolve();
}
})
.catch((err) => {
console.error("Error preloading one of the array images:", err);
loadedCount++; // Count as handled even if failed to continue processing
if (loadedCount === input.length) {
resolve();
}
});
});
}
});
};


export default BlastedImage;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-blasted-image",
"version": "0.0.8",
"version": "0.0.9",
"description": "A simple yet powerful image component for React Native, powered by Glide and SDWebImage",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 7a0c961

Please sign in to comment.