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> </RadialGradient>
</Defs> </Defs>
<Circle
cx="50"
cy="50"
r="30"
fill="red"
/>
<Rect <Rect
x="0" x="0"
y="0" y="0"

View File

@@ -30,9 +30,7 @@ public class RNSVGGroupShadowNode extends RNSVGVirtualNode {
if (opacity > MIN_OPACITY_FOR_DRAW) { if (opacity > MIN_OPACITY_FOR_DRAW) {
saveAndSetupCanvas(canvas); saveAndSetupCanvas(canvas);
if (mClipPath != null) { clip(canvas, paint);
canvas.clipPath(mClipPath, Region.Op.REPLACE);
}
for (int i = 0; i < getChildCount(); i++) { for (int i = 0; i < getChildCount(); i++) {
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(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"); "Paths should have a valid path (d) prop");
} }
if (mClipPath != null) { clip(canvas, paint);
canvas.clipPath(mClipPath, Region.Op.REPLACE);
}
if (setupFillPaint(paint, opacity)) { if (setupFillPaint(paint, opacity)) {
canvas.drawPath(mPath, paint); 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 // only set up the canvas if we have something to draw
saveAndSetupCanvas(canvas); saveAndSetupCanvas(canvas);
clip(canvas, paint);
String[] lines = new String[linesProp.size()]; String[] lines = new String[linesProp.size()];
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
lines[i] = linesProp.getString(i); lines[i] = linesProp.getString(i);

View File

@@ -17,6 +17,7 @@ import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.Region;
import android.util.Log; import android.util.Log;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
@@ -206,4 +207,11 @@ public abstract class RNSVGVirtualNode extends ReactShadowNode {
} }
return path; 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);
}
}
} }