Skip to content

Commit

Permalink
RN: Consistent API for Image Events
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yungsters authored and facebook-github-bot committed Jun 16, 2020
1 parent 90997c2 commit 74ab8f6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Libraries/Image/ImageProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export type ImageLoadEvent = SyntheticEvent<
source: $ReadOnly<{|
width: number,
height: number,
url: string,
uri: string,
|}>,
uri?: string, // Only on Android
|}>,
>;

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ static BOOL RCTShouldReloadImageForSizeChange(CGSize currentSize, CGSize idealSi
static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
{
NSDictionary *dict = @{
@"uri": source.request.URL.absoluteString,
@"width": @(source.size.width),
@"height": @(source.size.height),
@"url": source.request.URL.absoluteString,
};
return @{ @"source": dict };
}
Expand Down
4 changes: 2 additions & 2 deletions RNTester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NetworkImageCallbackExample extends React.Component<
}
onLoad={event => {
if (event.nativeEvent.source) {
const url = event.nativeEvent.source.url;
const url = event.nativeEvent.source.uri;
this._loadEventFired(
`✔ onLoad (+${new Date() - mountTime}ms) for URL ${url}`,
);
Expand Down Expand Up @@ -127,7 +127,7 @@ class NetworkImageCallbackExample extends React.Component<
onLoad={event => {
// Currently this image source feature is only available on iOS.
if (event.nativeEvent.source) {
const url = event.nativeEvent.source.url;
const url = event.nativeEvent.source.uri;
this._loadEventFired(
`✔ (prefetched) onLoad (+${new Date() -
mountTime}ms) for URL ${url}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,10 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {
switch (mEventType) {
case ON_LOAD:
eventData = Arguments.createMap();
// TODO: Remove this (to be less redundant and to be consistent with iOS).
eventData.putString("uri", mSourceUri);
eventData.putMap("source", createEventDataSource());
break;
case ON_ERROR:
eventData = Arguments.createMap();
// TODO: Remove this (to be less redundant and to be consistent with iOS).
eventData.putString("uri", mSourceUri);
eventData.putString("error", mErrorMessage);
break;
}
Expand All @@ -124,9 +120,9 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {

private WritableMap createEventDataSource() {
WritableMap source = Arguments.createMap();
source.putString("uri", mSourceUri);
source.putDouble("width", mWidth);
source.putDouble("height", mHeight);
source.putString("url", mSourceUri);
return source;
}
}

0 comments on commit 74ab8f6

Please sign in to comment.