Skip to content

Commit

Permalink
fix: Call onLoad prop in SvgCssUri (#1927)
Browse files Browse the repository at this point in the history
SvgCssUri calls onLoad if it's passed, just like in PR #1817 (with SvgUri).
  • Loading branch information
mantasio authored Jan 4, 2023
1 parent 38da5fb commit 76b742c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ react-native run-android
#### Pre RN 0.68

4. Scroll to the bottom until you find:

```xml
<ImportGroup Label="ExtensionTargets">
```
Expand Down
4 changes: 2 additions & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ If remote SVG file contains CSS in `<style>` element, use `SvgCssUri`:
```jsx
import * as React from 'react';
import { ActivityIndicator, View, StyleSheet } from 'react-native';
import { SvgUri } from 'react-native-svg';
import { SvgCssUri } from 'react-native-svg';
export default function TestComponent() {
const [loading, setLoading] = React.useState(true);
const onError = (e: Error) => {
Expand All @@ -105,7 +105,7 @@ export default function TestComponent() {
};
return (
<>
<SvgUri
<SvgCssUri
width="100"
height="100"
uri="https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ruby.svg"
Expand Down
13 changes: 10 additions & 3 deletions src/css.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,18 @@ export function SvgCss(props: XmlProps) {
}

export function SvgCssUri(props: UriProps) {
const { uri, onError = err } = props;
const { uri, onError = err, onLoad } = props;
const [xml, setXml] = useState<string | null>(null);
useEffect(() => {
uri ? fetchText(uri).then(setXml).catch(onError) : setXml(null);
}, [onError, uri]);
uri
? fetchText(uri)
.then((data) => {
setXml(data);
onLoad?.();
})
.catch(onError)
: setXml(null);
}, [onError, uri, onLoad]);
return <SvgCss xml={xml} override={props} />;
}

Expand Down

0 comments on commit 76b742c

Please sign in to comment.