Skip to content
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

Merged
merged 13 commits into from
Dec 4, 2024
Merged

Conversation

piaskowyk
Copy link
Member

@piaskowyk piaskowyk commented Nov 20, 2024

Summary

This PR addresses the issue reported at #6719 and aims to:

  • Unify the method used to obtain the view tag, as there are currently several approaches.
  • Avoid passing a class component to the findNodeHandler. Instead, we'll pass a ref to the component, similar to what Expo implemented here: [core] Use findNodeHandle with a native ref instead of class component instance expo/expo#33016.
  • Limit unnecessary invocations of findNodeHandler to no more than one call per render.
  • Remove the invocation of findHostInstance from Paper renderer on the New Architecture.

Additional Remarks:

  • When a class component is passed to createAnimatedComponent, it will still fall back to the slow path where we can get a native ref.
  • In 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 of findHostInstance to optimize the happy path.

Fixes #6719

Related PRs:

Test plan

  • check Paper
  • check Fabric
  • check Web

Copy link
Collaborator

@tjzel tjzel left a 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.

@piaskowyk piaskowyk marked this pull request as ready for review November 22, 2024 09:07
@piaskowyk piaskowyk requested review from tjzel and tomekzaw November 22, 2024 09:07
Copy link
Collaborator

@tjzel tjzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

@piaskowyk piaskowyk enabled auto-merge December 4, 2024 10:08
@piaskowyk piaskowyk added this pull request to the merge queue Dec 4, 2024
Merged via the queue into main with commit 5ffa477 Dec 4, 2024
9 checks passed
@piaskowyk piaskowyk deleted the @piaskowyk/findnodehandler-refactor branch December 4, 2024 10:09
piaskowyk added a commit that referenced this pull request Dec 10, 2024
piaskowyk added a commit that referenced this pull request Dec 10, 2024
@piaskowyk piaskowyk mentioned this pull request Dec 10, 2024
piaskowyk added a commit that referenced this pull request Dec 10, 2024
tjzel pushed a commit that referenced this pull request Dec 13, 2024
## Summary

This PR addresses the issue reported at
[https://github.com/software-mansion/react-native-reanimated/issues/6719](https://github.com/software-mansion/react-native-reanimated/issues/6719)
and aims to:

- **Unify the method used to obtain the view tag**, as there are
currently several approaches.
- **Avoid passing a class component to the findNodeHandler**. Instead,
we'll pass a ref to the component, similar to what Expo implemented
here:
[https://github.com/expo/expo/pull/33016](https://github.com/expo/expo/pull/33016).
- **Limit unnecessary invocations of findNodeHandler** to no more than
one call per render.
- **Remove the invocation of findHostInstance from Paper renderer** on
the New Architecture.

**Additional Remarks:**
- When a class component is passed to `createAnimatedComponent`, it will
still fall back to the slow path where we can get a native ref.
- In `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 of
`findHostInstance` to optimize the happy path.

Fixes
#6719

Related PRs:
- #6030
- #5960
- #4445
- expo/expo#33016

## Test plan

- [x] check Paper
- [x] check Fabric
- [x] check Web
tjzel pushed a commit that referenced this pull request Dec 13, 2024
## Summary

This PR addresses the issue reported at
[https://github.com/software-mansion/react-native-reanimated/issues/6719](https://github.com/software-mansion/react-native-reanimated/issues/6719)
and aims to:

- **Unify the method used to obtain the view tag**, as there are
currently several approaches.
- **Avoid passing a class component to the findNodeHandler**. Instead,
we'll pass a ref to the component, similar to what Expo implemented
here:
[https://github.com/expo/expo/pull/33016](https://github.com/expo/expo/pull/33016).
- **Limit unnecessary invocations of findNodeHandler** to no more than
one call per render.
- **Remove the invocation of findHostInstance from Paper renderer** on
the New Architecture.

**Additional Remarks:**
- When a class component is passed to `createAnimatedComponent`, it will
still fall back to the slow path where we can get a native ref.
- In `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 of
`findHostInstance` to optimize the happy path.

Fixes
#6719

Related PRs:
- #6030
- #5960
- #4445
- expo/expo#33016

## Test plan

- [x] check Paper
- [x] check Fabric
- [x] check Web
tjzel pushed a commit that referenced this pull request Dec 13, 2024
## Summary

This PR addresses the issue reported at
[https://github.com/software-mansion/react-native-reanimated/issues/6719](https://github.com/software-mansion/react-native-reanimated/issues/6719)
and aims to:

- **Unify the method used to obtain the view tag**, as there are
currently several approaches.
- **Avoid passing a class component to the findNodeHandler**. Instead,
we'll pass a ref to the component, similar to what Expo implemented
here:
[https://github.com/expo/expo/pull/33016](https://github.com/expo/expo/pull/33016).
- **Limit unnecessary invocations of findNodeHandler** to no more than
one call per render.
- **Remove the invocation of findHostInstance from Paper renderer** on
the New Architecture.

**Additional Remarks:**
- When a class component is passed to `createAnimatedComponent`, it will
still fall back to the slow path where we can get a native ref.
- In `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 of
`findHostInstance` to optimize the happy path.

Fixes
#6719

Related PRs:
- #6030
- #5960
- #4445
- expo/expo#33016

## Test plan

- [x] check Paper
- [x] check Fabric
- [x] check Web
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renimated calls findNodeHandle with class instances, which is a slow path in React
3 participants