fix: foreignObject clipping and transform

This commit is contained in:
Mikael Sand
2020-01-11 21:35:44 +02:00
parent f18c483555
commit 85e7943448
2 changed files with 36 additions and 1 deletions
@@ -10,6 +10,11 @@
package com.horcrux.svg;
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
@@ -27,6 +32,23 @@ class ForeignObjectView extends GroupView {
super(reactContext);
}
@Override
void draw(Canvas canvas, Paint paint, float opacity) {
float x = (float)relativeOnWidth(mX);
float y = (float)relativeOnHeight(mY);
float w = (float)relativeOnWidth(mW);
float h = (float)relativeOnHeight(mH);
canvas.translate(x, y);
canvas.clipRect(0, 0, w, h);
super.draw(canvas, paint, opacity);
}
@Override
public void onDescendantInvalidated(@NonNull View child, @NonNull View target) {
super.onDescendantInvalidated(child, target);
invalidate();
}
@ReactProp(name = "x")
public void setX(Dynamic x) {
mX = SVGLength.from(x);
+14 -1
View File
@@ -18,7 +18,20 @@
- (void)parseReference
{
self.dirty = false;
[self.svgView defineForeignObject:self foreignObjectName:self.name];
}
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
[self clip:context];
CGContextTranslateCTM(context, [self relativeOnWidth:self.x], [self relativeOnHeight:self.y]);
CGRect clip = CGRectMake(
0,
0,
[self relativeOnWidth:self.foreignObjectwidth],
[self relativeOnHeight:self.foreignObjectheight]
);
CGContextClipToRect(context, clip);
[super renderLayerTo:context rect:rect];
}
- (void)setX:(RNSVGLength *)x