mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 07:25:53 +00:00
[iOS] Fix transform in mask handling
cleanup mask implementation
This commit is contained in:
@@ -10,12 +10,9 @@
|
||||
package com.horcrux.svg;
|
||||
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.RectF;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
|
||||
@@ -33,13 +30,6 @@ class MaskShadowNode extends GroupShadowNode {
|
||||
Brush.BrushUnits mMaskUnits;
|
||||
Brush.BrushUnits mMaskContentUnits;
|
||||
|
||||
private float mMinX;
|
||||
private float mMinY;
|
||||
private float mVbWidth;
|
||||
private float mVbHeight;
|
||||
String mAlign;
|
||||
int mMeetOrSlice;
|
||||
|
||||
private static final float[] sRawMatrix = new float[]{
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
@@ -116,46 +106,6 @@ class MaskShadowNode extends GroupShadowNode {
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@ReactProp(name = "minX")
|
||||
public void setMinX(float minX) {
|
||||
mMinX = minX;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@ReactProp(name = "minY")
|
||||
public void setMinY(float minY) {
|
||||
mMinY = minY;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbWidth")
|
||||
public void setVbWidth(float vbWidth) {
|
||||
mVbWidth = vbWidth;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbHeight")
|
||||
public void setVbHeight(float vbHeight) {
|
||||
mVbHeight = vbHeight;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@ReactProp(name = "align")
|
||||
public void setAlign(String align) {
|
||||
mAlign = align;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@ReactProp(name = "meetOrSlice")
|
||||
public void setMeetOrSlice(int meetOrSlice) {
|
||||
mMeetOrSlice = meetOrSlice;
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
RectF getViewBox() {
|
||||
return new RectF(mMinX * mScale, mMinY * mScale, (mMinX + mVbWidth) * mScale, (mMinY + mVbHeight) * mScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveDefinition() {
|
||||
if (mName != null) {
|
||||
|
||||
@@ -498,36 +498,6 @@ class RenderableViewManager<T extends VirtualNode> extends ViewGroupManager<Rend
|
||||
public void setMaskTransform(RenderableView<MaskShadowNode> node, @Nullable ReadableArray matrixArray) {
|
||||
node.shadowNode.setMaskTransform(matrixArray);
|
||||
}
|
||||
|
||||
@ReactProp(name = "minX")
|
||||
public void setMinX(RenderableView<MaskShadowNode> node, float minX) {
|
||||
node.shadowNode.setMinX(minX);
|
||||
}
|
||||
|
||||
@ReactProp(name = "minY")
|
||||
public void setMinY(RenderableView<MaskShadowNode> node, float minY) {
|
||||
node.shadowNode.setMinY(minY);
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbWidth")
|
||||
public void setVbWidth(RenderableView<MaskShadowNode> node, float vbWidth) {
|
||||
node.shadowNode.setVbWidth(vbWidth);
|
||||
}
|
||||
|
||||
@ReactProp(name = "vbHeight")
|
||||
public void setVbHeight(RenderableView<MaskShadowNode> node, float vbHeight) {
|
||||
node.shadowNode.setVbHeight(vbHeight);
|
||||
}
|
||||
|
||||
@ReactProp(name = "align")
|
||||
public void setAlign(RenderableView<MaskShadowNode> node, String align) {
|
||||
node.shadowNode.setAlign(align);
|
||||
}
|
||||
|
||||
@ReactProp(name = "meetOrSlice")
|
||||
public void setMeetOrSlice(RenderableView<MaskShadowNode> node, int meetOrSlice) {
|
||||
node.shadowNode.setMeetOrSlice(meetOrSlice);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import { numberProp } from '../lib/props';
|
||||
import PATTERN_UNITS from '../lib/PATTERN_UNITS';
|
||||
import { MaskAttributes } from '../lib/attributes';
|
||||
import extractTransform from '../lib/extract/extractTransform';
|
||||
import extractViewBox from "react-native-svg/lib/extract/extractViewBox";
|
||||
|
||||
export default class extends Component {
|
||||
static displayName = 'Mask';
|
||||
@@ -21,8 +20,6 @@ export default class extends Component {
|
||||
'userSpaceOnUse',
|
||||
'objectBoundingBox',
|
||||
]),
|
||||
viewBox: PropTypes.string,
|
||||
preserveAspectRatio: PropTypes.string
|
||||
};
|
||||
|
||||
render() {
|
||||
@@ -62,7 +59,6 @@ export default class extends Component {
|
||||
maskTransform={extractedTransform}
|
||||
maskUnits={maskUnits !== undefined ? PATTERN_UNITS[maskUnits] : 0}
|
||||
maskContentUnits={maskContentUnits !== undefined ? PATTERN_UNITS[maskContentUnits] : 1}
|
||||
{...extractViewBox({ viewBox, preserveAspectRatio })}
|
||||
>
|
||||
{children}
|
||||
</RNSVGMask>
|
||||
|
||||
@@ -11,11 +11,4 @@
|
||||
@property (nonatomic, assign) RNSVGUnits maskContentUnits;
|
||||
@property (nonatomic, assign) CGAffineTransform maskTransform;
|
||||
|
||||
@property (nonatomic, assign) CGFloat minX;
|
||||
@property (nonatomic, assign) CGFloat minY;
|
||||
@property (nonatomic, assign) CGFloat vbWidth;
|
||||
@property (nonatomic, assign) CGFloat vbHeight;
|
||||
@property (nonatomic, strong) NSString *align;
|
||||
@property (nonatomic, assign) RNSVGVBMOS meetOrSlice;
|
||||
|
||||
@end
|
||||
|
||||
@@ -185,6 +185,7 @@ UInt32 saturate(double value) {
|
||||
NSUInteger iheight = height;
|
||||
NSUInteger iwidth = width;
|
||||
NSUInteger npixels = iheight * iwidth;
|
||||
CGRect drawBounds = CGRectMake(0, 0, width, height);
|
||||
|
||||
// Allocate pixel buffer and bitmap context for mask
|
||||
NSUInteger bytesPerPixel = 4;
|
||||
@@ -194,7 +195,7 @@ UInt32 saturate(double value) {
|
||||
UInt32 * pixels = (UInt32 *) calloc(npixels, sizeof(UInt32));
|
||||
CGContextRef bcontext = CGBitmapContextCreate(pixels, iwidth, iheight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
|
||||
|
||||
// Clip to mask bounds, adjust to viewbox and render the mask
|
||||
// Clip to mask bounds and render the mask
|
||||
CGFloat x = [RNSVGPercentageConverter stringToFloat:[_maskNode x]
|
||||
relative:width
|
||||
offset:0];
|
||||
@@ -209,13 +210,6 @@ UInt32 saturate(double value) {
|
||||
offset:0];
|
||||
CGRect maskBounds = CGRectMake(x, y, w, h);
|
||||
CGContextClipToRect(bcontext, maskBounds);
|
||||
|
||||
CGRect drawBounds = CGRectMake(0, 0, width, height);
|
||||
CGAffineTransform _viewBoxTransform = [RNSVGViewBox getTransform:rect
|
||||
eRect:drawBounds
|
||||
align:_maskNode.align
|
||||
meetOrSlice:_maskNode.meetOrSlice];
|
||||
CGContextConcatCTM(bcontext, _viewBoxTransform);
|
||||
[_maskNode renderLayerTo:bcontext rect:rect];
|
||||
|
||||
// Apply luminanceToAlpha filter primitive
|
||||
|
||||
@@ -26,11 +26,4 @@ RCT_EXPORT_VIEW_PROPERTY(maskUnits, RNSVGUnits)
|
||||
RCT_EXPORT_VIEW_PROPERTY(maskContentUnits, RNSVGUnits)
|
||||
RCT_EXPORT_VIEW_PROPERTY(maskTransform, CGAffineTransform)
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(minX, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(minY, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(vbWidth, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(vbHeight, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(align, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS)
|
||||
|
||||
@end
|
||||
|
||||
@@ -177,7 +177,6 @@ const PatternAttributes = {
|
||||
};
|
||||
|
||||
const MaskAttributes = {
|
||||
...ViewBoxAttributes,
|
||||
name: true,
|
||||
x: true,
|
||||
y: true,
|
||||
|
||||
Reference in New Issue
Block a user