mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-26 20:32:23 +00:00
Fix Images do not render if they are not in the cache
This commit is contained in:
@@ -15,7 +15,6 @@ import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Point;
|
||||
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ImageShadowNode extends RenderableShadowNode {
|
||||
if (Fresco.getImagePipeline().isInBitmapMemoryCache(request)) {
|
||||
tryRender(request, canvas, paint, opacity * mOpacity);
|
||||
} else {
|
||||
loadBitmap(request, canvas, paint);
|
||||
loadBitmap(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class ImageShadowNode extends RenderableShadowNode {
|
||||
return path;
|
||||
}
|
||||
|
||||
private void loadBitmap(ImageRequest request, final Canvas canvas, final Paint paint) {
|
||||
private void loadBitmap(ImageRequest request) {
|
||||
final DataSource<CloseableReference<CloseableImage>> dataSource
|
||||
= Fresco.getImagePipeline().fetchDecodedImage(request, getThemedContext());
|
||||
|
||||
@@ -135,7 +135,8 @@ public class ImageShadowNode extends RenderableShadowNode {
|
||||
@Override
|
||||
public void onNewResultImpl(Bitmap bitmap) {
|
||||
mLoading.set(false);
|
||||
getSvgShadowNode().drawOutput();
|
||||
SvgViewShadowNode shadowNode = getSvgShadowNode();
|
||||
shadowNode.markUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.horcrux.svg;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
public class SvgInstancesManager {
|
||||
private static final SparseArray<SvgViewShadowNode> mTagToShadowNode = new SparseArray<>();
|
||||
private static final SparseArray<SvgView> mTagToSvgView = new SparseArray<>();
|
||||
|
||||
static void registerShadowNode(SvgViewShadowNode shadowNode) {
|
||||
mTagToShadowNode.put(shadowNode.getReactTag(), shadowNode);
|
||||
}
|
||||
|
||||
static void registerSvgView(SvgView svg) {
|
||||
mTagToSvgView.put(svg.getId(), svg);
|
||||
}
|
||||
|
||||
static void unregisterInstance(int tag) {
|
||||
mTagToShadowNode.remove(tag);
|
||||
mTagToSvgView.remove(tag);
|
||||
}
|
||||
|
||||
static SvgView getSvgViewByTag(int tag) {
|
||||
return mTagToSvgView.get(tag);
|
||||
}
|
||||
|
||||
static SvgViewShadowNode getShadowNodeByTag(int tag) {
|
||||
return mTagToShadowNode.get(tag);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Point;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
@@ -31,7 +32,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Custom {@link View} implementation that draws an RNSVGSvg React view and its children.
|
||||
* Custom {@link View} implementation that draws an RNSVGSvg React view and its \childrn.
|
||||
*/
|
||||
public class SvgView extends View {
|
||||
public enum Events {
|
||||
@@ -63,6 +64,12 @@ public class SvgView extends View {
|
||||
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(int id) {
|
||||
super.setId(id);
|
||||
SvgInstancesManager.registerSvgView(this);
|
||||
}
|
||||
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
@@ -80,19 +87,16 @@ public class SvgView extends View {
|
||||
}
|
||||
|
||||
private SvgViewShadowNode getShadowNode() {
|
||||
return SvgViewShadowNode.getShadowNodeByTag(getId());
|
||||
return SvgInstancesManager.getShadowNodeByTag(getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
SvgViewShadowNode svg = getShadowNode();
|
||||
if (svg != null) {
|
||||
mTargetTag = getShadowNode().hitTest(new Point((int) ev.getX(), (int) ev.getY()));
|
||||
mTargetTag = getShadowNode().hitTest(new Point((int) ev.getX(), (int) ev.getY()));
|
||||
|
||||
if (mTargetTag != -1) {
|
||||
handleTouchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
if (mTargetTag != -1) {
|
||||
handleTouchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.dispatchTouchEvent(ev);
|
||||
@@ -188,4 +192,6 @@ public class SvgView extends View {
|
||||
event.putString("base64", getShadowNode().getBase64());
|
||||
mEventEmitter.receiveEvent(getId(), Events.EVENT_DATA_URL.toString(), event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ public class SvgViewManager extends BaseViewManager<SvgView, SvgViewShadowNode>
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDropViewInstance(SvgView view) {
|
||||
SvgInstancesManager.unregisterInstance(view.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SvgView createViewInstance(ThemedReactContext reactContext) {
|
||||
return new SvgView(reactContext);
|
||||
|
||||
@@ -37,14 +37,6 @@ import java.util.Map;
|
||||
* Shadow node for RNSVG virtual tree root - RNSVGSvgView
|
||||
*/
|
||||
public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
|
||||
private static final SparseArray<SvgViewShadowNode> mTagToShadowNode = new SparseArray<>();
|
||||
private @Nullable Surface mSurface;
|
||||
|
||||
public static SvgViewShadowNode getShadowNodeByTag(int tag) {
|
||||
return mTagToShadowNode.get(tag);
|
||||
}
|
||||
|
||||
private boolean mResponsible = false;
|
||||
|
||||
private final Map<String, VirtualNode> mDefinedClipPaths = new HashMap<>();
|
||||
@@ -70,7 +62,7 @@ public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
@Override
|
||||
public void setReactTag(int reactTag) {
|
||||
super.setReactTag(reactTag);
|
||||
mTagToShadowNode.put(getReactTag(), this);
|
||||
SvgInstancesManager.registerShadowNode(this);
|
||||
}
|
||||
|
||||
public Object drawOutput() {
|
||||
@@ -169,8 +161,4 @@ public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
public PropHelper.RNSVGBrush getDefinedBrush(String brushRef) {
|
||||
return mDefinedBrushes.get(brushRef);
|
||||
}
|
||||
|
||||
public void finalize() {
|
||||
mTagToShadowNode.remove(getReactTag());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user