Skip to content

Commit 739c02b

Browse files
committed
Cleanup
1 parent 1e54c64 commit 739c02b

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

packages/react-native-web/src/exports/Image/index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function raiseOnErrorEvent(uri, { onError, onLoadEnd }) {
157157
}
158158
if (onLoadEnd) onLoadEnd();
159159
}
160+
160161
function hasSourceDiff(a: ImageSource, b: ImageSource) {
161162
return (
162163
a.uri !== b.uri || JSON.stringify(a.headers) !== JSON.stringify(b.headers)
@@ -343,7 +344,8 @@ const BaseImage: ImageComponent = React.forwardRef((props, ref) => {
343344
});
344345

345346
/**
346-
* This component handles specifically loading an image source with header
347+
* This component handles specifically loading an image source with headers
348+
* default source is never loaded using headers
347349
*/
348350
const ImageWithHeaders: ImageComponent = React.forwardRef((props, ref) => {
349351
// $FlowIgnore
@@ -391,25 +393,27 @@ const ImageWithHeaders: ImageComponent = React.forwardRef((props, ref) => {
391393
});
392394

393395
// $FlowIgnore: This is the correct type, but casting makes it unhappy since the variables aren't defined yet
394-
const Image: ImageComponent & ImageStatics = React.forwardRef((props, ref) => {
395-
if (props.source && props.source.headers) {
396-
return <ImageWithHeaders ref={ref} {...props} />;
397-
}
396+
const ImageWithStatics: ImageComponent & ImageStatics = React.forwardRef(
397+
(props, ref) => {
398+
if (props.source && props.source.headers) {
399+
return <ImageWithHeaders ref={ref} {...props} />;
400+
}
398401

399-
return <BaseImage ref={ref} {...props} />;
400-
});
402+
return <BaseImage ref={ref} {...props} />;
403+
}
404+
);
401405

402-
Image.displayName = 'Image';
406+
ImageWithStatics.displayName = 'Image';
403407

404-
Image.getSize = function (uri, success, failure) {
408+
ImageWithStatics.getSize = function (uri, success, failure) {
405409
ImageLoader.getSize(uri, success, failure);
406410
};
407411

408-
Image.prefetch = function (uri) {
412+
ImageWithStatics.prefetch = function (uri) {
409413
return ImageLoader.prefetch(uri);
410414
};
411415

412-
Image.queryCache = function (uris) {
416+
ImageWithStatics.queryCache = function (uris) {
413417
return ImageLoader.queryCache(uris);
414418
};
415419

@@ -465,4 +469,4 @@ const resizeModeStyles = StyleSheet.create({
465469
}
466470
});
467471

468-
export default Image;
472+
export default ImageWithStatics;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const ImageLoader = {
125125
image.onload = (nativeEvent) => {
126126
// avoid blocking the main thread
127127
const onDecode = () => {
128+
// Append `source` to match RN's ImageLoadEvent interface
128129
nativeEvent.source = {
129130
uri: image.src,
130131
width: image.naturalWidth,
@@ -148,7 +149,6 @@ const ImageLoader = {
148149
return id;
149150
},
150151
loadWithHeaders(source: ImageSource): LoadRequest {
151-
let loadRequest: LoadRequest;
152152
let uri: string;
153153
const abortCtrl = new AbortController();
154154
const request = new Request(source.uri, {
@@ -176,7 +176,6 @@ const ImageLoader = {
176176
source,
177177
cancel: () => {
178178
abortCtrl.abort();
179-
if (loadRequest) loadRequest.cancel();
180179
URL.revokeObjectURL(uri);
181180
}
182181
};

0 commit comments

Comments
 (0)