mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
fix Image Exception on Android
This commit is contained in:
@@ -11,35 +11,18 @@ package com.horcrux.svg;
|
|||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.BitmapShader;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffXfermode;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.RectF;
|
|
||||||
import android.graphics.Shader;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.facebook.common.logging.FLog;
|
|
||||||
import com.facebook.common.util.UriUtil;
|
import com.facebook.common.util.UriUtil;
|
||||||
import com.facebook.drawee.interfaces.DraweeController;
|
|
||||||
import com.facebook.imagepipeline.request.ImageRequest;
|
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -49,7 +32,10 @@ import javax.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
public class RNSVGImageShadowNode extends RNSVGPathShadowNode {
|
public class RNSVGImageShadowNode extends RNSVGPathShadowNode {
|
||||||
|
|
||||||
private ReadableMap mLayout;
|
private String mX;
|
||||||
|
private String mY;
|
||||||
|
private String mW;
|
||||||
|
private String mH;
|
||||||
private ReadableMap mSrc;
|
private ReadableMap mSrc;
|
||||||
private Uri mUri;
|
private Uri mUri;
|
||||||
private boolean mLocalImage;
|
private boolean mLocalImage;
|
||||||
@@ -78,7 +64,6 @@ public class RNSVGImageShadowNode extends RNSVGPathShadowNode {
|
|||||||
bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
|
bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("URI", "" + e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
@@ -96,9 +81,27 @@ public class RNSVGImageShadowNode extends RNSVGPathShadowNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactProp(name = "layout")
|
@ReactProp(name = "x")
|
||||||
public void setLayout(@Nullable ReadableMap layout) {
|
public void setX(String x) {
|
||||||
mLayout = layout;
|
mX = x;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = "y")
|
||||||
|
public void setY(String y) {
|
||||||
|
mY = y;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = "width")
|
||||||
|
public void setWidth(String width) {
|
||||||
|
mW = width;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = "height")
|
||||||
|
public void seHeight(String height) {
|
||||||
|
mH = height;
|
||||||
markUpdated();
|
markUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +135,6 @@ public class RNSVGImageShadowNode extends RNSVGPathShadowNode {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas, Paint paint, float opacity) {
|
public void draw(Canvas canvas, Paint paint, float opacity) {
|
||||||
canvas.saveLayer(0f, 0f, 0f, 0f, paint, Canvas.ALL_SAVE_FLAG);
|
canvas.saveLayer(0f, 0f, 0f, 0f, paint, Canvas.ALL_SAVE_FLAG);
|
||||||
Log.e("Count", "" + canvas.getSaveCount());
|
|
||||||
loadBitmap(getResourceDrawableId(getThemedContext(), null), canvas, paint);
|
loadBitmap(getResourceDrawableId(getThemedContext(), null), canvas, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,137 +0,0 @@
|
|||||||
import _ from 'lodash';
|
|
||||||
import ReactNativeViewAttributes from 'react-native/Libraries/Components/View/ReactNativeViewAttributes';
|
|
||||||
|
|
||||||
function arrayDiffer(a, b) {
|
|
||||||
if (_.isNil(a)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.length !== b.length) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function percentageDiffer(a, b) {
|
|
||||||
if (a === b) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (let key in a) {
|
|
||||||
if (a.hasOwnProperty(key)) {
|
|
||||||
if (key === 'type' && a.type !== b.type) {
|
|
||||||
return true;
|
|
||||||
} else if (a[key].percentage !== b[key].percentage || a[key].value !== b[key].value) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fontAndLinesDiffer(a, b) {
|
|
||||||
if (a === b) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.font !== b.font) {
|
|
||||||
if (a.font === null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (b.font === null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
a.font.fontFamily !== b.font.fontFamily ||
|
|
||||||
a.font.fontSize !== b.font.fontSize ||
|
|
||||||
a.font.fontWeight !== b.font.fontWeight ||
|
|
||||||
a.font.fontStyle !== b.font.fontStyle
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return arrayDiffer(a.lines, b.lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
const NodeAttributes = {
|
|
||||||
...ReactNativeViewAttributes.UIView,
|
|
||||||
transform: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
opacity: true,
|
|
||||||
clipPath: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
clipPathId: true,
|
|
||||||
clipRule: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const GroupAttributes = {
|
|
||||||
asClipPath: true,
|
|
||||||
...NodeAttributes
|
|
||||||
};
|
|
||||||
|
|
||||||
const RenderableAttributes = {
|
|
||||||
fill: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
fillRule: true,
|
|
||||||
stroke: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
strokeWidth: true,
|
|
||||||
strokeLinecap: true,
|
|
||||||
strokeLinejoin: true,
|
|
||||||
strokeDasharray: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
strokeDashoffset: true,
|
|
||||||
...NodeAttributes
|
|
||||||
};
|
|
||||||
|
|
||||||
const PathAttributes = {
|
|
||||||
d: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
...RenderableAttributes
|
|
||||||
};
|
|
||||||
|
|
||||||
const TextAttributes = {
|
|
||||||
alignment: true,
|
|
||||||
frame: {
|
|
||||||
diff: fontAndLinesDiffer
|
|
||||||
},
|
|
||||||
path: {
|
|
||||||
diff: arrayDiffer
|
|
||||||
},
|
|
||||||
...RenderableAttributes
|
|
||||||
};
|
|
||||||
|
|
||||||
const ShapeAttributes = {
|
|
||||||
shape: {
|
|
||||||
diff: percentageDiffer
|
|
||||||
},
|
|
||||||
...RenderableAttributes
|
|
||||||
};
|
|
||||||
|
|
||||||
const ImageAttributes = {
|
|
||||||
...NodeAttributes,
|
|
||||||
layout: {
|
|
||||||
diff: percentageDiffer
|
|
||||||
},
|
|
||||||
src: true
|
|
||||||
};
|
|
||||||
|
|
||||||
export {
|
|
||||||
GroupAttributes,
|
|
||||||
PathAttributes,
|
|
||||||
TextAttributes,
|
|
||||||
ShapeAttributes,
|
|
||||||
ImageAttributes
|
|
||||||
};
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user