mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 06:07:41 +00:00
Fix: image onLoad props (#2317)
# Summary Change data structure returned from the Image onLoad event. Add fix in new arch for returned sizes. ## Test Plan Manually test in both architectures and platforms. ### What's required for testing (prerequisites)? ### What are the steps to reproduce (after prerequisites)? ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ | --------- Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
This commit is contained in:
@@ -133,10 +133,14 @@ 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});
|
||||
|
||||
auto imageSource = _state->getData().getImageSource();
|
||||
imageSource.size = {image.size.width, image.size.height};
|
||||
if (_eventEmitter != nullptr) {
|
||||
static_cast<const RNSVGImageEventEmitter &>(*_eventEmitter).onLoad({.source = {
|
||||
.width = imageSource.size.width * imageSource.scale,
|
||||
.height = imageSource.size.height * imageSource.scale,
|
||||
.uri = imageSource.uri, }});
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_image = CGImageRetain(image.CGImage);
|
||||
self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image));
|
||||
@@ -203,18 +207,21 @@ 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));
|
||||
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];
|
||||
});
|
||||
}];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->_image = CGImageRetain(image.CGImage);
|
||||
self->_imageSize = CGSizeMake(CGImageGetWidth(self->_image), CGImageGetHeight(self->_image));
|
||||
if (self->_onLoad) {
|
||||
RCTImageSource *sourceLoaded = [src imageSourceWithSize:image.size scale:image.scale];
|
||||
NSDictionary *dict = @{
|
||||
@"uri" : sourceLoaded.request.URL.absoluteString,
|
||||
@"width" : @(sourceLoaded.size.width),
|
||||
@"height" : @(sourceLoaded.size.height),
|
||||
};
|
||||
self->_onLoad(@{@"source" : dict});
|
||||
}
|
||||
[self invalidate];
|
||||
});
|
||||
}];
|
||||
#endif // RCT_NEW_ARCH_ENABLED
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user