fix: macOS new architecture build (#2341)

# Summary
Based on recommendations from this
[proposition](https://github.com/software-mansion/react-native-svg/issues/2192#issuecomment-2177330499)
and added some changes now we can build macOS using the new
architecture.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| macOS     |         |

---------

Co-authored-by: Maciej Stosio <maciekstosio@users.noreply.github.com>
This commit is contained in:
Bohdan Artiukhov
2024-07-23 15:34:32 +02:00
committed by GitHub
parent 0d97399d06
commit 67620f5b6a
21 changed files with 459 additions and 260 deletions

View File

@@ -58,9 +58,9 @@ using namespace facebook::react;
- (BOOL)isSimpleClipPath
{
NSArray<RNSVGView *> *children = self.subviews;
NSArray<RNSVGPlatformView *> *children = self.subviews;
if (children.count == 1) {
RNSVGView *child = children[0];
RNSVGPlatformView *child = children[0];
if ([child class] != [RNSVGGroup class]) {
return true;
}

View File

@@ -12,21 +12,12 @@
#import "RNSVGPainter.h"
#import "RNSVGVBMOS.h"
#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTViewComponentView.h>
#endif // RCT_NEW_ARCH_ENABLED
@class RNSVGNode;
@class RNSVGMarker;
@class RNSVGMask;
@class RNSVGFilter;
@interface RNSVGSvgView :
#ifdef RCT_NEW_ARCH_ENABLED
RCTViewComponentView <RNSVGContainer>
#else
RNSVGView <RNSVGContainer>
#endif // RCT_NEW_ARCH_ENABLED
@interface RNSVGSvgView : RNSVGView <RNSVGContainer>
@property (nonatomic, strong) RNSVGLength *bbWidth;
@property (nonatomic, strong) RNSVGLength *bbHeight;

View File

@@ -119,13 +119,13 @@ using namespace facebook::react;
rendered = NO;
}
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)mountChildComponentView:(RNSVGView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
[super mountChildComponentView:childComponentView index:index];
[self invalidate];
}
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)unmountChildComponentView:(RNSVGView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
[super unmountChildComponentView:childComponentView index:index];
[self invalidate];
@@ -133,14 +133,14 @@ using namespace facebook::react;
#endif // RCT_NEW_ARCH_ENABLED
- (void)insertReactSubview:(RNSVGView *)subview atIndex:(NSInteger)atIndex
- (void)insertReactSubview:(RNSVGPlatformView *)subview atIndex:(NSInteger)atIndex
{
[super insertReactSubview:subview atIndex:atIndex];
[self insertSubview:subview atIndex:atIndex];
[self invalidate];
}
- (void)removeReactSubview:(RNSVGView *)subview
- (void)removeReactSubview:(RNSVGPlatformView *)subview
{
[super removeReactSubview:subview];
[self invalidate];
@@ -290,7 +290,7 @@ using namespace facebook::react;
_viewBoxTransform = CGAffineTransformIdentity;
_invviewBoxTransform = CGAffineTransformIdentity;
}
for (RNSVGView *node in self.subviews) {
for (RNSVGPlatformView *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
RNSVGNode *svg = (RNSVGNode *)node;
if (svg.responsible && !self.responsible) {

View File

@@ -12,10 +12,6 @@
#import <React/RCTPointerEvents.h>
#import <React/UIView+React.h>
#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTViewComponentView.h>
#endif // RCT_NEW_ARCH_ENABLED
@class RNSVGGroup;
/**
@@ -23,12 +19,7 @@
interfaces for all non-definition nodes.
*/
@interface RNSVGNode :
#ifdef RCT_NEW_ARCH_ENABLED
RCTViewComponentView
#else
RNSVGView
#endif // RCT_NEW_ARCH_ENABLED
@interface RNSVGNode : RNSVGView
/*
N[1/Sqrt[2], 36]
The inverse of the square root of 2.

View File

@@ -46,27 +46,27 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
return self;
}
- (void)insertReactSubview:(RNSVGView *)subview atIndex:(NSInteger)atIndex
- (void)insertReactSubview:(RNSVGPlatformView *)subview atIndex:(NSInteger)atIndex
{
[super insertReactSubview:subview atIndex:atIndex];
[self insertSubview:subview atIndex:atIndex];
[self invalidate];
}
- (void)removeReactSubview:(RNSVGView *)subview
- (void)removeReactSubview:(RNSVGPlatformView *)subview
{
[super removeReactSubview:subview];
[self invalidate];
}
#ifdef RCT_NEW_ARCH_ENABLED
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)mountChildComponentView:(RNSVGView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
[super mountChildComponentView:childComponentView index:index];
[self invalidate];
}
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
- (void)unmountChildComponentView:(RNSVGView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
[super unmountChildComponentView:childComponentView index:index];
[self invalidate];
@@ -84,7 +84,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
return;
}
_dirty = true;
RNSVGView *container = self.superview;
RNSVGPlatformView *container = self.superview;
// on Fabric, when the child components are added to hierarchy and their props are set,
// their superview is not set yet.
if (container != nil) {
@@ -240,7 +240,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
}
_matrix = matrix;
_invmatrix = CGAffineTransformInvert(matrix);
RNSVGView *container = self.superview;
RNSVGPlatformView *container = self.superview;
// on Fabric, when the child components are added to hierarchy and their props are set,
// their superview is still their componentView, we change it in `mountChildComponentView` method.
if ([container conformsToProtocol:@protocol(RNSVGContainer)]) {

View File

@@ -1,5 +1,8 @@
// Most (if not all) of this file could probably go away once react-native-macos's version of RCTUIKit.h makes its way
// upstream. https://github.com/microsoft/react-native-macos/issues/242
#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTViewComponentView.h>
#endif // RCT_NEW_ARCH_ENABLED
#if !TARGET_OS_OSX
@@ -8,7 +11,11 @@
#define RNSVGColor UIColor
#define RNSVGPlatformView UIView
#define RNSVGTextView UILabel
#ifdef RCT_NEW_ARCH_ENABLED
#define RNSVGView RCTViewComponentView
#else
#define RNSVGView UIView
#endif // RCT_NEW_ARCH_ENABLED
#else // TARGET_OS_OSX [
@@ -29,7 +36,16 @@ extern "C" {
#define RNSVGPlatformView NSView
#define RNSVGTextView NSTextView
@interface RNSVGView : RCTUIView
@interface RNSVGColor (CGColor)
- (NSColor *)CGColor;
@end
@interface RNSVGView :
#ifdef RCT_NEW_ARCH_ENABLED
RCTViewComponentView
#else
RCTUIView
#endif // RCT_NEW_ARCH_ENABLED
@property CGPoint center;
@property (nonatomic, strong) RNSVGColor *tintColor;

View File

@@ -311,7 +311,7 @@ RNSVGTopAlignedLabel *label;
NSString *str = self.content;
if (!str) {
for (RNSVGView *node in self.subviews) {
for (RNSVGPlatformView *node in self.subviews) {
if ([node isKindOfClass:[RNSVGText class]]) {
RNSVGText *text = (RNSVGText *)node;
advance += [text getSubtreeTextChunksTotalAdvance];

View File

@@ -345,7 +345,7 @@ using namespace facebook::react;
return cachedAdvance;
}
CGFloat advance = 0;
for (RNSVGView *node in self.subviews) {
for (RNSVGPlatformView *node in self.subviews) {
if ([node isKindOfClass:[RNSVGText class]]) {
RNSVGText *text = (RNSVGText *)node;
advance += [text getSubtreeTextChunksTotalAdvance];

View File

@@ -128,7 +128,11 @@ void setCommonNodeProps(const T &nodeProps, RNSVGNode *node)
node.pointerEvents = RCTPointerEventsUnspecified;
}
node.accessibilityIdentifier = RCTNSStringFromStringNilIfEmpty(nodeProps.testId);
#if !TARGET_OS_OSX
node.isAccessibilityElement = nodeProps.accessible;
#else
node.accessibilityElement = nodeProps.accessible;
#endif // !TARGET_OS_OSX
node.accessibilityLabel = RCTNSStringFromStringNilIfEmpty(nodeProps.accessibilityLabel);
}

View File

@@ -18,7 +18,7 @@ RCT_EXPORT_MODULE()
return [RNSVGDefs new];
}
- (RNSVGView *)view
- (RNSVGPlatformView *)view
{
return [self node];
}

View File

@@ -20,7 +20,7 @@ RCT_EXPORT_MODULE()
return [RNSVGNode new];
}
- (RNSVGView *)view
- (RNSVGPlatformView *)view
{
return [self node];
}

View File

@@ -13,7 +13,7 @@
RCT_EXPORT_MODULE()
- (RNSVGView *)view
- (RNSVGPlatformView *)view
{
return [RNSVGSvgView new];
}