restore clip after clip

This commit is contained in:
Horcrux
2016-04-21 22:09:22 +08:00
parent 26912bbe15
commit a48d21de6e
5 changed files with 18 additions and 7 deletions

View File

@@ -36,6 +36,12 @@ class ClipPathAttr extends Component{
/>
</RadialGradient>
</Defs>
<Circle
cx="50"
cy="50"
r="30"
fill="red"
/>
<Rect
x="0"
y="0"

View File

@@ -30,9 +30,7 @@ public class RNSVGGroupShadowNode extends RNSVGVirtualNode {
if (opacity > MIN_OPACITY_FOR_DRAW) {
saveAndSetupCanvas(canvas);
if (mClipPath != null) {
canvas.clipPath(mClipPath, Region.Op.REPLACE);
}
clip(canvas, paint);
for (int i = 0; i < getChildCount(); i++) {
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);

View File

@@ -130,10 +130,7 @@ public class RNSVGPathShadowNode extends RNSVGVirtualNode {
"Paths should have a valid path (d) prop");
}
if (mClipPath != null) {
canvas.clipPath(mClipPath, Region.Op.REPLACE);
}
clip(canvas, paint);
if (setupFillPaint(paint, opacity)) {
canvas.drawPath(mPath, paint);

View File

@@ -71,6 +71,8 @@ public class RNSVGTextShadowNode extends RNSVGPathShadowNode {
// only set up the canvas if we have something to draw
saveAndSetupCanvas(canvas);
clip(canvas, paint);
String[] lines = new String[linesProp.size()];
for (int i = 0; i < lines.length; i++) {
lines[i] = linesProp.getString(i);

View File

@@ -17,6 +17,7 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Region;
import android.util.Log;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
@@ -206,4 +207,11 @@ public abstract class RNSVGVirtualNode extends ReactShadowNode {
}
return path;
}
protected void clip(Canvas canvas, Paint paint) {
if (mClipPath != null) {
canvas.clipPath(mClipPath, Region.Op.REPLACE);
canvas.saveLayer(0f, 0f, 0f, 0f, paint, Canvas.CLIP_SAVE_FLAG);
}
}
}