Skip to content

Commit

Permalink
Added onVisibleEndReached and using it instead of onEndReached.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya Chandra authored and Ananya Chandra committed Jan 30, 2019
1 parent 431d3ab commit 88d306c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
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.sticky.13",
"version": "1.4.0-beta.sticky.14",
"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: 6 additions & 2 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface RecyclerListViewProps {
onScroll?: (rawEvent: ScrollEvent, offsetX: number, offsetY: number) => void;
onRecreate?: (params: OnRecreateParams) => void;
onEndReached?: () => void;
onVisibleEndReached?: () => void;
onEndReachedThreshold?: number;
onVisibleIndexesChanged?: TOnItemStatusChanged;
onVisibleIndicesChanged?: TOnItemStatusChanged;
Expand Down Expand Up @@ -570,17 +571,20 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}

private _processOnEndReached(): void {
if (this.props.onEndReached && this._virtualRenderer) {
if ((this.props.onEndReached || this.props.onVisibleEndReached) && this._virtualRenderer) {
const layout = this._virtualRenderer.getLayoutDimension();
const viewabilityTracker = this._virtualRenderer.getViewabilityTracker();
if (viewabilityTracker) {
const windowBound = this.props.isHorizontal ? layout.width - this._layout.width : layout.height - this._layout.height;
const lastOffset = viewabilityTracker ? viewabilityTracker.getLastOffset() : 0;
if (windowBound - lastOffset <= Default.value<number>(this.props.onEndReachedThreshold, 0)) {
if (!this._onEndReachedCalled) {
if (this.props.onEndReached && !this._onEndReachedCalled) {
this._onEndReachedCalled = true;
this.props.onEndReached();
}
if (this.props.onVisibleEndReached && windowBound - lastOffset <= 0) {
this.props.onVisibleEndReached();
}
} else {
this._onEndReachedCalled = false;
}
Expand Down
5 changes: 1 addition & 4 deletions src/core/StickyContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class StickyContainer<P extends StickyContainerProps, S extends S
ref: this._getRecyclerRef,
onVisibleIndicesChanged: this._onVisibleIndicesChanged,
onScroll: this._onScroll,
onEndReached: this._onEndReached,
onVisibleEndReached: this._onEndReached,
});
return (
<View style={this.props.style ? this.props.style : {flex: 1}}>
Expand Down Expand Up @@ -158,9 +158,6 @@ export default class StickyContainer<P extends StickyContainerProps, S extends S
if (this._stickyFooterRef) {
this._stickyFooterRef.onEndReached();
}
if (this.props.children && this.props.children.props.onEndReached) {
this.props.children.props.onEndReached();
}
}

private _assertChildType = (): void => {
Expand Down

0 comments on commit 88d306c

Please sign in to comment.