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 for scroll to offset api #219

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recyclerlistview",
"version": "1.4.0-beta.10",
"version": "1.4.0-beta.12",
"description": "The listview that you need and deserve. It was built for performance, uses cell recycling to achieve smooth scrolling.",
"main": "dist/reactnative/index.js",
"types": "dist/reactnative/index.d.ts",
Expand Down
8 changes: 2 additions & 6 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends

public scrollToOffset = (x: number, y: number, animate: boolean = false): void => {
if (this._scrollComponent) {
if (this.props.useWindowScroll) {
x += this.props.distanceFromWindow!;
y += this.props.distanceFromWindow!;
}
if (this.props.isHorizontal) {
y = 0;
} else {
Expand Down Expand Up @@ -304,7 +300,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends

public getCurrentScrollOffset(): number {
const viewabilityTracker = this._virtualRenderer.getViewabilityTracker();
return viewabilityTracker ? viewabilityTracker.getLastOffset() : 0;
return (viewabilityTracker ? viewabilityTracker.getLastOffset() : 0) + this.props.distanceFromWindow!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If think it should be 0 if viewability tracker is unavailable otherwise without doing anything there will be a non zero offset.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, minimum offset for viewability tracker is zero. Thus this should only be attributed if lastOffset > distanceFromWindow

}

public findApproxFirstVisibleIndex(): number {
Expand Down Expand Up @@ -432,7 +428,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
this._virtualRenderer.attachVisibleItemsListener(this.props.onVisibleIndexesChanged!);
}
this._params = {
initialOffset: this.props.initialOffset ? this.props.initialOffset : this._initialOffset,
initialOffset: this._initialOffset ? this._initialOffset : this.props.initialOffset,
initialRenderIndex: this.props.initialRenderIndex,
isHorizontal: this.props.isHorizontal,
itemCount: this.props.dataProvider.getSize(),
Expand Down