Skip to content

Commit

Permalink
fix: add trigger onScroll even if scroll offset has been changed from…
Browse files Browse the repository at this point in the history
… the outside
  • Loading branch information
matyas-igor committed Sep 9, 2020
1 parent 0a0929a commit 1b06a68
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/VirtualList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface Props {
stickyIndices?: number[]
style?: React.CSSProperties
onItemsRendered?({ startIndex, stopIndex }: RenderedRows): void
onScroll?(offset: number, event: UIEvent): void
onScroll?(offset: number, event?: UIEvent): void
renderItem(itemInfo: ItemInfo): React.ReactNode
}

Expand Down Expand Up @@ -159,11 +159,18 @@ export default class VirtualList extends React.PureComponent<Props, State> {
offset: nextProps.scrollOffset || 0,
scrollChangeReason: SCROLL_CHANGE_REASON.REQUESTED,
})
if (typeof nextProps.onScroll === 'function') {
nextProps.onScroll(nextProps.scrollOffset || 0)
}
} else if (typeof nextProps.scrollToIndex === 'number' && (scrollPropsHaveChanged || itemPropsHaveChanged)) {
const offset = this.getOffsetForIndex(nextProps.scrollToIndex, nextProps.scrollToAlignment, nextProps.itemCount)
this.setState({
offset: this.getOffsetForIndex(nextProps.scrollToIndex, nextProps.scrollToAlignment, nextProps.itemCount),
offset,
scrollChangeReason: SCROLL_CHANGE_REASON.REQUESTED,
})
if (typeof nextProps.onScroll === 'function') {
nextProps.onScroll(offset)
}
}
}

Expand Down

0 comments on commit 1b06a68

Please sign in to comment.