Skip to content

Commit 62b9d78

Browse files
feat: add onSvgLayout event to ios
1 parent c85523b commit 62b9d78

18 files changed

+108
-73
lines changed

apple/RNSVGNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
6262
@property (nonatomic, assign) CGRect fillBounds;
6363
@property (nonatomic, assign) CGRect strokeBounds;
6464
@property (nonatomic, assign) CGRect markerBounds;
65-
@property (nonatomic, copy) RCTDirectEventBlock onLayout;
65+
@property (nonatomic, copy) RCTDirectEventBlock onSvgLayout;
6666

6767
/**
6868
* RNSVGSvgView which ownes current RNSVGNode

apple/RNSVGNode.mm

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#import "RNSVGGlyphContext.h"
1313
#import "RNSVGGroup.h"
1414

15+
#ifdef RCT_NEW_ARCH_ENABLED
16+
#import <react/renderer/components/rnsvg/ComponentDescriptors.h>
17+
using namespace facebook::react;
18+
#endif // RCT_NEW_ARCH_ENABLED
19+
1520
@interface RNSVGNode ()
1621
@property (nonatomic, readwrite, weak) RNSVGSvgView *svgView;
1722
@property (nonatomic, readwrite, weak) RNSVGGroup *textRoot;
@@ -264,16 +269,18 @@ - (void)setClientRect:(CGRect)clientRect
264269
_clientRect = clientRect;
265270
#ifdef RCT_NEW_ARCH_ENABLED
266271
if (_eventEmitter != nullptr) {
267-
facebook::react::LayoutMetrics customLayoutMetrics = _layoutMetrics;
268-
customLayoutMetrics.frame.size.width = _clientRect.size.width;
269-
customLayoutMetrics.frame.size.height = _clientRect.size.height;
270-
customLayoutMetrics.frame.origin.x = _clientRect.origin.x;
271-
customLayoutMetrics.frame.origin.y = _clientRect.origin.y;
272-
_eventEmitter->onLayout(customLayoutMetrics);
272+
static_cast<const RNSVGGroupEventEmitter &>(*_eventEmitter)
273+
.onSvgLayout(
274+
{.layout = {
275+
.x = static_cast<int>(_clientRect.origin.x),
276+
.y = static_cast<int>(_clientRect.origin.y),
277+
.width = static_cast<int>(_clientRect.size.width),
278+
.height = static_cast<int>(_clientRect.size.height)
279+
}});
273280
}
274281
#else
275-
if (self.onLayout) {
276-
self.onLayout(@{
282+
if (self.onSvgLayout) {
283+
self.onSvgLayout(@{
277284
@"layout" : @{
278285
@"x" : @(_clientRect.origin.x),
279286
@"y" : @(_clientRect.origin.y),
@@ -660,7 +667,7 @@ - (void)prepareForRecycle
660667
_fillBounds = CGRectZero;
661668
_strokeBounds = CGRectZero;
662669
_markerBounds = CGRectZero;
663-
_onLayout = nil;
670+
_onSvgLayout = nil;
664671

665672
_svgView = nil;
666673
_textRoot = nil;

apple/ViewManagers/RNSVGNodeManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ - (RNSVGPlatformView *)view
4141
RCT_EXPORT_VIEW_PROPERTY(clipPath, NSString)
4242
RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule)
4343
RCT_EXPORT_VIEW_PROPERTY(responsible, BOOL)
44-
RCT_EXPORT_VIEW_PROPERTY(onLayout, RCTDirectEventBlock)
44+
RCT_EXPORT_VIEW_PROPERTY(onSvgLayout, RCTDirectEventBlock)
4545

4646
RCT_CUSTOM_SHADOW_PROPERTY(top, id, RNSVGNode) {}
4747
RCT_CUSTOM_SHADOW_PROPERTY(right, id, RNSVGNode) {}

src/fabric/CircleNativeComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ type ColorStruct = Readonly<{
3333
}>;
3434

3535
type OnSvgLayoutEvent = Readonly<{
36-
x: Int32;
37-
y: Int32;
38-
width: Int32;
39-
height: Int32;
36+
layout: {
37+
x: Int32;
38+
y: Int32;
39+
width: Int32;
40+
height: Int32;
41+
};
4042
}>;
4143

4244
interface SvgRenderableCommonProps {

src/fabric/ClipPathNativeComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ type ColorStruct = Readonly<{
3333
}>;
3434

3535
type OnSvgLayoutEvent = Readonly<{
36-
x: Int32;
37-
y: Int32;
38-
width: Int32;
39-
height: Int32;
36+
layout: {
37+
x: Int32;
38+
y: Int32;
39+
width: Int32;
40+
height: Int32;
41+
};
4042
}>;
4143

4244
interface SvgRenderableCommonProps {

src/fabric/EllipseNativeComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ type ColorStruct = Readonly<{
3333
}>;
3434

3535
type OnSvgLayoutEvent = Readonly<{
36-
x: Int32;
37-
y: Int32;
38-
width: Int32;
39-
height: Int32;
36+
layout: {
37+
x: Int32;
38+
y: Int32;
39+
width: Int32;
40+
height: Int32;
41+
};
4042
}>;
4143

4244
interface SvgRenderableCommonProps {

src/fabric/ForeignObjectNativeComponent.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ type ColorStruct = Readonly<{
3333
}>;
3434

3535
type OnSvgLayoutEvent = Readonly<{
36-
x: Int32;
37-
y: Int32;
38-
width: Int32;
39-
height: Int32;
36+
layout: {
37+
x: Int32;
38+
y: Int32;
39+
width: Int32;
40+
height: Int32;
41+
};
4042
}>;
41-
4243
interface SvgRenderableCommonProps {
4344
color?: ColorValue;
4445
fill?: UnsafeMixed<ColorValue | ColorStruct>;

src/fabric/GroupNativeComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ type ColorStruct = Readonly<{
3333
}>;
3434

3535
type OnSvgLayoutEvent = Readonly<{
36-
x: Int32;
37-
y: Int32;
38-
width: Int32;
39-
height: Int32;
36+
layout: {
37+
x: Int32;
38+
y: Int32;
39+
width: Int32;
40+
height: Int32;
41+
};
4042
}>;
4143

4244
interface SvgRenderableCommonProps {

src/fabric/ImageNativeComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ type ColorStruct = Readonly<{
4545
}>;
4646

4747
type OnSvgLayoutEvent = Readonly<{
48-
x: Int32;
49-
y: Int32;
50-
width: Int32;
51-
height: Int32;
48+
layout: {
49+
x: Int32;
50+
y: Int32;
51+
width: Int32;
52+
height: Int32;
53+
};
5254
}>;
5355

5456
interface SvgRenderableCommonProps {

src/fabric/LineNativeComponent.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ type ColorStruct = Readonly<{
3333
}>;
3434

3535
type OnSvgLayoutEvent = Readonly<{
36-
x: Int32;
37-
y: Int32;
38-
width: Int32;
39-
height: Int32;
36+
layout: {
37+
x: Int32;
38+
y: Int32;
39+
width: Int32;
40+
height: Int32;
41+
};
4042
}>;
4143

4244
interface SvgRenderableCommonProps {

0 commit comments

Comments
 (0)