Skip to content

Commit d28eceb

Browse files
committed
[add] load images with http headers
1 parent e0f3204 commit d28eceb

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
@@ -185,7 +185,7 @@ const Image: React.AbstractComponent<
185185
);
186186
}
187187
}
188-
188+
const [loadedUri, setLoadedUri] = React.useState('');
189189
const [state, updateState] = React.useState(() => {
190190
const uri = resolveAssetUri(source);
191191
if (uri != null) {
@@ -210,7 +210,7 @@ const Image: React.AbstractComponent<
210210
filterRef.current
211211
);
212212
const resizeMode = props.resizeMode || _resizeMode || 'cover';
213-
const selectedSource = shouldDisplaySource ? source : defaultSource;
213+
const selectedSource = shouldDisplaySource ? loadedUri : defaultSource;
214214
const displayImageUri = resolveAssetUri(selectedSource);
215215
const imageSizeStyle = resolveAssetDimensions(selectedSource);
216216
const backgroundImage = displayImageUri ? `url("${displayImageUri}")` : null;
@@ -256,22 +256,23 @@ const Image: React.AbstractComponent<
256256
}
257257

258258
// Image loading
259-
const uri = resolveAssetUri(source);
260259
React.useEffect(() => {
261260
abortPendingRequest();
262261

262+
const uri = resolveAssetUri(source);
263263
if (uri != null) {
264264
updateState(LOADING);
265265
if (onLoadStart) {
266266
onLoadStart();
267267
}
268268

269269
requestRef.current = ImageLoader.load(
270-
uri,
271-
function load(e) {
270+
{ uri, headers: source?.headers },
271+
function load(result) {
272272
updateState(LOADED);
273+
setLoadedUri(result.uri);
273274
if (onLoad) {
274-
onLoad(e);
275+
onLoad(result);
275276
}
276277
if (onLoadEnd) {
277278
onLoadEnd();
@@ -301,7 +302,7 @@ const Image: React.AbstractComponent<
301302
}
302303

303304
return abortPendingRequest;
304-
}, [uri, requestRef, updateState, onError, onLoad, onLoadEnd, onLoadStart]);
305+
}, [source, updateState, onError, onLoad, onLoadEnd, onLoadStart]);
305306

306307
return (
307308
<View

0 commit comments

Comments
 (0)