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

Fix animatedRef on Fabric #4445

Merged
merged 9 commits into from
May 22, 2023
Merged

Conversation

mstach60161
Copy link
Contributor

@mstach60161 mstach60161 commented May 10, 2023

Summary

Problem

If the scrollable component is not root, UI scrollTo doesn't work on Fabric.

#4384 - It was fixed here for Paper, but after this change app crashes on Fabric, because getScrollableNode in both architectures returns viewTag as a number, not component. It's working for Paper, because we are passing either component or number to findNodeHandle method, but on Fabric we need component ref.

Fix

Instead of getScrollableNode, we can use getNativeScrollRef and get scrollable reference.

TODO

Unfortunately this method is not implemented yet for Flash-list -> https://shopify.github.io/flash-list/docs/usage#:~:text=Unsupported%20methods%3A
so for now, UI scrollTo on FlashList works only for Paper Architecture.

Test plan

ScrollToExample:

  • Paper, ScrollView
  • Paper, FlatList
  • Fabric, ScrollView
  • Fabric, FlatList

@mstach60161 mstach60161 requested a review from tomekzaw May 10, 2023 17:36
@tomekzaw tomekzaw changed the title Fix animtedRef on Fabric Fix animatedRef on Fabric May 11, 2023
@piaskowyk
Copy link
Member

Does it mean that getScrollableNode on Paper returns a component but on Fabric the same function return a view tag?

src/reanimated2/hook/useAnimatedRef.ts Outdated Show resolved Hide resolved
src/reanimated2/hook/useAnimatedRef.ts Outdated Show resolved Hide resolved
mstach60161 and others added 2 commits May 15, 2023 14:48
Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
Copy link
Member

@piaskowyk piaskowyk left a comment

Choose a reason for hiding this comment

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

We need add some comments here, and table with information about which method is used by ScrollView, FlatList and FlashList

Comment on lines 30 to 35
console.warn(
`[Reanimated] ${
component.displayName || component.name || 'Component'
} has no implemented 'getNativeScrollRef' method. Please report this issue to the library maintainers.`
);
}
Copy link
Member

Choose a reason for hiding this comment

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

We need to remove this config because we can pass here reference to any object.

@@ -19,6 +22,25 @@ function getShareableShadowNodeFromComponent(
return getShadowNodeWrapperFromHostInstance(component);
}

function getScrollableRef(component: ComponentRef): ComponentRef {
Copy link
Member

Choose a reason for hiding this comment

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

getScrollableRef -> getComponentRef

Copy link
Member

Choose a reason for hiding this comment

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

getComponentRef is too generic I think

src/reanimated2/hook/useAnimatedRef.ts Outdated Show resolved Hide resolved
Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
Copy link
Member

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

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

👏

@mstach60161 mstach60161 added this pull request to the merge queue May 22, 2023
Merged via the queue into main with commit 54bf5ce May 22, 2023
@mstach60161 mstach60161 deleted the @mstach60161/fix-stateNode-undefined branch May 22, 2023 12:02
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

- Fixes software-mansion#4256

### Problem

If the scrollable component is not root, UI `scrollTo` doesn't work on
Fabric.

software-mansion#4384 - It was fixed here for Paper, but after this change app crashes
on Fabric, because `getScrollableNode` in both architectures returns
viewTag as a number, not component. It's working for Paper, because we
are passing either component or number to `findNodeHandle` method, but
on Fabric we need component ref.

### Fix
 
Instead of `getScrollableNode`, we can use `getNativeScrollRef` and get
scrollable reference.


### TODO

Unfortunately this method is not implemented yet for `Flash-list` ->
https://shopify.github.io/flash-list/docs/usage#:~:text=Unsupported%20methods%3A
so for now, UI `scrollTo` on FlashList works only for Paper
Architecture.

## Test plan

ScrollToExample:

- Paper, ScrollView
- Paper, FlatList
- Fabric, ScrollView
- Fabric, FlatList

---------

Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
@piaskowyk piaskowyk mentioned this pull request Nov 22, 2024
3 tasks
github-merge-queue bot pushed a commit that referenced this pull request Dec 4, 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
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.

3.0.2 Android Cannot read property 'stateNode' of undefined
3 participants