mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 22:51:09 +08:00
[fix] Image EncodingError for SVG in Safari iOS 11
Fixes an EncodingError exception being thrown in Safari iOS 11 when decoding an SVG URL. The exception prevents the onLoad handler from being called. Close #1063
This commit is contained in:
committed by
Nicolas Gallagher
parent
744aaa26d4
commit
b9172ceb8e
@@ -52,12 +52,14 @@ const ImageLoader = {
|
||||
image.onerror = onError;
|
||||
image.onload = e => {
|
||||
// avoid blocking the main thread
|
||||
const onDecode = () => onLoad(e);
|
||||
if (typeof image.decode === 'function') {
|
||||
image.decode().then(() => { onLoad(e) });
|
||||
// Safari currently throws exceptions when decoding svgs.
|
||||
// We want to catch that error and allow the load handler
|
||||
// to be forwarded to the onLoad handler in this case
|
||||
image.decode().then(onDecode, onDecode);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
onLoad(e);
|
||||
}, 0);
|
||||
setTimeout(onDecode, 0);
|
||||
}
|
||||
};
|
||||
image.src = uri;
|
||||
|
||||
Reference in New Issue
Block a user