diff --git a/android/src/main/java/com/horcrux/svg/RenderableView.java b/android/src/main/java/com/horcrux/svg/RenderableView.java index d3d792a3b..57d6e8197 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableView.java +++ b/android/src/main/java/com/horcrux/svg/RenderableView.java @@ -22,6 +22,7 @@ import android.graphics.RectF; import android.graphics.Region; import android.view.ViewParent; +import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ColorPropConverter; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; @@ -30,7 +31,9 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableType; +import com.facebook.react.bridge.WritableMap; import com.facebook.react.touch.ReactHitSlopView; +import com.facebook.react.uimanager.events.RCTEventEmitter; import com.facebook.react.uimanager.PointerEvents; import java.lang.reflect.Field; import java.util.ArrayList; @@ -98,6 +101,14 @@ public abstract class RenderableView extends VirtualView implements ReactHitSlop private @Nullable ArrayList mAttributeList; private @Nullable RenderableView mCaller; + public void onReceiveNativeEvent() { + WritableMap event = Arguments.createMap(); + ReactContext reactContext = (ReactContext)getContext(); + reactContext + .getJSModule(RCTEventEmitter.class) + .receiveEvent(getId(), "topSvgLayout", event); + } + @Nullable String mFilter; private static final Pattern regex = Pattern.compile("[0-9.-]+"); diff --git a/android/src/main/java/com/horcrux/svg/RenderableViewManager.java b/android/src/main/java/com/horcrux/svg/RenderableViewManager.java index dccc8d900..06095e45f 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableViewManager.java +++ b/android/src/main/java/com/horcrux/svg/RenderableViewManager.java @@ -142,6 +142,7 @@ import com.facebook.react.viewmanagers.RNSVGUseManagerDelegate; import com.facebook.react.viewmanagers.RNSVGUseManagerInterface; import com.horcrux.svg.events.SvgLoadEvent; +import com.horcrux.svg.events.SvgOnLayoutEvent; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -589,6 +590,12 @@ class RenderableViewManager extends VirtualViewManager super(svgclass); } + public Map getExportedCustomDirectEventTypeConstants() { + Map eventTypes = new HashMap<>(); + eventTypes.put(SvgOnLayoutEvent.EVENT_NAME, MapBuilder.of("registrationName", "onSvgLayout")); + return eventTypes; + } + static class GroupViewManagerAbstract extends RenderableViewManager { GroupViewManagerAbstract(SVGClass svgClass) { super(svgClass); diff --git a/android/src/main/java/com/horcrux/svg/VirtualView.java b/android/src/main/java/com/horcrux/svg/VirtualView.java index 815b236d6..ba19448f3 100644 --- a/android/src/main/java/com/horcrux/svg/VirtualView.java +++ b/android/src/main/java/com/horcrux/svg/VirtualView.java @@ -20,11 +20,12 @@ import com.facebook.react.bridge.ReadableType; import com.facebook.react.common.ReactConstants; import com.facebook.react.uimanager.DisplayMetricsHolder; -import com.facebook.react.uimanager.OnLayoutEvent; import com.facebook.react.uimanager.PointerEvents; import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.views.view.ReactViewGroup; +import com.horcrux.svg.events.SvgOnLayoutEvent; + import java.util.ArrayList; import javax.annotation.Nullable; @@ -603,7 +604,14 @@ void setClientRect(RectF rect) { EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(mContext, getId()); if (eventDispatcher != null) { - eventDispatcher.dispatchEvent(OnLayoutEvent.obtain(this.getId(), left, top, width, height)); + eventDispatcher.dispatchEvent( + new SvgOnLayoutEvent( + UIManagerHelper.getSurfaceId(VirtualView.this), + this.getId(), + left, + top, + width, + height)); } } diff --git a/android/src/main/java/com/horcrux/svg/events/SvgOnLayoutEvent.java b/android/src/main/java/com/horcrux/svg/events/SvgOnLayoutEvent.java new file mode 100644 index 000000000..5f32c419a --- /dev/null +++ b/android/src/main/java/com/horcrux/svg/events/SvgOnLayoutEvent.java @@ -0,0 +1,50 @@ +package com.horcrux.svg.events; + +import androidx.core.util.Pools.SynchronizedPool; + +import com.facebook.react.bridge.Arguments; +import com.facebook.react.bridge.WritableMap; +import com.facebook.react.uimanager.PixelUtil; +import com.facebook.react.uimanager.events.Event; + +public class SvgOnLayoutEvent extends Event { + + public static final String EVENT_NAME = "topSvgLayout"; + public int x = 0; + public int y = 0; + public int width = 0; + public int height = 0; + + public SvgOnLayoutEvent(int surfaceId, int viewId, int x, int y, int width, int height) { + super(surfaceId, viewId); + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + @Override + public String getEventName() { + return EVENT_NAME; + } + + @Override + public short getCoalescingKey() { + return 0; + } + + @Override + protected WritableMap getEventData() { + WritableMap layout = Arguments.createMap(); + layout.putDouble("x", (double) PixelUtil.toDIPFromPixel((float) x)); + layout.putDouble("y", (double) PixelUtil.toDIPFromPixel((float) y)); + layout.putDouble("width", (double) PixelUtil.toDIPFromPixel((float) width)); + layout.putDouble("height", (double) PixelUtil.toDIPFromPixel((float) height)); + + WritableMap event = Arguments.createMap(); + event.putMap("layout", layout); + event.putInt("target", getViewTag()); + + return event; + } +} diff --git a/apple/RNSVGNode.h b/apple/RNSVGNode.h index 1ad9f40b3..292621535 100644 --- a/apple/RNSVGNode.h +++ b/apple/RNSVGNode.h @@ -62,7 +62,7 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE; @property (nonatomic, assign) CGRect fillBounds; @property (nonatomic, assign) CGRect strokeBounds; @property (nonatomic, assign) CGRect markerBounds; -@property (nonatomic, copy) RCTDirectEventBlock onLayout; +@property (nonatomic, copy) RCTDirectEventBlock onSvgLayout; /** * RNSVGSvgView which ownes current RNSVGNode diff --git a/apple/RNSVGNode.mm b/apple/RNSVGNode.mm index 7e7b98fc8..fcf828798 100644 --- a/apple/RNSVGNode.mm +++ b/apple/RNSVGNode.mm @@ -12,6 +12,11 @@ #import "RNSVGGlyphContext.h" #import "RNSVGGroup.h" +#ifdef RCT_NEW_ARCH_ENABLED +#import +using namespace facebook::react; +#endif // RCT_NEW_ARCH_ENABLED + @interface RNSVGNode () @property (nonatomic, readwrite, weak) RNSVGSvgView *svgView; @property (nonatomic, readwrite, weak) RNSVGGroup *textRoot; @@ -264,16 +269,18 @@ - (void)setClientRect:(CGRect)clientRect _clientRect = clientRect; #ifdef RCT_NEW_ARCH_ENABLED if (_eventEmitter != nullptr) { - facebook::react::LayoutMetrics customLayoutMetrics = _layoutMetrics; - customLayoutMetrics.frame.size.width = _clientRect.size.width; - customLayoutMetrics.frame.size.height = _clientRect.size.height; - customLayoutMetrics.frame.origin.x = _clientRect.origin.x; - customLayoutMetrics.frame.origin.y = _clientRect.origin.y; - _eventEmitter->onLayout(customLayoutMetrics); + static_cast(*_eventEmitter) + .onSvgLayout( + {.layout = { + .x = static_cast(_clientRect.origin.x), + .y = static_cast(_clientRect.origin.y), + .width = static_cast(_clientRect.size.width), + .height = static_cast(_clientRect.size.height) + }}); } #else - if (self.onLayout) { - self.onLayout(@{ + if (self.onSvgLayout) { + self.onSvgLayout(@{ @"layout" : @{ @"x" : @(_clientRect.origin.x), @"y" : @(_clientRect.origin.y), @@ -660,7 +667,7 @@ - (void)prepareForRecycle _fillBounds = CGRectZero; _strokeBounds = CGRectZero; _markerBounds = CGRectZero; - _onLayout = nil; + _onSvgLayout = nil; _svgView = nil; _textRoot = nil; diff --git a/apple/ViewManagers/RNSVGNodeManager.mm b/apple/ViewManagers/RNSVGNodeManager.mm index dd563eb0f..800b8343b 100644 --- a/apple/ViewManagers/RNSVGNodeManager.mm +++ b/apple/ViewManagers/RNSVGNodeManager.mm @@ -41,7 +41,7 @@ - (RNSVGPlatformView *)view RCT_EXPORT_VIEW_PROPERTY(clipPath, NSString) RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule) RCT_EXPORT_VIEW_PROPERTY(responsible, BOOL) -RCT_EXPORT_VIEW_PROPERTY(onLayout, RCTDirectEventBlock) +RCT_EXPORT_VIEW_PROPERTY(onSvgLayout, RCTDirectEventBlock) RCT_CUSTOM_SHADOW_PROPERTY(top, id, RNSVGNode) {} RCT_CUSTOM_SHADOW_PROPERTY(right, id, RNSVGNode) {} diff --git a/src/elements/Svg.tsx b/src/elements/Svg.tsx index c5da1573c..7ec207c0e 100644 --- a/src/elements/Svg.tsx +++ b/src/elements/Svg.tsx @@ -177,10 +177,6 @@ export default class Svg extends Shape { extractResponder(props, props, this as ResponderInstanceProps); - if (onLayout != null) { - props.onLayout = onLayout; - } - const gStyle = Object.assign({}, StyleSheet.flatten(style)); if (transform) { if (gStyle.transform) { @@ -214,6 +210,7 @@ export default class Svg extends Shape { strokeLinecap, strokeLinejoin, strokeMiterlimit, + onLayout, }} /> diff --git a/src/fabric/CircleNativeComponent.ts b/src/fabric/CircleNativeComponent.ts index 09ec6df5e..d35a441f4 100644 --- a/src/fabric/CircleNativeComponent.ts +++ b/src/fabric/CircleNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -56,6 +66,7 @@ interface NativeProps cx?: UnsafeMixed; cy?: UnsafeMixed; r?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGCircle', { diff --git a/src/fabric/ClipPathNativeComponent.ts b/src/fabric/ClipPathNativeComponent.ts index d9c79ca4d..f027f4462 100644 --- a/src/fabric/ClipPathNativeComponent.ts +++ b/src/fabric/ClipPathNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -59,7 +69,9 @@ interface NativeProps extends ViewProps, SvgNodeCommonProps, SvgRenderableCommonProps, - SvgGroupCommonProps {} + SvgGroupCommonProps { + onSvgLayout?: DirectEventHandler; +} export default codegenNativeComponent('RNSVGClipPath', { interfaceOnly: true, diff --git a/src/fabric/EllipseNativeComponent.ts b/src/fabric/EllipseNativeComponent.ts index 4773f8316..0a973aa2e 100644 --- a/src/fabric/EllipseNativeComponent.ts +++ b/src/fabric/EllipseNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -57,6 +67,7 @@ interface NativeProps cy?: UnsafeMixed; rx?: UnsafeMixed; ry?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGEllipse', { diff --git a/src/fabric/ForeignObjectNativeComponent.ts b/src/fabric/ForeignObjectNativeComponent.ts index 2acdb0342..982497d9c 100644 --- a/src/fabric/ForeignObjectNativeComponent.ts +++ b/src/fabric/ForeignObjectNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,14 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -64,6 +73,7 @@ interface NativeProps y?: UnsafeMixed; height?: UnsafeMixed; width?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGForeignObject', { diff --git a/src/fabric/GroupNativeComponent.ts b/src/fabric/GroupNativeComponent.ts index d509b8440..36d9cf136 100644 --- a/src/fabric/GroupNativeComponent.ts +++ b/src/fabric/GroupNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -59,7 +69,9 @@ interface NativeProps extends ViewProps, SvgNodeCommonProps, SvgRenderableCommonProps, - SvgGroupCommonProps {} + SvgGroupCommonProps { + onSvgLayout?: DirectEventHandler; +} export default codegenNativeComponent('RNSVGGroup', { interfaceOnly: true, diff --git a/src/fabric/ImageNativeComponent.ts b/src/fabric/ImageNativeComponent.ts index 77226f8c2..f19da4d59 100644 --- a/src/fabric/ImageNativeComponent.ts +++ b/src/fabric/ImageNativeComponent.ts @@ -44,6 +44,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -74,6 +83,7 @@ interface NativeProps align?: string; meetOrSlice?: Int32; onLoad?: DirectEventHandler; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGImage', { diff --git a/src/fabric/LineNativeComponent.ts b/src/fabric/LineNativeComponent.ts index ab0e45add..e30174e32 100644 --- a/src/fabric/LineNativeComponent.ts +++ b/src/fabric/LineNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -57,6 +67,7 @@ interface NativeProps y1?: UnsafeMixed; x2?: UnsafeMixed; y2?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGLine', { diff --git a/src/fabric/MaskNativeComponent.ts b/src/fabric/MaskNativeComponent.ts index dac11a35f..88e2652c1 100644 --- a/src/fabric/MaskNativeComponent.ts +++ b/src/fabric/MaskNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -67,6 +77,7 @@ interface NativeProps maskUnits?: Int32; maskContentUnits?: Int32; maskType?: Int32; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGMask', { diff --git a/src/fabric/PathNativeComponent.ts b/src/fabric/PathNativeComponent.ts index 5520ae183..6d155c48b 100644 --- a/src/fabric/PathNativeComponent.ts +++ b/src/fabric/PathNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,14 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -54,6 +63,7 @@ interface NativeProps SvgNodeCommonProps, SvgRenderableCommonProps { d?: string; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGPath', { diff --git a/src/fabric/RectNativeComponent.ts b/src/fabric/RectNativeComponent.ts index 9d8f37ba0..ec5251b21 100644 --- a/src/fabric/RectNativeComponent.ts +++ b/src/fabric/RectNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -59,6 +69,7 @@ interface NativeProps width?: UnsafeMixed; rx?: UnsafeMixed; ry?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGRect', { diff --git a/src/fabric/TSpanNativeComponent.ts b/src/fabric/TSpanNativeComponent.ts index 1e85f40bf..f7c5127d9 100644 --- a/src/fabric/TSpanNativeComponent.ts +++ b/src/fabric/TSpanNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -76,6 +86,7 @@ interface NativeProps SvgGroupCommonProps, SvgTextCommonProps { content?: string; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGTSpan', { diff --git a/src/fabric/TextNativeComponent.ts b/src/fabric/TextNativeComponent.ts index 539b228b9..c695394cd 100644 --- a/src/fabric/TextNativeComponent.ts +++ b/src/fabric/TextNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -74,7 +84,9 @@ interface NativeProps SvgNodeCommonProps, SvgRenderableCommonProps, SvgGroupCommonProps, - SvgTextCommonProps {} + SvgTextCommonProps { + onSvgLayout?: DirectEventHandler; +} export default codegenNativeComponent('RNSVGText', { interfaceOnly: true, diff --git a/src/fabric/TextPathNativeComponent.ts b/src/fabric/TextPathNativeComponent.ts index e6d630766..687d730a7 100644 --- a/src/fabric/TextPathNativeComponent.ts +++ b/src/fabric/TextPathNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -80,6 +90,7 @@ interface NativeProps midLine?: string; spacing?: string; startOffset?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGTextPath', { diff --git a/src/fabric/UseNativeComponent.ts b/src/fabric/UseNativeComponent.ts index e1e01bb53..b546418b3 100644 --- a/src/fabric/UseNativeComponent.ts +++ b/src/fabric/UseNativeComponent.ts @@ -1,6 +1,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; import type { ColorValue } from 'react-native'; import type { + DirectEventHandler, Float, Int32, WithDefault, @@ -31,6 +32,15 @@ type ColorStruct = Readonly<{ brushRef?: string; }>; +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + interface SvgRenderableCommonProps { color?: ColorValue; fill?: UnsafeMixed; @@ -58,6 +68,7 @@ interface NativeProps y?: UnsafeMixed; height?: UnsafeMixed; width?: UnsafeMixed; + onSvgLayout?: DirectEventHandler; } export default codegenNativeComponent('RNSVGUse', { diff --git a/src/lib/extract/extractProps.ts b/src/lib/extract/extractProps.ts index df192fa49..010b05b3c 100644 --- a/src/lib/extract/extractProps.ts +++ b/src/lib/extract/extractProps.ts @@ -108,7 +108,7 @@ export default function extractProps( } if (onLayout) { - extracted.onLayout = onLayout; + extracted.onSvgLayout = onLayout; } if (markerStart) { diff --git a/src/lib/extract/types.ts b/src/lib/extract/types.ts index fdf4c5622..29e883033 100644 --- a/src/lib/extract/types.ts +++ b/src/lib/extract/types.ts @@ -7,6 +7,10 @@ import type { TransformsStyle, } from 'react-native'; import type React from 'react'; +import { + DirectEventHandler, + Int32, +} from 'react-native/Libraries/Types/CodegenTypes'; export type NumberProp = string | number; export type NumberArray = NumberProp[] | NumberProp; @@ -299,6 +303,15 @@ export interface CommonMarkerProps { markerEnd?: string; } +type OnSvgLayoutEvent = Readonly<{ + layout: { + x: Int32; + y: Int32; + width: Int32; + height: Int32; + }; +}>; + export interface NativeProps { onLayout?: (event: LayoutChangeEvent) => void; } @@ -349,7 +362,7 @@ export type extractedProps = { opacity?: number; matrix?: number[]; propList?: string[]; - onLayout?: (event: LayoutChangeEvent) => void; + onSvgLayout?: DirectEventHandler; ref?: (instance: React.Component | null) => void; markerStart?: string; markerMid?: string;