Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 507ecb5

Browse files
committed
Add onLoadFinished callback with image width and height
1 parent a4f6c2e commit 507ecb5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/imageCacheHoc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default function imageCacheHoc(Image, options = {}) {
6262
component: PropTypes.func,
6363
props: PropTypes.object,
6464
}),
65+
onLoadFinished: PropTypes.func,
6566
};
6667

6768
/**
@@ -238,6 +239,17 @@ export default function imageCacheHoc(Image, options = {}) {
238239
// See: https://github.com/billmalarky/react-native-image-cache-hoc/issues/6#issuecomment-354490597
239240
if (this._isMounted && localFilePath) {
240241
this.setState({ localFilePath });
242+
243+
if (this.props.onLoadFinished) {
244+
Image.getSize(
245+
Platform.OS === 'ios' ? localFilePath : 'file://' + localFilePath,
246+
(width, height) => {
247+
if (this._isMounted) {
248+
this.props.onLoadFinished(width, height);
249+
}
250+
}
251+
);
252+
}
241253
}
242254
}
243255

tests/CacheableImage.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe('CacheableImage', function () {
9494
'permanent',
9595
'style',
9696
'placeholder',
97+
'onLoadFinished',
9798
]);
9899
});
99100

0 commit comments

Comments
 (0)