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:
Wojciech Lewicki
2022-08-16 12:00:32 +02:00
committed by GitHub
parent 77267be5fc
commit 98c14b4f45
177 changed files with 16855 additions and 16018 deletions

View File

@@ -6,14 +6,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGUse.h"
#import "RNSVGSymbol.h"
#import <React/RCTLog.h>
#import "RNSVGSymbol.h"
#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
@@ -40,166 +40,171 @@ using namespace facebook::react;
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGUseProps>(props);
const auto &newProps = *std::static_pointer_cast<const RNSVGUseProps>(props);
self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
if (RCTNSStringFromStringNilIfEmpty(newProps.useheight)) {
self.useheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.useheight)];
}
if (RCTNSStringFromStringNilIfEmpty(newProps.usewidth)) {
self.usewidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.usewidth)];
}
if (RCTNSStringFromStringNilIfEmpty(newProps.height)) {
self.useheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.height)];
}
if (RCTNSStringFromStringNilIfEmpty(newProps.width)) {
self.usewidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.width)];
}
self.href = RCTNSStringFromStringNilIfEmpty(newProps.href);
self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
if (RCTNSStringFromStringNilIfEmpty(newProps.useheight)) {
self.useheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.useheight)];
}
if (RCTNSStringFromStringNilIfEmpty(newProps.usewidth)) {
self.usewidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.usewidth)];
}
if (RCTNSStringFromStringNilIfEmpty(newProps.height)) {
self.useheight = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.height)];
}
if (RCTNSStringFromStringNilIfEmpty(newProps.width)) {
self.usewidth = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.width)];
}
self.href = RCTNSStringFromStringNilIfEmpty(newProps.href);
setCommonRenderableProps(newProps, self);
setCommonRenderableProps(newProps, self);
}
- (void)prepareForRecycle
{
[super prepareForRecycle];
_x = nil;
_y = nil;
_useheight = nil;
_usewidth = nil;
_href = nil;
[super prepareForRecycle];
_x = nil;
_y = nil;
_useheight = nil;
_usewidth = nil;
_href = nil;
}
#endif // RN_FABRIC_ENABLED
- (void)setHref:(NSString *)href
{
if ([href isEqualToString:_href]) {
return;
}
if ([href isEqualToString:_href]) {
return;
}
[self invalidate];
_href = href;
[self invalidate];
_href = href;
}
- (void)setX:(RNSVGLength *)x
{
if ([x isEqualTo:_x]) {
return;
}
if ([x isEqualTo:_x]) {
return;
}
[self invalidate];
_x = x;
[self invalidate];
_x = x;
}
- (void)setY:(RNSVGLength *)y
{
if ([y isEqualTo:_y]) {
return;
}
if ([y isEqualTo:_y]) {
return;
}
[self invalidate];
_y = y;
[self invalidate];
_y = y;
}
- (void)setUsewidth:(RNSVGLength *)usewidth
{
if ([usewidth isEqualTo:_usewidth]) {
return;
}
if ([usewidth isEqualTo:_usewidth]) {
return;
}
[self invalidate];
_usewidth = usewidth;
[self invalidate];
_usewidth = usewidth;
}
- (void)setUseheight:(RNSVGLength *)useheight
{
if ([useheight isEqualTo:_useheight]) {
return;
}
if ([useheight isEqualTo:_useheight]) {
return;
}
[self invalidate];
_useheight = useheight;
[self invalidate];
_useheight = useheight;
}
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
CGContextTranslateCTM(context, [self relativeOnWidth:self.x], [self relativeOnHeight:self.y]);
RNSVGNode* definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (definedTemplate) {
[self beginTransparencyLayer:context];
[self clip:context];
CGContextTranslateCTM(context, [self relativeOnWidth:self.x], [self relativeOnHeight:self.y]);
RNSVGNode *definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (definedTemplate) {
[self beginTransparencyLayer:context];
[self clip:context];
if ([definedTemplate isKindOfClass:[RNSVGRenderable class]]) {
[(RNSVGRenderable*)definedTemplate mergeProperties:self];
}
if ([definedTemplate isKindOfClass:[RNSVGRenderable class]]) {
[(RNSVGRenderable *)definedTemplate mergeProperties:self];
}
if ([definedTemplate class] == [RNSVGSymbol class]) {
RNSVGSymbol *symbol = (RNSVGSymbol*)definedTemplate;
[symbol renderSymbolTo:context width:[self relativeOnWidth:self.usewidth] height:[self relativeOnHeight:self.useheight]];
} else {
[definedTemplate renderTo:context rect:rect];
}
if ([definedTemplate isKindOfClass:[RNSVGRenderable class]]) {
[(RNSVGRenderable*)definedTemplate resetProperties];
}
[self endTransparencyLayer:context];
} else if (self.href) {
// TODO: calling yellow box here
RCTLogWarn(@"`Use` element expected a pre-defined svg template as `href` prop, template named: %@ is not defined.", self.href);
return;
if ([definedTemplate class] == [RNSVGSymbol class]) {
RNSVGSymbol *symbol = (RNSVGSymbol *)definedTemplate;
[symbol renderSymbolTo:context
width:[self relativeOnWidth:self.usewidth]
height:[self relativeOnHeight:self.useheight]];
} else {
return;
[definedTemplate renderTo:context rect:rect];
}
CGRect bounds = definedTemplate.clientRect;
self.clientRect = bounds;
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;
if ([definedTemplate isKindOfClass:[RNSVGRenderable class]]) {
[(RNSVGRenderable *)definedTemplate resetProperties];
}
self.frame = bounds;
[self endTransparencyLayer:context];
} else if (self.href) {
// TODO: calling yellow box here
RCTLogWarn(
@"`Use` element expected a pre-defined svg template as `href` prop, template named: %@ is not defined.",
self.href);
return;
} else {
return;
}
CGRect bounds = definedTemplate.clientRect;
self.clientRect = bounds;
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;
}
- (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint transformed = CGPointApplyAffineTransform(point, self.invmatrix);
transformed = CGPointApplyAffineTransform(transformed, self.invTransform);
RNSVGNode const* definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (event) {
self.active = NO;
} else if (self.active) {
return self;
}
RNSVGPlatformView const* hitChild = [definedTemplate hitTest:transformed withEvent:event];
if (hitChild) {
self.active = YES;
return self;
}
return nil;
}
- (CGPathRef)getPath: (CGContextRef)context
- (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGAffineTransform transform = CGAffineTransformMakeTranslation([self relativeOnWidth:self.x], [self relativeOnHeight:self.y]);
RNSVGNode const* definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (!definedTemplate) {
return nil;
}
CGPathRef path = [definedTemplate getPath:context];
return CGPathCreateCopyByTransformingPath(path, &transform);
CGPoint transformed = CGPointApplyAffineTransform(point, self.invmatrix);
transformed = CGPointApplyAffineTransform(transformed, self.invTransform);
RNSVGNode const *definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (event) {
self.active = NO;
} else if (self.active) {
return self;
}
RNSVGPlatformView const *hitChild = [definedTemplate hitTest:transformed withEvent:event];
if (hitChild) {
self.active = YES;
return self;
}
return nil;
}
- (CGPathRef)getPath:(CGContextRef)context
{
CGAffineTransform transform =
CGAffineTransformMakeTranslation([self relativeOnWidth:self.x], [self relativeOnHeight:self.y]);
RNSVGNode const *definedTemplate = [self.svgView getDefinedTemplate:self.href];
if (!definedTemplate) {
return nil;
}
CGPathRef path = [definedTemplate getPath:context];
return CGPathCreateCopyByTransformingPath(path, &transform);
}
@end