|
1 |
| -type GestureHandlerRef = { |
2 |
| - viewTag: GestureHandlerRef; |
3 |
| - current: HTMLElement; |
4 |
| -}; |
| 1 | +import type { GestureHandlerRef, SVGRef } from './web/interfaces'; |
| 2 | +import { isRNSVGElement } from './web/utils'; |
5 | 3 |
|
6 | 4 | export default function findNodeHandle(
|
7 |
| - viewRef: GestureHandlerRef | HTMLElement |
8 |
| -): HTMLElement | number { |
| 5 | + viewRef: GestureHandlerRef | SVGRef | HTMLElement | SVGElement |
| 6 | +): HTMLElement | SVGElement | number { |
9 | 7 | // Old API assumes that child handler is HTMLElement.
|
10 | 8 | // However, if we nest handlers, we will get ref to another handler.
|
11 | 9 | // In that case, we want to recursively call findNodeHandle with new handler viewTag (which can also be ref to another handler).
|
12 | 10 | if ((viewRef as GestureHandlerRef)?.viewTag !== undefined) {
|
13 | 11 | return findNodeHandle((viewRef as GestureHandlerRef).viewTag);
|
14 | 12 | }
|
15 | 13 |
|
16 |
| - if (viewRef instanceof HTMLElement) { |
| 14 | + if (viewRef instanceof Element) { |
17 | 15 | if (viewRef.style.display === 'contents') {
|
18 | 16 | return findNodeHandle(viewRef.firstChild as HTMLElement);
|
19 | 17 | }
|
20 | 18 |
|
21 | 19 | return viewRef;
|
22 | 20 | }
|
23 | 21 |
|
| 22 | + if (isRNSVGElement(viewRef)) { |
| 23 | + return (viewRef as SVGRef).elementRef.current; |
| 24 | + } |
| 25 | + |
24 | 26 | // In new API, we receive ref object which `current` field points to wrapper `div` with `display: contents;`.
|
25 | 27 | // We want to return the first descendant (in DFS order) that doesn't have this property.
|
26 |
| - let element = viewRef?.current; |
| 28 | + let element = (viewRef as GestureHandlerRef)?.current; |
27 | 29 |
|
28 | 30 | while (element && element.style.display === 'contents') {
|
29 | 31 | element = element.firstChild as HTMLElement;
|
|
0 commit comments