Skip to content

Commit ea19c28

Browse files
committed
[add] load images with http headers
1 parent f81505c commit ea19c28

File tree

1 file changed

+8
-7
lines changed
  • packages/react-native-web/src/exports/Image

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const Image: React.AbstractComponent<
190190
);
191191
}
192192
}
193-
193+
const [loadedUri, setLoadedUri] = React.useState('');
194194
const [state, updateState] = React.useState(() => {
195195
const uri = resolveAssetUri(source);
196196
if (uri != null) {
@@ -215,7 +215,7 @@ const Image: React.AbstractComponent<
215215
filterRef.current
216216
);
217217
const resizeMode = props.resizeMode || _resizeMode || 'cover';
218-
const selectedSource = shouldDisplaySource ? source : defaultSource;
218+
const selectedSource = shouldDisplaySource ? loadedUri : defaultSource;
219219
const displayImageUri = resolveAssetUri(selectedSource);
220220
const imageSizeStyle = resolveAssetDimensions(selectedSource);
221221
const backgroundImage = displayImageUri ? `url("${displayImageUri}")` : null;
@@ -261,22 +261,23 @@ const Image: React.AbstractComponent<
261261
}
262262

263263
// Image loading
264-
const uri = resolveAssetUri(source);
265264
React.useEffect(() => {
266265
abortPendingRequest();
267266

267+
const uri = resolveAssetUri(source);
268268
if (uri != null) {
269269
updateState(LOADING);
270270
if (onLoadStart) {
271271
onLoadStart();
272272
}
273273

274274
requestRef.current = ImageLoader.load(
275-
uri,
276-
function load(e) {
275+
{ uri, headers: source?.headers },
276+
function load(result) {
277277
updateState(LOADED);
278+
setLoadedUri(result.uri);
278279
if (onLoad) {
279-
onLoad(e);
280+
onLoad(result);
280281
}
281282
if (onLoadEnd) {
282283
onLoadEnd();
@@ -306,7 +307,7 @@ const Image: React.AbstractComponent<
306307
}
307308

308309
return abortPendingRequest;
309-
}, [uri, requestRef, updateState, onError, onLoad, onLoadEnd, onLoadStart]);
310+
}, [source, updateState, onError, onLoad, onLoadEnd, onLoadStart]);
310311

311312
return (
312313
<View

0 commit comments

Comments
 (0)