Skip to content

Commit 74ab8f6

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Consistent API for Image Events
Summary: Changes the `onLoad` and `onError` events on `Image` to be consistent with each other and with the `ImageSource` type. Changelog: [Android][Breaking] - On `Image`, `onLoad` and `onError` event objects will no longer have an extra `uri` property. [Android][Breaking] - On `Image`, `onLoad` event objects' `source.url` is now renamed to `source.uri`. [iOS][Breaking] - On `Image`, `onLoad` event objects' `source.url` is now renamed to `source.uri`. Reviewed By: mdvacca Differential Revision: D22023565 fbshipit-source-id: 5ea7904c697f87e01118bdb81ed50ab0a5aecdce
1 parent 90997c2 commit 74ab8f6

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

Libraries/Image/ImageProps.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ export type ImageLoadEvent = SyntheticEvent<
2121
source: $ReadOnly<{|
2222
width: number,
2323
height: number,
24-
url: string,
24+
uri: string,
2525
|}>,
26-
uri?: string, // Only on Android
2726
|}>,
2827
>;
2928

Libraries/Image/RCTImageView.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ static BOOL RCTShouldReloadImageForSizeChange(CGSize currentSize, CGSize idealSi
4141
static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
4242
{
4343
NSDictionary *dict = @{
44+
@"uri": source.request.URL.absoluteString,
4445
@"width": @(source.size.width),
4546
@"height": @(source.size.height),
46-
@"url": source.request.URL.absoluteString,
4747
};
4848
return @{ @"source": dict };
4949
}

RNTester/js/examples/Image/ImageExample.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class NetworkImageCallbackExample extends React.Component<
7676
}
7777
onLoad={event => {
7878
if (event.nativeEvent.source) {
79-
const url = event.nativeEvent.source.url;
79+
const url = event.nativeEvent.source.uri;
8080
this._loadEventFired(
8181
`✔ onLoad (+${new Date() - mountTime}ms) for URL ${url}`,
8282
);
@@ -127,7 +127,7 @@ class NetworkImageCallbackExample extends React.Component<
127127
onLoad={event => {
128128
// Currently this image source feature is only available on iOS.
129129
if (event.nativeEvent.source) {
130-
const url = event.nativeEvent.source.url;
130+
const url = event.nativeEvent.source.uri;
131131
this._loadEventFired(
132132
`✔ (prefetched) onLoad (+${new Date() -
133133
mountTime}ms) for URL ${url}`,

ReactAndroid/src/main/java/com/facebook/react/views/image/ImageLoadEvent.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,10 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {
107107
switch (mEventType) {
108108
case ON_LOAD:
109109
eventData = Arguments.createMap();
110-
// TODO: Remove this (to be less redundant and to be consistent with iOS).
111-
eventData.putString("uri", mSourceUri);
112110
eventData.putMap("source", createEventDataSource());
113111
break;
114112
case ON_ERROR:
115113
eventData = Arguments.createMap();
116-
// TODO: Remove this (to be less redundant and to be consistent with iOS).
117-
eventData.putString("uri", mSourceUri);
118114
eventData.putString("error", mErrorMessage);
119115
break;
120116
}
@@ -124,9 +120,9 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {
124120

125121
private WritableMap createEventDataSource() {
126122
WritableMap source = Arguments.createMap();
123+
source.putString("uri", mSourceUri);
127124
source.putDouble("width", mWidth);
128125
source.putDouble("height", mHeight);
129-
source.putString("url", mSourceUri);
130126
return source;
131127
}
132128
}

0 commit comments

Comments
 (0)