-
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
Add onStartReached and onStartReachedThreshold to VirtualizedList #35321
Conversation
@@ -146,19 +146,6 @@ export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> { | |||
*/ | |||
numColumns?: number | undefined; | |||
|
|||
/** |
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.
Those are already defined in VirtualizedList
Base commit: 6003e70 |
Base commit: 6003e70 |
PR build artifact for 8f7f6ad is ready. |
PR build artifact for 8f7f6ad is ready. |
export function FlatList_onStartReached(): React.Node { | ||
const [output, setOutput] = React.useState(''); | ||
const exampleProps = { | ||
onStartReached: (info: {distanceFromStart: number, ...}) => |
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.
Is this called when a new list is mounted at zero position?
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.
Yes it will, I think both behaviour seem ok to me.
Overall lgtm but please add unit test coverage to the existing suite. |
@NickGerleman Thanks for the review, I think I addressed everything. |
PR build artifact for 0295f84 is ready. |
PR build artifact for 0295f84 is ready. |
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
// TODO: T121172172 Look into why we're "defaulting" to a threshold of 2 when oERT is not present | ||
const threshold = | ||
onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : 2; | ||
const startThreshold = | ||
onStartReachedThresholdOrDefault(onStartReachedThreshold) * visibleLength; |
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.
Hey, I finally am getting around to some internal feedback on the change (just minor nits), but then I noticed that I think this line is a behavior change. Before, if onEndReachedThreshold
wasn't set, the threshold was 2 pixels. But now it is 2 viewports, which would be a decent shift.
Would you mind if I change that back when landing?
// TODO: T121172172 Look into why we're "defaulting" to a threshold of 2 when oERT is not present | ||
const threshold = | ||
onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : 2; | ||
const startThreshold = | ||
onStartReachedThresholdOrDefault(onStartReachedThreshold) * visibleLength; | ||
const endThreshold = | ||
onEndReachedThresholdOrDefault(onEndReachedThreshold) * visibleLength; | ||
const isWithinStartThreshold = distanceFromStart <= startThreshold; | ||
const isWithinEndThreshold = distanceFromEnd <= endThreshold; |
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.
// TODO: T121172172 Look into why we're "defaulting" to a threshold of 2 when oERT is not present | |
const threshold = | |
onEndReachedThreshold != null ? onEndReachedThreshold * visibleLength : 2; | |
const startThreshold = | |
onStartReachedThresholdOrDefault(onStartReachedThreshold) * visibleLength; | |
const endThreshold = | |
onEndReachedThresholdOrDefault(onEndReachedThreshold) * visibleLength; | |
const isWithinStartThreshold = distanceFromStart <= startThreshold; | |
const isWithinEndThreshold = distanceFromEnd <= endThreshold; | |
// TODO: T121172172 Look into why we're "defaulting" to a threshold of 2px | |
// when oERT is not present (different from 2 viewports used elsewhere) | |
const DEFAULT_THRESHOLD_PX = 2; | |
const startThreshold = | |
onStartReachedThreshold != null | |
? onStartReachedThreshold * visibleLength | |
: DEFAULT_THRESHOLD_PX; | |
const endThreshold = | |
onEndReachedThreshold != null | |
? onEndReachedThreshold * visibleLength | |
: DEFAULT_THRESHOLD_PX; | |
const isWithinStartThreshold = distanceFromStart <= startThreshold; | |
const isWithinEndThreshold = distanceFromEnd <= endThreshold; |
This is the patch I have on the incoming diff. The code here... definitely seems incorrect. But also if it has always been like this I'm sure there is product code which might work incorrectly if the callback is called two viewports away from where it was before.
Really should probably just make it zero everywhere or at least two everywhere instead of 2px here and 2 viewports elsewhere and implied by the functions.
@NickGerleman merged this pull request in 7683713. |
Hey thanks for merging this, didn't have the time to address your feedback, I assume you did it yourself? |
Yep! I added in the patch in the most recent comment. |
…cebook#35321) Summary: Add `onStartReached` and `onStartReachedThreshold` to `VirtualizedList`. This allows implementing bidirectional paging. ## Changelog [General] [Added] - Add onStartReached and onStartReachedThreshold to VirtualizedList Pull Request resolved: facebook#35321 Test Plan: Tested in the new RN tester example that the callback is triggered when close to the start of the list. Reviewed By: yungsters Differential Revision: D41653054 Pulled By: NickGerleman fbshipit-source-id: 368b357fa0d83a43afb52a3f8df84a2fbbedc132
Summary
Add
onStartReached
andonStartReachedThreshold
toVirtualizedList
. This allows implementing bidirectional paging.Changelog
[General] [Added] - Add onStartReached and onStartReachedThreshold to VirtualizedList
Test Plan
Tested in the new RN tester example that the callback is triggered when close to the start of the list.