From f3e132bb0b54f67970e9f946d97fac06c0b4868b Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Wed, 21 Feb 2024 08:26:57 -0800 Subject: [PATCH] Correctly pass Image.source attribute to the C++ side (#43129) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43129 ## Changelog: [Internal] - C++ side expects "source" property to be an up to date, correctly resolved Image source inside `ImageProps`. Incidentally, it wasn't the case when: * we build for an Android platform * the asset is a "packager asset", i.e. bundled by Metro and included in APK It hasn't been an issue in the case of "pure" Android platform, as it instead uses "src" prop, instead of source on the Java implementation side, ignoring "source" completely, so the fact that "source" wasn't propagated correctly to C++ in some cases didn't affect Android. However, there are some new use cases where we'd like to have correct "source" value in C++ as well (and ultimately align this between all the platforms, so it's "source" everywhere, but this is a matter of a separate discussion). Differential Revision: D54000899 fbshipit-source-id: 9bfb9e7c157cf19ddf396c141b03b75f3b2022e8 --- packages/react-native/Libraries/Image/Image.android.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/react-native/Libraries/Image/Image.android.js b/packages/react-native/Libraries/Image/Image.android.js index ac8660e968e63f..c113d24f2bc9cb 100644 --- a/packages/react-native/Libraries/Image/Image.android.js +++ b/packages/react-native/Libraries/Image/Image.android.js @@ -171,7 +171,11 @@ let BaseImage: AbstractImageAndroid = React.forwardRef( ...restProps, style, shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError), + // Both iOS and C++ sides expect to have "source" prop, whereas on Android it's "src" + // (for historical reasons). So in the latter case we populate both "src" and "source", + // in order to have a better alignment between platforms in the future. src: sources, + source: sources, /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found * when making Flow check .android.js files. */ headers: (source?.[0]?.headers || source?.headers: ?{[string]: string}),