Skip to content

Commit

Permalink
Fix scroll value issue when scrollOffset is less than distance from w…
Browse files Browse the repository at this point in the history
…indow (#223)
  • Loading branch information
naqvitalha authored and muskeinsingh committed Aug 3, 2018
1 parent 9ccfbdb commit a0e665c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit a0e665c

Please sign in to comment.