-
Notifications
You must be signed in to change notification settings - Fork 24.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
feat: [ScrollView,FlatList] Add ref.scrollToStart({animated?: boolean})
method
#45202
base: main
Are you sure you want to change the base?
Conversation
e5f52f3
to
88aa470
Compare
88aa470
to
8a8e141
Compare
This seems like a sane addition, but current implementation is not correct for horizontal lists in RTL. |
Let me create a demo and test it https://reactnative.dev/blog/2016/08/19/right-to-left-support-for-react-native-apps#making-an-app-rtl-ready |
The RNTester FlatList example has a checkbox for RTL which will apply forceRTL. That is what I usually use. But, the gist is that, as of recent versions, all the events and commands are aligned so that x coordinate space is not inverted. This can be a bit tricky, since as more content is added to the list, the x coordinate will change alongside.
|
@@ -146,6 +146,11 @@ class VirtualizedList extends StateSafePureComponent<Props, State> { | |||
this.scrollToOffset({animated, offset}); | |||
} | |||
|
|||
scrollToStart(params?: ?{animated?: ?boolean, ...}) { | |||
const animated = params ? params.animated : true; | |||
this.scrollToOffset({animated, offset: 0}); |
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.
how does this behave if ScrollView has insets?
Summary:
scrollToEnd(options?: {animated?: boolean})
is available out of the box, and it's surprising thatscrollToStart
wasn't added yetChangelog:
[GENERAL] [ADDED] - [ScrollView, FlatList] Add
ref.scrollToStart({animated?: boolean})
methodTest Plan:
Manual + types tests
Screen.Recording.2024-06-27.at.12.27.29.mov
Screen.Recording.2024-06-27.at.12.23.52.mov