Skip to content

Commit 5dda561

Browse files
Fix bug Flatlist: called many many times
1 parent 606ff33 commit 5dda561

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/RefreshListView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type State = {
4545
isFooterRefreshing: boolean; // Whether the tail is refreshing
4646
footerState: RefreshState;
4747
};
48-
48+
let callOnScrollEnd = false;
4949
export default class RefreshListView<ItemT> extends Component<
5050
Props<ItemT>,
5151
State
@@ -146,6 +146,7 @@ export default class RefreshListView<ItemT> extends Component<
146146
scrollEventThrottle={16}
147147
onScroll={this._onScroll.bind(this)}
148148
ListFooterComponent={this._renderFooter}
149+
onEndReached={() => (callOnScrollEnd = true)}
149150
/>
150151
);
151152
}
@@ -157,10 +158,11 @@ export default class RefreshListView<ItemT> extends Component<
157158
let height = event.nativeEvent.layoutMeasurement.height;
158159
let contentHeight = Math.floor(event.nativeEvent.contentSize.height); //Solve the problem of not triggering Android loading more
159160

160-
if (this.shouldStartFooterRefreshing()) {
161+
if (callOnScrollEnd && this.shouldStartFooterRefreshing()) {
161162
if (offsetY + height >= contentHeight) {
162163
console.log('load more');
163164
this.startFooterRefreshing();
165+
callOnScrollEnd = false;
164166
}
165167
}
166168

0 commit comments

Comments
 (0)