Repository navigation
fix(native): accept SectionList refs in useScrollToTop under RN 0.87 strict types - #13221
Conversation
…strict types RN 0.87 enables the strict TypeScript API by default. ScrollView is now the component type, so the getScrollResponder branch of ScrollableWrapper no longer type-checks for SectionList, which only exposes scrollToLocation and matches none of the ScrollableView members. Add scrollToLocation to the ScrollableView union and scroll the list to the first item when a SectionList ref is passed.
✅ Deploy Preview for react-navigation-example ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13221 +/- ##
==========================================
+ Coverage 72.24% 78.04% +5.79%
==========================================
Files 238 263 +25
Lines 8391 10520 +2129
Branches 3480 4364 +884
==========================================
+ Hits 6062 8210 +2148
+ Misses 2274 2247 -27
- Partials 55 63 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
satya164
left a comment
There was a problem hiding this comment.
thanks for the pr. i have a couple of changes
| @@ -0,0 +1,165 @@ | |||
| import { expect, jest, test } from '@jest/globals'; | |||
There was a problem hiding this comment.
please remove this test. it doesn't test anything useful, but exact code that was just added.
| @@ -103,6 +110,12 @@ export function useScrollToTop(ref: React.RefObject<ScrollableWrapper>) { | |||
| scrollable.scrollToOffset({ offset: 0, animated: true }); | |||
| } else if ('scrollResponderScrollTo' in scrollable) { | |||
| scrollable.scrollResponderScrollTo({ y: 0, animated: true }); | |||
| } else if ('scrollToLocation' in scrollable) { | |||
| scrollable.scrollToLocation({ | |||
| sectionIndex: 0, | |||
| itemIndex: 0, | |||
| animated: true, | |||
| }); | |||
| } | |||
| } | |||
There was a problem hiding this comment.
move scrollToLocation to before scrollResponderScrollTo. scrollResponderScrollTo should be the last fallback.
|
from testing, it seems the only change we need is the return type of |
Problem
RN 0.87 enables the strict TypeScript API by default.
ScrollViewis now the component type (typeof ScrollViewWrapper), not the instance type. When aSectionListref is passed touseScrollToTop, it falls through to thegetScrollResponder()branch inScrollableWrapper, which fails to type-check becauseSectionList.getScrollResponder()returnsScrollResponderTypethat no longer matchesReact.ReactNode | ScrollView.Fix
Add
scrollToLocationto theScrollableViewunion soSectionListmatches directly on theScrollableViewbranch, avoiding the brokengetScrollResponderpath entirely. This also adds the runtimescrollToLocationhandler in the scroll-to-top logic.Reproduction
Fixes #13220