Skip to content
Closed
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
26 changes: 23 additions & 3 deletions src/MasonryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type State = {
};

// This will get cloned and added a bunch of props that are supposed to be on
// ScrollView so we wan't to make sure we don't pass them over (especially
// ScrollView so we want to make sure we don't pass them over (especially
// onLayout since it exists on both).
class FakeScrollView extends React.Component<{ style?: any, children?: any }> {
render() {
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class MasonryList extends React.Component<Props, State> {
state = _stateFromProps(this.props);
_listRefs: Array<?VirtualizedList> = [];
_scrollRef: ?ScrollView;
_endsReached = 0;
_endReached = false;

componentWillReceiveProps(newProps: Props) {
this.setState(_stateFromProps(newProps));
Expand Down Expand Up @@ -196,6 +196,26 @@ export default class MasonryList extends React.Component<Props, State> {
);
};

/**
* Temporary workaround for onEndReached getting called by each column
*/
_onEndReached = event => {
if (this._endReached) {
return;
}

this._endReached = true;

if (this.props.onEndReached) {
this.props.onEndReached(event);
}

// small lag to avoid _onEndReached getting called by multiple columns
setTimeout(() => {
this._endReached = false;
}, 200);
};

_getItemLayout = (columnIndex, rowIndex) => {
const column = this.state.columns[columnIndex];
let offset = 0;
Expand Down Expand Up @@ -242,7 +262,7 @@ export default class MasonryList extends React.Component<Props, State> {
renderItem({ item, index, column: col.index })}
renderScrollComponent={this._renderScrollComponent}
keyExtractor={keyExtractor}
onEndReached={onEndReached}
onEndReached={this._onEndReached}
onEndReachedThreshold={this.props.onEndReachedThreshold}
removeClippedSubviews={false}
/>,
Expand Down