mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
fix: transform scale on android (#2452)
# Summary Undo these changes https://github.com/software-mansion/react-native-svg/pull/2403/files#diff-7f8adeb6e7faded1a7ef711b4fa9d2b12d29ff386217e838c4551866afdd8bef that introduced a bug described here https://github.com/software-mansion/react-native-svg/issues/2442#issuecomment-2354170651
This commit is contained in:
@@ -64,8 +64,6 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
public SvgView(ReactContext reactContext) {
|
||||
super(reactContext);
|
||||
mScale = DisplayMetricsHolder.getScreenDisplayMetrics().density;
|
||||
mScaleX = 1;
|
||||
mScaleY = 1;
|
||||
mPaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
|
||||
mPaint.setTypeface(Typeface.DEFAULT);
|
||||
|
||||
@@ -128,7 +126,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (getParent() instanceof VirtualView || mScaleX <= 0 || mScaleY <= 0) {
|
||||
if (getParent() instanceof VirtualView) {
|
||||
return;
|
||||
}
|
||||
super.onDraw(canvas);
|
||||
@@ -137,17 +135,13 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
}
|
||||
if (mBitmap != null) {
|
||||
mPaint.reset();
|
||||
mPaint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
|
||||
mPaint.setFlags(
|
||||
Paint.ANTI_ALIAS_FLAG
|
||||
| Paint.DEV_KERN_TEXT_FLAG
|
||||
| Paint.SUBPIXEL_TEXT_FLAG
|
||||
| Paint.FILTER_BITMAP_FLAG);
|
||||
mPaint.setTypeface(Typeface.DEFAULT);
|
||||
if (mScaleX != 1 || mScaleY != 1) {
|
||||
canvas.drawBitmap(
|
||||
mBitmap,
|
||||
-(float) (mBitmap.getWidth() - getWidth()) / 2,
|
||||
-(float) (mBitmap.getHeight() - getHeight()) / 2,
|
||||
mPaint);
|
||||
} else {
|
||||
canvas.drawBitmap(mBitmap, 0, 0, mPaint);
|
||||
}
|
||||
canvas.drawBitmap(mBitmap, 0, 0, mPaint);
|
||||
if (toDataUrlTask != null) {
|
||||
toDataUrlTask.run();
|
||||
toDataUrlTask = null;
|
||||
@@ -182,8 +176,6 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
private final Map<String, Brush> mDefinedBrushes = new HashMap<>();
|
||||
private Canvas mCanvas;
|
||||
private final float mScale;
|
||||
private float mScaleX;
|
||||
private float mScaleY;
|
||||
private final Paint mPaint = new Paint();
|
||||
|
||||
private float mMinX;
|
||||
@@ -284,9 +276,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
if (invalid) {
|
||||
return null;
|
||||
}
|
||||
Bitmap bitmap =
|
||||
Bitmap.createBitmap(
|
||||
(int) (width * mScaleX), (int) (height * mScaleY), Bitmap.Config.ARGB_8888);
|
||||
Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
|
||||
mCurrentBitmap = bitmap;
|
||||
drawChildren(new Canvas(bitmap));
|
||||
return bitmap;
|
||||
@@ -401,11 +391,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
}
|
||||
|
||||
float[] transformed = {touchX, touchY};
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
Matrix invViewBoxMatrix = new Matrix(mInvViewBoxMatrix);
|
||||
invViewBoxMatrix.preTranslate((width * mScaleX - width) / 2, (height * mScaleY - height) / 2);
|
||||
invViewBoxMatrix.mapPoints(transformed);
|
||||
mInvViewBoxMatrix.mapPoints(transformed);
|
||||
|
||||
int count = getChildCount();
|
||||
int viewTag = -1;
|
||||
@@ -475,12 +461,4 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
public Bitmap getCurrentBitmap() {
|
||||
return mCurrentBitmap;
|
||||
}
|
||||
|
||||
public void setTransformProperty() {
|
||||
mScaleX = super.getScaleX();
|
||||
mScaleY = super.getScaleY();
|
||||
super.setScaleX(1);
|
||||
super.setScaleY(1);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ package com.horcrux.svg;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.util.SparseArray;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
@@ -392,13 +390,4 @@ class SvgViewManager extends ReactViewManager
|
||||
public void setBorderStartStartRadius(SvgView view, double value) {
|
||||
super.setBorderRadius(view, 12, (float) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransformProperty(
|
||||
@NonNull ReactViewGroup view,
|
||||
@androidx.annotation.Nullable ReadableArray transforms,
|
||||
@androidx.annotation.Nullable ReadableArray transformOrigin) {
|
||||
super.setTransformProperty(view, transforms, transformOrigin);
|
||||
((SvgView) view).setTransformProperty();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user