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 scroll value issue when scrollOffset is less than distance from w… #223

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends

public getCurrentScrollOffset(): number {
const viewabilityTracker = this._virtualRenderer.getViewabilityTracker();
let currentOffset = (viewabilityTracker ? viewabilityTracker.getLastOffset() : 0);
if (currentOffset > this.props.distanceFromWindow!) {
currentOffset += this.props.distanceFromWindow!;
}
return currentOffset;
return viewabilityTracker ? viewabilityTracker.getLastActualOffset() + this.props.distanceFromWindow! : 0;
}

public findApproxFirstVisibleIndex(): number {
Expand Down
7 changes: 7 additions & 0 deletions src/core/ViewabilityTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class ViewabilityTracker {
public onEngagedRowsChanged: TOnItemStatusChanged | null;

private _currentOffset: number;
private _actualOffset: number;
private _maxOffset: number;
private _renderAheadOffset: number;
private _visibleWindow: Range;
Expand All @@ -32,6 +33,7 @@ export default class ViewabilityTracker {

constructor(renderAheadOffset: number, initialOffset: number) {
this._currentOffset = Math.max(0, initialOffset);
this._actualOffset = this._currentOffset;
this._maxOffset = 0;
this._renderAheadOffset = renderAheadOffset;
this._visibleWindow = { start: 0, end: 0 };
Expand Down Expand Up @@ -75,6 +77,7 @@ export default class ViewabilityTracker {
}

public updateOffset(offset: number): void {
this._actualOffset = offset;
offset = Math.min(this._maxOffset, Math.max(0, offset));
if (this._currentOffset !== offset) {
this._currentOffset = offset;
Expand All @@ -91,6 +94,10 @@ export default class ViewabilityTracker {
return this._currentOffset;
}

public getLastActualOffset(): number {
return this._actualOffset;
}

public getEngagedIndexes(): number[] {
return this._engagedIndexes;
}
Expand Down