mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-31 05:51:47 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user