-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor findNodeHandler #6736
base: main
Are you sure you want to change the base?
Refactor findNodeHandler #6736
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall. Make sure to test it with the newest Gesture Handler and SVG on their more complex examples, since they used to have cases where these refs mechanisms broke.
packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/NativeEventsManager.ts
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/NativeEventsManager.ts
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/NativeEventsManager.ts
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/NativeEventsManager.ts
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/NativeEventsManager.ts
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx
Show resolved
Hide resolved
packages/react-native-reanimated/src/platform-specific/RNRenderer.ts
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/createAnimatedComponent/commonTypes.ts
Show resolved
Hide resolved
packages/react-native-reanimated/src/platform-specific/RNRenderer.ts
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/platform-specific/RNRenderer.ts
Outdated
Show resolved
Hide resolved
? this.#managedComponent | ||
: componentAnimatedRef | ||
) ?? -1; | ||
if (typeof scrollableNode === 'number') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work as intended on Fabric where there are shadow node wrappers instead of view tags (numbers)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On both platforms, getScrollableNode
returns a number - I've checked it for both ScrollView and FlatList.
packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx
Outdated
Show resolved
Hide resolved
packages/react-native-reanimated/src/platform-specific/RNRenderer.ts
Outdated
Show resolved
Hide resolved
// This is a native ref to a Paper component | ||
return ref; | ||
} | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we throw an error in such case for easier debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When findHostInstanceFastPath
returns undefined
we call findHostInstance_DEPRECATED()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an error. That just means it’s a ref to a non-native component, and it’s necessary to call findHostInstance_DEPRECATED
on them - I'll add a proper comment to code to explain it.
} catch (e) { | ||
findHostInstance_DEPRECATED = (_ref: unknown) => null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will that happen? Shouldn't we throw an error indeed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the previous behavior. I wonder if we should change it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just followed the previous implementation, but it might be more reasonable to throw an error instead
|
||
resolveFindHostInstance_DEPRECATED(); | ||
return findHostInstance_DEPRECATED( | ||
isFabric() ? component : component._componentRef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we can skip this isFabric()
call here and just call a function that uses findHostInstance_DEPRECATED
under the hood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can call isFabric()
only once to determine which implementation should be called but now I think there's a risk that isFabric()
will be called too early.
packages/react-native-reanimated/src/createAnimatedComponent/NativeEventsManager.ts
Show resolved
Hide resolved
// This is a native ref to a Paper component | ||
return ref; | ||
} | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When findHostInstanceFastPath
returns undefined
we call findHostInstance_DEPRECATED()
} catch (e) { | ||
findHostInstance_DEPRECATED = (_ref: unknown) => null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the previous behavior. I wonder if we should change it 🤔
|
||
resolveFindHostInstance_DEPRECATED(); | ||
return findHostInstance_DEPRECATED( | ||
isFabric() ? component : component._componentRef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
Summary
This PR addresses the issue reported at #6719 and aims to:
Additional Remarks:
createAnimatedComponent
, it will still fall back to the slow path where we can get a native ref.NativeEventManager
, we need to call findNodeHandler again after every render to ensure that the children of<GestureDetector />
haven't changed their native tags.LayoutAnimationConfig
still uses findNodeHandler. It requires a complete refactor of their functionality to eliminate its use, and I plan to handle this in another PR.findHostInstance_DEPRECATED
always follows the slow path even for native refs, which is why I've implemented our own version offindHostInstance
to optimize the happy path.Fixes #6719
Related PRs:
Test plan