mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
chore: add CI for JS, iOS and Android formatting (#1782)
Added CI workflow and local pre-commit hook for formatting and linting the newly added JS, iOS and Android code.
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
|
||||
#ifdef RN_FABRIC_ENABLED
|
||||
#import <react/renderer/components/rnsvg/ComponentDescriptors.h>
|
||||
#import "RCTFabricComponentsPlugins.h"
|
||||
#import "RCTConversions.h"
|
||||
#import <react/renderer/components/view/conversions.h>
|
||||
#import "RCTConversions.h"
|
||||
#import "RCTFabricComponentsPlugins.h"
|
||||
#import "RNSVGFabricConversions.h"
|
||||
#endif // RN_FABRIC_ENABLED
|
||||
|
||||
@@ -41,177 +41,177 @@ using namespace facebook::react;
|
||||
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &newProps = *std::static_pointer_cast<const RNSVGForeignObjectProps>(props);
|
||||
const auto &newProps = *std::static_pointer_cast<const RNSVGForeignObjectProps>(props);
|
||||
|
||||
self.x = RCTNSStringFromStringNilIfEmpty(newProps.x) ? [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)] : nil;
|
||||
self.y = RCTNSStringFromStringNilIfEmpty(newProps.y) ? [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)] : nil;
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.foreignObjectheight)) {
|
||||
self.foreignObjectheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.foreignObjectheight)];
|
||||
}
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.foreignObjectwidth)) {
|
||||
self.foreignObjectwidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.foreignObjectwidth)];
|
||||
}
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.height)) {
|
||||
self.foreignObjectheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.height)];
|
||||
}
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.width)) {
|
||||
self.foreignObjectwidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.width)];
|
||||
}
|
||||
self.x = RCTNSStringFromStringNilIfEmpty(newProps.x)
|
||||
? [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]
|
||||
: nil;
|
||||
self.y = RCTNSStringFromStringNilIfEmpty(newProps.y)
|
||||
? [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]
|
||||
: nil;
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.foreignObjectheight)) {
|
||||
self.foreignObjectheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.foreignObjectheight)];
|
||||
}
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.foreignObjectwidth)) {
|
||||
self.foreignObjectwidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.foreignObjectwidth)];
|
||||
}
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.height)) {
|
||||
self.foreignObjectheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.height)];
|
||||
}
|
||||
if (RCTNSStringFromStringNilIfEmpty(newProps.width)) {
|
||||
self.foreignObjectwidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.width)];
|
||||
}
|
||||
|
||||
setCommonGroupProps(newProps, self);
|
||||
setCommonGroupProps(newProps, self);
|
||||
}
|
||||
|
||||
- (void)prepareForRecycle
|
||||
{
|
||||
[super prepareForRecycle];
|
||||
_x = nil;
|
||||
_y = nil;
|
||||
_foreignObjectheight = nil;
|
||||
_foreignObjectwidth = nil;
|
||||
[super prepareForRecycle];
|
||||
_x = nil;
|
||||
_y = nil;
|
||||
_foreignObjectheight = nil;
|
||||
_foreignObjectwidth = nil;
|
||||
}
|
||||
#endif // RN_FABRIC_ENABLED
|
||||
- (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||
{
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)parseReference
|
||||
{
|
||||
self.dirty = false;
|
||||
self.dirty = false;
|
||||
}
|
||||
|
||||
- (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];
|
||||
[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)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
|
||||
{
|
||||
[self pushGlyphContext];
|
||||
[self pushGlyphContext];
|
||||
|
||||
__block CGRect bounds = CGRectNull;
|
||||
|
||||
[self traverseSubviews:^(RNSVGView *node) {
|
||||
if ([node isKindOfClass:[RNSVGMask class]] || [node isKindOfClass:[RNSVGClipPath class]]) {
|
||||
// no-op
|
||||
} else if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||
RNSVGNode* svgNode = (RNSVGNode*)node;
|
||||
if (svgNode.display && [@"none" isEqualToString:svgNode.display]) {
|
||||
return YES;
|
||||
}
|
||||
if (svgNode.responsible && !self.svgView.responsible) {
|
||||
self.svgView.responsible = YES;
|
||||
}
|
||||
|
||||
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
||||
[(RNSVGRenderable*)node mergeProperties:self];
|
||||
}
|
||||
|
||||
[svgNode renderTo:context rect:rect];
|
||||
|
||||
CGRect nodeRect = svgNode.clientRect;
|
||||
if (!CGRectIsEmpty(nodeRect)) {
|
||||
bounds = CGRectUnion(bounds, nodeRect);
|
||||
}
|
||||
|
||||
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
||||
[(RNSVGRenderable*)node resetProperties];
|
||||
}
|
||||
} else if ([node isKindOfClass:[RNSVGSvgView class]]) {
|
||||
RNSVGSvgView* svgView = (RNSVGSvgView*)node;
|
||||
CGFloat width = [self relativeOnWidth:svgView.bbWidth];
|
||||
CGFloat height = [self relativeOnHeight:svgView.bbHeight];
|
||||
CGRect rect = CGRectMake(0, 0, width, height);
|
||||
CGContextClipToRect(context, rect);
|
||||
[svgView drawToContext:context withRect:rect];
|
||||
} else {
|
||||
node.hidden = false;
|
||||
[node.layer renderInContext:context];
|
||||
node.hidden = true;
|
||||
}
|
||||
__block CGRect bounds = CGRectNull;
|
||||
|
||||
[self traverseSubviews:^(RNSVGView *node) {
|
||||
if ([node isKindOfClass:[RNSVGMask class]] || [node isKindOfClass:[RNSVGClipPath class]]) {
|
||||
// no-op
|
||||
} else if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||
RNSVGNode *svgNode = (RNSVGNode *)node;
|
||||
if (svgNode.display && [@"none" isEqualToString:svgNode.display]) {
|
||||
return YES;
|
||||
}];
|
||||
CGPathRef path = [self getPath:context];
|
||||
[self setHitArea:path];
|
||||
if (!CGRectEqualToRect(bounds, CGRectNull)) {
|
||||
self.clientRect = bounds;
|
||||
self.fillBounds = CGPathGetBoundingBox(path);
|
||||
self.strokeBounds = CGPathGetBoundingBox(self.strokePath);
|
||||
self.pathBounds = CGRectUnion(self.fillBounds, self.strokeBounds);
|
||||
}
|
||||
if (svgNode.responsible && !self.svgView.responsible) {
|
||||
self.svgView.responsible = YES;
|
||||
}
|
||||
|
||||
CGAffineTransform current = CGContextGetCTM(context);
|
||||
CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM);
|
||||
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
||||
[(RNSVGRenderable *)node mergeProperties:self];
|
||||
}
|
||||
|
||||
self.ctm = svgToClientTransform;
|
||||
self.screenCTM = current;
|
||||
[svgNode renderTo:context rect:rect];
|
||||
|
||||
CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
|
||||
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
|
||||
CGPoint center = CGPointApplyAffineTransform(mid, transform);
|
||||
CGRect nodeRect = svgNode.clientRect;
|
||||
if (!CGRectIsEmpty(nodeRect)) {
|
||||
bounds = CGRectUnion(bounds, nodeRect);
|
||||
}
|
||||
|
||||
self.bounds = bounds;
|
||||
if (!isnan(center.x) && !isnan(center.y)) {
|
||||
self.center = center;
|
||||
}
|
||||
self.frame = bounds;
|
||||
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
||||
[(RNSVGRenderable *)node resetProperties];
|
||||
}
|
||||
} else if ([node isKindOfClass:[RNSVGSvgView class]]) {
|
||||
RNSVGSvgView *svgView = (RNSVGSvgView *)node;
|
||||
CGFloat width = [self relativeOnWidth:svgView.bbWidth];
|
||||
CGFloat height = [self relativeOnHeight:svgView.bbHeight];
|
||||
CGRect rect = CGRectMake(0, 0, width, height);
|
||||
CGContextClipToRect(context, rect);
|
||||
[svgView drawToContext:context withRect:rect];
|
||||
} else {
|
||||
node.hidden = false;
|
||||
[node.layer renderInContext:context];
|
||||
node.hidden = true;
|
||||
}
|
||||
|
||||
[self popGlyphContext];
|
||||
return YES;
|
||||
}];
|
||||
CGPathRef path = [self getPath:context];
|
||||
[self setHitArea:path];
|
||||
if (!CGRectEqualToRect(bounds, CGRectNull)) {
|
||||
self.clientRect = bounds;
|
||||
self.fillBounds = CGPathGetBoundingBox(path);
|
||||
self.strokeBounds = CGPathGetBoundingBox(self.strokePath);
|
||||
self.pathBounds = CGRectUnion(self.fillBounds, self.strokeBounds);
|
||||
|
||||
CGAffineTransform current = CGContextGetCTM(context);
|
||||
CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM);
|
||||
|
||||
self.ctm = svgToClientTransform;
|
||||
self.screenCTM = current;
|
||||
|
||||
CGAffineTransform transform = CGAffineTransformConcat(self.matrix, self.transforms);
|
||||
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
|
||||
CGPoint center = CGPointApplyAffineTransform(mid, transform);
|
||||
|
||||
self.bounds = bounds;
|
||||
if (!isnan(center.x) && !isnan(center.y)) {
|
||||
self.center = center;
|
||||
}
|
||||
self.frame = bounds;
|
||||
}
|
||||
|
||||
[self popGlyphContext];
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
[self invalidate];
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (void)setX:(RNSVGLength *)x
|
||||
{
|
||||
if ([x isEqualTo:_x]) {
|
||||
return;
|
||||
}
|
||||
if ([x isEqualTo:_x]) {
|
||||
return;
|
||||
}
|
||||
|
||||
_x = x;
|
||||
[self invalidate];
|
||||
_x = x;
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (void)setY:(RNSVGLength *)y
|
||||
{
|
||||
if ([y isEqualTo:_y]) {
|
||||
return;
|
||||
}
|
||||
if ([y isEqualTo:_y]) {
|
||||
return;
|
||||
}
|
||||
|
||||
_y = y;
|
||||
[self invalidate];
|
||||
_y = y;
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (void)setForeignObjectwidth:(RNSVGLength *)foreignObjectwidth
|
||||
{
|
||||
if ([foreignObjectwidth isEqualTo:_foreignObjectwidth]) {
|
||||
return;
|
||||
}
|
||||
if ([foreignObjectwidth isEqualTo:_foreignObjectwidth]) {
|
||||
return;
|
||||
}
|
||||
|
||||
_foreignObjectwidth = foreignObjectwidth;
|
||||
[self invalidate];
|
||||
_foreignObjectwidth = foreignObjectwidth;
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (void)setForeignObjectheight:(RNSVGLength *)foreignObjectheight
|
||||
{
|
||||
if ([foreignObjectheight isEqualTo:_foreignObjectheight]) {
|
||||
return;
|
||||
}
|
||||
if ([foreignObjectheight isEqualTo:_foreignObjectheight]) {
|
||||
return;
|
||||
}
|
||||
|
||||
_foreignObjectheight = foreignObjectheight;
|
||||
[self invalidate];
|
||||
_foreignObjectheight = foreignObjectheight;
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user