From 09995fc8741cfdc6095d09627262b4f6fbbaafc2 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 31 Dec 2024 09:03:54 -0800 Subject: [PATCH] Change Image load event size info from logical size to pixel (#45198) Summary: Fixes https://github.com/facebook/react-native/issues/45188. This fixes old arch. fabric fix may wait until https://github.com/facebook/react-native/issues/44918. ## Changelog: [IOS] [BREAKING] - Change Image load event size info from logical size to pixel Pull Request resolved: https://github.com/facebook/react-native/pull/45198 Test Plan: Android/iOS return the same size . ``` { console.log( `RNImage:${Platform.OS} load JPEG image from url`, e.nativeEvent, ); }} /> ``` Reviewed By: cortinico Differential Revision: D67735347 Pulled By: cipolleschi fbshipit-source-id: 72422d8c15e4cc6313215bf6d9a2c1e6b5a235ad --- packages/react-native/Libraries/Image/RCTImageView.mm | 6 +++--- .../react/renderer/components/image/ImageEventEmitter.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/Image/RCTImageView.mm b/packages/react-native/Libraries/Image/RCTImageView.mm index 8cd0ec29df1..3e65fca9321 100644 --- a/packages/react-native/Libraries/Image/RCTImageView.mm +++ b/packages/react-native/Libraries/Image/RCTImageView.mm @@ -41,8 +41,8 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source) { NSDictionary *dict = @{ @"uri" : source.request.URL.absoluteString, - @"width" : @(source.size.width), - @"height" : @(source.size.height), + @"width" : @(source.size.width * source.scale), + @"height" : @(source.size.height * source.scale), }; return @{@"source" : dict}; } @@ -406,7 +406,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame) } } else { if (strongSelf->_onLoad) { - RCTImageSource *sourceLoaded = [source imageSourceWithSize:image.size scale:source.scale]; + RCTImageSource *sourceLoaded = [source imageSourceWithSize:image.size scale:image.scale]; strongSelf->_onLoad(onLoadParamsForSource(sourceLoaded)); } if (strongSelf->_onLoadEnd) { diff --git a/packages/react-native/ReactCommon/react/renderer/components/image/ImageEventEmitter.cpp b/packages/react-native/ReactCommon/react/renderer/components/image/ImageEventEmitter.cpp index 30d136f3479..f041351578e 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/image/ImageEventEmitter.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/image/ImageEventEmitter.cpp @@ -17,8 +17,8 @@ void ImageEventEmitter::onLoad(const ImageSource& source) const { dispatchEvent("load", [source](jsi::Runtime& runtime) { auto src = jsi::Object(runtime); src.setProperty(runtime, "uri", source.uri); - src.setProperty(runtime, "width", source.size.width); - src.setProperty(runtime, "height", source.size.height); + src.setProperty(runtime, "width", source.size.width * source.scale); + src.setProperty(runtime, "height", source.size.height * source.scale); auto payload = jsi::Object(runtime); payload.setProperty(runtime, "source", src); return payload;