From 7ccd8c5a79f05d5f00010bd4f28f564e56a5f327 Mon Sep 17 00:00:00 2001 From: Patrick Wehbe Date: Sat, 20 Jun 2026 14:18:34 +0300 Subject: [PATCH] feat: allow passing HTTP headers to SvgUri Thread an optional `headers` prop through the URI components so requests can carry custom HTTP headers, modelled on React Native's `ImageURISource.headers`. The prop is optional and defaults to the previous behaviour, so existing usage is unaffected. `fetchText`/`fetchUriData` now accept an optional headers map and forward it to `fetch(uri, { headers })`. `headers` is added to `UriProps` and passed from `SvgUri`, `SvgFromUri`, `SvgCssUri` and `SvgWithCssUri`, including in the effect/`componentDidUpdate` paths so changing the headers re-fetches. Closes #2320 --- apps/common/test/Test2320.tsx | 52 +++++++++++++++++++++++++++++++++++ apps/common/test/index.tsx | 1 + src/css/css.tsx | 23 +++++++++------- src/utils/fetchData.ts | 11 +++++--- src/xml.tsx | 33 ++++++++++++++-------- 5 files changed, 95 insertions(+), 25 deletions(-) create mode 100644 apps/common/test/Test2320.tsx diff --git a/apps/common/test/Test2320.tsx b/apps/common/test/Test2320.tsx new file mode 100644 index 000000000..a160cc762 --- /dev/null +++ b/apps/common/test/Test2320.tsx @@ -0,0 +1,52 @@ +import React from 'react'; +import {Button, View} from 'react-native'; +import {Circle, Svg, SvgUri} from 'react-native-svg'; + +// https://github.com/software-mansion/react-native-svg/issues/2320 +// SvgUri (and the other URI components) accept an optional `headers` prop +// that is forwarded to the underlying fetch call, mirroring +// ImageURISource.headers. +export default () => { + const [uri, setUri] = React.useState(null); + + // Keep the headers object referentially stable so the effect does not + // re-run and re-fetch on every render. + const headers = React.useMemo( + () => ({ + Authorization: 'Bearer example-token', + 'X-Custom-Header': 'react-native-svg', + }), + [], + ); + + return ( + + + + {uri && ( + + )} + +