Skip to content

Commit

Permalink
Correctly pass Image.source attribute to the C++ side (#43129)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
rshest authored and facebook-github-bot committed Feb 21, 2024
1 parent ee2bc59 commit f3e132b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Expand Down

0 comments on commit f3e132b

Please sign in to comment.