Skip to content

Commit

Permalink
revert 4.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
magicismight committed Nov 14, 2016
1 parent 4d3f168 commit f566381
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 59 deletions.
25 changes: 22 additions & 3 deletions android/src/main/java/com/horcrux/svg/RNSVGSvgView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,10 +27,12 @@
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");

Expand All @@ -45,6 +48,7 @@ public String toString() {
}
}

private @Nullable Bitmap mBitmap;
private RCTEventEmitter mEventEmitter;
private EventDispatcher mEventDispatcher;
private int mTargetTag;
Expand All @@ -54,7 +58,6 @@ public String toString() {

public RNSVGSvgView(ReactContext reactContext) {
super(reactContext);
setOpaque(false);
mEventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
}
Expand All @@ -63,6 +66,22 @@ private RNSVGSvgViewShadowNode getShadowNode() {
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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +52,7 @@ protected RNSVGSvgView createViewInstance(ThemedReactContext reactContext) {

@Override
public void updateExtraData(RNSVGSvgView root, Object extraData) {
root.setSurfaceTextureListener((RNSVGSvgViewShadowNode) extraData);
root.setBitmap((Bitmap) extraData);
}

@Override
Expand Down
74 changes: 20 additions & 54 deletions android/src/main/java/com/horcrux/svg/RNSVGSvgViewShadowNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
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;
Expand All @@ -35,15 +29,14 @@
/**
* 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<>();

public static RNSVGSvgViewShadowNode getShadowNodeByTag(int tag) {
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<>();
Expand All @@ -62,27 +55,25 @@ public boolean isVirtualAnchor() {
@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;
}
}

try {
Canvas canvas = mSurface.lockCanvas(null);
drawChildren(canvas);
@Override
public void setReactTag(int reactTag) {
super.setReactTag(reactTag);
mTagToShadowNode.put(getReactTag(), this);
}

if (mSurface != null) {
mSurface.unlockCanvasAndPost(canvas);
}
public Object drawOutput() {
Bitmap bitmap = Bitmap.createBitmap(
(int) getLayoutWidth(),
(int) getLayoutHeight(),
Bitmap.Config.ARGB_8888);

} 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) {
Expand All @@ -106,14 +97,6 @@ private void drawChildren(Canvas canvas) {
}
}

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(),
Expand All @@ -128,27 +111,6 @@ public String getBase64() {
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;
Expand Down Expand Up @@ -199,4 +161,8 @@ public void defineBrush(PropHelper.RNSVGBrush brush, String brushRef) {
public PropHelper.RNSVGBrush getDefinedBrush(String brushRef) {
return mDefinedBrushes.get(brushRef);
}

public void finalize() {
mTagToShadowNode.remove(getReactTag());
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.3.2",
"version": "4.3.3",
"name": "react-native-svg",
"description": "SVG library for react-native",
"repository": {
Expand Down

0 comments on commit f566381

Please sign in to comment.