mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 16:04:38 +00:00
revert 4.3.2
This commit is contained in:
@@ -9,11 +9,12 @@
|
||||
|
||||
package com.horcrux.svg;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Point;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.TextureView;
|
||||
|
||||
import com.facebook.react.ReactRootView;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
@@ -26,10 +27,12 @@ import com.facebook.react.uimanager.events.TouchEventCoalescingKeyHelper;
|
||||
import com.facebook.react.uimanager.events.TouchEventType;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Custom {@link View} implementation that draws an RNSVGSvg React view and its \children.
|
||||
*/
|
||||
public class RNSVGSvgView extends TextureView {
|
||||
public class RNSVGSvgView extends View {
|
||||
public enum Events {
|
||||
EVENT_DATA_URL("onDataURL");
|
||||
|
||||
@@ -45,6 +48,7 @@ public class RNSVGSvgView extends TextureView {
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable Bitmap mBitmap;
|
||||
private RCTEventEmitter mEventEmitter;
|
||||
private EventDispatcher mEventDispatcher;
|
||||
private int mTargetTag;
|
||||
@@ -54,7 +58,6 @@ public class RNSVGSvgView extends TextureView {
|
||||
|
||||
public RNSVGSvgView(ReactContext reactContext) {
|
||||
super(reactContext);
|
||||
setOpaque(false);
|
||||
mEventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
|
||||
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
}
|
||||
@@ -63,6 +66,22 @@ public class RNSVGSvgView extends TextureView {
|
||||
return RNSVGSvgViewShadowNode.getShadowNodeByTag(getId());
|
||||
}
|
||||
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
mBitmap = bitmap;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mBitmap != null) {
|
||||
canvas.drawBitmap(mBitmap, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
mTargetTag = getShadowNode().hitTest(new Point((int) ev.getX(), (int) ev.getY()));
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
package com.horcrux.svg;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.BaseViewManager;
|
||||
@@ -50,7 +52,7 @@ public class RNSVGSvgViewManager extends BaseViewManager<RNSVGSvgView, RNSVGSvgV
|
||||
|
||||
@Override
|
||||
public void updateExtraData(RNSVGSvgView root, Object extraData) {
|
||||
root.setSurfaceTextureListener((RNSVGSvgViewShadowNode) extraData);
|
||||
root.setBitmap((Bitmap) extraData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,16 +15,10 @@ import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.util.Base64;
|
||||
import android.util.SparseArray;
|
||||
import android.view.TextureView;
|
||||
import android.graphics.Color;
|
||||
import android.view.Surface;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.SurfaceTexture;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
import com.facebook.react.uimanager.UIViewOperationQueue;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -35,7 +29,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Shadow node for RNSVG virtual tree root - RNSVGSvgView
|
||||
*/
|
||||
public class RNSVGSvgViewShadowNode extends LayoutShadowNode implements TextureView.SurfaceTextureListener {
|
||||
public class RNSVGSvgViewShadowNode extends LayoutShadowNode {
|
||||
|
||||
private static final SparseArray<RNSVGSvgViewShadowNode> mTagToShadowNode = new SparseArray<>();
|
||||
|
||||
@@ -43,7 +37,6 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode implements TextureV
|
||||
return mTagToShadowNode.get(tag);
|
||||
}
|
||||
|
||||
private @Nullable Surface mSurface;
|
||||
private boolean mResponsible = false;
|
||||
private static final Map<String, RNSVGVirtualNode> mDefinedClipPaths = new HashMap<>();
|
||||
private static final Map<String, RNSVGVirtualNode> mDefinedTemplates = new HashMap<>();
|
||||
@@ -62,27 +55,25 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode implements TextureV
|
||||
@Override
|
||||
public void onCollectExtraUpdates(UIViewOperationQueue uiUpdater) {
|
||||
super.onCollectExtraUpdates(uiUpdater);
|
||||
drawOutput();
|
||||
uiUpdater.enqueueUpdateExtraData(getReactTag(), this);
|
||||
uiUpdater.enqueueUpdateExtraData(getReactTag(), drawOutput());
|
||||
|
||||
}
|
||||
|
||||
public void drawOutput() {
|
||||
if (mSurface == null || !mSurface.isValid()) {
|
||||
markChildrenUpdatesSeen(this);
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void setReactTag(int reactTag) {
|
||||
super.setReactTag(reactTag);
|
||||
mTagToShadowNode.put(getReactTag(), this);
|
||||
}
|
||||
|
||||
try {
|
||||
Canvas canvas = mSurface.lockCanvas(null);
|
||||
drawChildren(canvas);
|
||||
public Object drawOutput() {
|
||||
Bitmap bitmap = Bitmap.createBitmap(
|
||||
(int) getLayoutWidth(),
|
||||
(int) getLayoutHeight(),
|
||||
Bitmap.Config.ARGB_8888);
|
||||
|
||||
if (mSurface != null) {
|
||||
mSurface.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||
FLog.e(ReactConstants.TAG, e.getClass().getSimpleName() + " in Svg.unlockCanvasAndPost");
|
||||
}
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawChildren(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private void drawChildren(Canvas canvas) {
|
||||
@@ -106,14 +97,6 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode implements TextureV
|
||||
}
|
||||
}
|
||||
|
||||
private void markChildrenUpdatesSeen(ReactShadowNode shadowNode) {
|
||||
for (int i = 0; i < shadowNode.getChildCount(); i++) {
|
||||
ReactShadowNode child = shadowNode.getChildAt(i);
|
||||
child.markUpdateSeen();
|
||||
markChildrenUpdatesSeen(child);
|
||||
}
|
||||
}
|
||||
|
||||
public String getBase64() {
|
||||
Bitmap bitmap = Bitmap.createBitmap(
|
||||
(int) getLayoutWidth(),
|
||||
@@ -128,27 +111,6 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode implements TextureV
|
||||
return Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
||||
mSurface = new Surface(surface);
|
||||
mTagToShadowNode.put(getReactTag(), this);
|
||||
drawOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
||||
mTagToShadowNode.remove(getReactTag());
|
||||
surface.release();
|
||||
mSurface = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
|
||||
|
||||
public void enableTouchEvents() {
|
||||
if (!mResponsible) {
|
||||
mResponsible = true;
|
||||
@@ -199,4 +161,8 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode implements TextureV
|
||||
public PropHelper.RNSVGBrush getDefinedBrush(String brushRef) {
|
||||
return mDefinedBrushes.get(brushRef);
|
||||
}
|
||||
|
||||
public void finalize() {
|
||||
mTagToShadowNode.remove(getReactTag());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user