add onLoad prop to Image component (#2293)

# Summary

Closes #1442

We want to add new props to the Image Component.

## Test Plan

Added the Test component. 
Manually test that in Android and IOS platforms on new and old
Architectures.

### What are the steps to reproduce (after prerequisites)?

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |         |
This commit is contained in:
Bohdan Artiukhov
2024-06-27 16:10:28 +02:00
committed by GitHub
parent 7b5d4daaed
commit c0ee3e9ca0
13 changed files with 225 additions and 9 deletions
+1
View File
@@ -32,5 +32,6 @@
@property (nonatomic, strong) RNSVGLength *imageheight;
@property (nonatomic, strong) NSString *align;
@property (nonatomic, assign) RNSVGVBMOS meetOrSlice;
@property (nonatomic, copy) RCTDirectEventBlock onLoad;
@end
+16 -6
View File
@@ -133,6 +133,10 @@ using namespace facebook::react;
// See for more info: T46311063.
return;
}
auto imageSource = _state->getData().getImageSource();
imageSource.size = {image.size.width, image.size.height};
static_cast<const RNSVGImageEventEmitter &>(*_eventEmitter).onLoad({imageSource.size.width, imageSource.size.height, imageSource.uri});
dispatch_async(dispatch_get_main_queue(), ^{
self->_image = CGImageRetain(image.CGImage);
self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image));
@@ -199,12 +203,18 @@ using namespace facebook::react;
_reloadImageCancellationBlock = [[self.bridge moduleForName:@"ImageLoader"]
loadImageWithURLRequest:src.request
callback:^(NSError *error, UIImage *image) {
dispatch_async(dispatch_get_main_queue(), ^{
self->_image = CGImageRetain(image.CGImage);
self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image));
[self invalidate];
});
}];
dispatch_async(dispatch_get_main_queue(), ^{
self->_image = CGImageRetain(image.CGImage);
self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image));
RCTImageSource *sourceLoaded = [src imageSourceWithSize:image.size scale:image.scale];
self->_onLoad(@{
@"width" : @(sourceLoaded.size.width),
@"height" : @(sourceLoaded.size.height),
@"uri" : sourceLoaded.request.URL.absoluteString
});
[self invalidate];
});
}];
#endif // RCT_NEW_ARCH_ENABLED
}
+1
View File
@@ -36,5 +36,6 @@ RCT_CUSTOM_VIEW_PROPERTY(height, id, RNSVGImage)
RCT_EXPORT_VIEW_PROPERTY(src, RCTImageSource)
RCT_EXPORT_VIEW_PROPERTY(align, NSString)
RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS)
RCT_EXPORT_VIEW_PROPERTY(onLoad, RCTDirectEventBlock);
@end