mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-05 22:56:11 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)]) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ RCT_EXPORT_MODULE()
|
||||
return [RNSVGDefs new];
|
||||
}
|
||||
|
||||
- (RNSVGView *)view
|
||||
- (RNSVGPlatformView *)view
|
||||
{
|
||||
return [self node];
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ RCT_EXPORT_MODULE()
|
||||
return [RNSVGNode new];
|
||||
}
|
||||
|
||||
- (RNSVGView *)view
|
||||
- (RNSVGPlatformView *)view
|
||||
{
|
||||
return [self node];
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
- (RNSVGView *)view
|
||||
- (RNSVGPlatformView *)view
|
||||
{
|
||||
return [RNSVGSvgView new];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user