Skip to content

Commit

Permalink
fix(@hippy/react-web): fix Image repeatedly triggering onError
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdyqin authored and hippy-actions[bot] committed Jul 17, 2023
1 parent 89f8ec0 commit 68727ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/hippy-react-web/src/components/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const Image: React.FC<ImageProps> = React.forwardRef((props: ImageProps, ref) =>
useElementLayout(imgRef, onLayout);

const [imgSource, setImgSource] = useState(defaultSource ? { uri: defaultSource } : source);
const [loadedSource, setLoadedSource] = useState('');

const onImageLoad = () => {
if (onLoad && isFunc(onLoad)) {
Expand All @@ -154,10 +155,11 @@ const Image: React.FC<ImageProps> = React.forwardRef((props: ImageProps, ref) =>
});
}
onLoadEnd();
setLoadedSource(source.uri);
};

// load source url when provide defaultSource
if (imgSource.uri !== source.uri) {
// first load source url when provide defaultSource
if (imgSource.uri !== source.uri && loadedSource !== source.uri) {
ImageLoader.load(source.uri, () => {
setImgSource(source);
onImageLoad();
Expand Down

0 comments on commit 68727ac

Please sign in to comment.