mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-29 13:21:50 +00:00
fix: foreignObject clipping and transform
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user