fix(Reanimated): useAnimatedRef breaking on SectionList #8301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8294
I went down the rabbit hole to find how to obtain proper node handles and host instances for Shadow Node Wrapper.
I tested the following components:
Native results
Logs from native Fabric
Conclusions
findNodeHandle()
always returns the correct handle on a refgetScrollableNode()
always returns a number handle and it's the correct handle (same asfindNodeHandle()
)findHostInstance_DEPRECATED()
always throws on some components, i.e.View
getNativeScrollRef()
always returns a result offindHostInstance_DEPRECATED()
on a ref, iffindHostInstance_DEPRECATED()
on the ref doesn't throw (seeScrollView
andFlatList
) or an object with__internalInstanceHandle
if it throws (seeFlashList
orSectionList
).__internalInstanceHandle.stateNode.node
.findHostInstance_DEPRECATED()
doesn't throw on a ref if ref has_reactInternals
property.getScrollRef()
andgetScrollResponder()
methods aren't necessary to obtain the ShadowNodeWrapper.Proposed solution:
findNodeHandle
on the ref.__internalInstanceHandle
prop. If it does, return it.getNativeScrollRef()
method. If it does, returngetNativeScrollRef().__internalInstanceHandle
._reactInternals
prop. If it does, returnfindHostInstanceDeprecated().__internalInstanceHandle
.Web results
Web logs
Web
getScrollableNode()
returns an actionable ref (i.e. - one that hasscrollTo
method). On components likeSectionList
this is the way of obtaining the actionable ref.getScrollableNode()
is not defined on every list component, i.e.SectionList
.getNativeScrollRef()
always provides an actionable ref if defined.findNodeHandle
is an identity function.Proposed solution:
getScrollableNode()
method. If it does, returngetScrollableNode()
.getNativeScrollRef()
method. If it does, returngetNativeScrollRef()
.Test plan