Skip to content

Commit b433435

Browse files
committed
[add] Image: Append source to nativeEvent
1 parent 45ff86b commit b433435

File tree

1 file changed

+11
-2
lines changed
  • packages/react-native-web/src/modules/ImageLoader

1 file changed

+11
-2
lines changed

packages/react-native-web/src/modules/ImageLoader/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,18 @@ const ImageLoader = {
122122
id += 1;
123123
const image = new window.Image();
124124
image.onerror = onError;
125-
image.onload = (e) => {
125+
image.onload = (nativeEvent) => {
126126
// avoid blocking the main thread
127-
const onDecode = () => onLoad({ nativeEvent: e });
127+
const onDecode = () => {
128+
// Append `source` to match RN's ImageLoadEvent interface
129+
nativeEvent.source = {
130+
uri: image.src,
131+
width: image.naturalWidth,
132+
height: image.naturalHeight
133+
};
134+
135+
onLoad({ nativeEvent });
136+
};
128137
if (typeof image.decode === 'function') {
129138
// Safari currently throws exceptions when decoding svgs.
130139
// We want to catch that error and allow the load handler

0 commit comments

Comments
 (0)