diff --git a/src/createAnimatedComponent.tsx b/src/createAnimatedComponent.tsx index 5e1f7c96ed7..069fcc3c9f6 100644 --- a/src/createAnimatedComponent.tsx +++ b/src/createAnimatedComponent.tsx @@ -344,19 +344,6 @@ export default function createAnimatedComponent( _reattachNativeEvents( prevProps: AnimatedComponentProps ) { - let viewTag: number | undefined; - - for (const key in this.props) { - const prop = this.props[key]; - if ( - has('current', prop) && - prop.current instanceof WorkletEventHandler - ) { - if (viewTag === undefined) { - viewTag = prop.current.viewTag; - } - } - } for (const key in prevProps) { const prop = this.props[key]; if ( @@ -368,6 +355,9 @@ export default function createAnimatedComponent( } } + const node = this._getEventViewRef(); + const viewTag = findNodeHandle(options?.setNativeProps ? this : node); + for (const key in this.props) { const prop = this.props[key]; if ( @@ -375,8 +365,7 @@ export default function createAnimatedComponent( prop.current instanceof WorkletEventHandler && prop.current.reattachNeeded ) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - prop.current.registerForEvents(viewTag!, key); + prop.current.registerForEvents(viewTag as number, key); prop.current.reattachNeeded = false; } }