File tree 2 files changed +17
-7
lines changed
handlers/gestures/GestureDetector
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 1
1
import React , { forwardRef } from 'react' ;
2
2
import type { LegacyRef , PropsWithChildren } from 'react' ;
3
3
import { tagMessage } from '../../../utils' ;
4
+ import { isRNSVGNode } from '../../../web/utils' ;
4
5
5
6
export const Wrap = forwardRef < HTMLDivElement , PropsWithChildren < { } > > (
6
7
( { children } , ref ) => {
7
8
try {
8
9
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9
10
const child : any = React . Children . only ( children ) ;
10
11
11
- const isRNSVGNode =
12
- Object . getPrototypeOf ( child ?. type ) ?. name === 'WebShape' ;
13
-
14
- if ( isRNSVGNode ) {
12
+ if ( isRNSVGNode ( child ) ) {
15
13
const clone = React . cloneElement (
16
14
child ,
17
15
{ ref } ,
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ function spherical2tilt(altitudeAngle: number, azimuthAngle: number) {
233
233
return { tiltX, tiltY } ;
234
234
}
235
235
236
- const RNSVGElements = [
236
+ export const RNSVGElements = new Set ( [
237
237
'Circle' ,
238
238
'ClipPath' ,
239
239
'Ellipse' ,
@@ -254,7 +254,7 @@ const RNSVGElements = [
254
254
'Text' ,
255
255
'TextPath' ,
256
256
'Use' ,
257
- ] ;
257
+ ] ) ;
258
258
259
259
// This function helps us determine whether given node is SVGElement or not. In our implementation of
260
260
// findNodeHandle, we can encounter such element in 2 forms - SVG tag or ref to SVG Element. Since Gesture Handler
@@ -269,7 +269,19 @@ export function isRNSVGElement(viewRef: SVGRef | GestureHandlerRef) {
269
269
const componentClassName = Object . getPrototypeOf ( viewRef ) . constructor . name ;
270
270
271
271
return (
272
- RNSVGElements . indexOf ( componentClassName ) >= 0 &&
272
+ RNSVGElements . has ( componentClassName ) &&
273
273
Object . hasOwn ( viewRef , 'elementRef' )
274
274
) ;
275
275
}
276
+
277
+ // This function checks if given node is SVGElement. Unlike the function above, this one
278
+ // operates on React Nodes, not DOM nodes.
279
+ //
280
+ // Second condition was introduced to handle case where SVG element was wrapped with
281
+ // `createAnimatedComponent` from Reanimated.
282
+ export function isRNSVGNode ( node : any ) {
283
+ return (
284
+ Object . getPrototypeOf ( node ?. type ) ?. name === 'WebShape' ||
285
+ RNSVGElements . has ( node ?. type ?. displayName )
286
+ ) ;
287
+ }
You can’t perform that action at this time.
0 commit comments