Skip to content

Commit a720634

Browse files
committed
Setting :isScrolling immediately (rather than waiting on RAF) in :onScroll handler
1 parent 8bf0103 commit a720634

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

dist/react-virtualized.js

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-virtualized.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

es/Grid/Grid.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,9 @@ var Grid = function (_Component) {
353353

354354
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
355355
var columnDatum = this._columnMetadata[columnIndex];
356-
var child = renderCell({ columnIndex: columnIndex, rowIndex: rowIndex });
356+
var renderedCell = renderCell({ columnIndex: columnIndex, rowIndex: rowIndex });
357357
var key = rowIndex + '-' + columnIndex;
358-
359-
child = React.createElement(
358+
var child = React.createElement(
360359
'div',
361360
{
362361
key: key,
@@ -368,7 +367,7 @@ var Grid = function (_Component) {
368367
width: this._getColumnWidth(columnIndex)
369368
}
370369
},
371-
child
370+
renderedCell
372371
);
373372

374373
childrenToDisplay.push(child);
@@ -727,8 +726,18 @@ var Grid = function (_Component) {
727726
// The mouse may move faster then the animation frame does.
728727
// Use requestAnimationFrame to avoid over-updating.
729728
if (this.state.scrollLeft !== scrollLeft || this.state.scrollTop !== scrollTop) {
729+
// Browsers with cancelable scroll events (eg. Firefox) interrupt scrolling animations if scrollTop/scrollLeft is set.
730+
// Other browsers (eg. Safari) don't scroll as well without the help under certain conditions (DOM or style changes during scrolling).
731+
// All things considered, this seems to be the best current work around that I'm aware of.
732+
// For more information see https://github.com/bvaughn/react-virtualized/pull/124
730733
var scrollPositionChangeReason = event.cancelable ? SCROLL_POSITION_CHANGE_REASONS.OBSERVED : SCROLL_POSITION_CHANGE_REASONS.REQUESTED;
731734

735+
if (!this.state.isScrolling) {
736+
this.setState({
737+
isScrolling: true
738+
});
739+
}
740+
732741
this._setNextState({
733742
isScrolling: true,
734743
scrollLeft: scrollLeft,

source/Grid/Grid.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,9 @@ export default class Grid extends Component {
430430

431431
for (let columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
432432
let columnDatum = this._columnMetadata[columnIndex]
433-
let child = renderCell({ columnIndex, rowIndex })
433+
let renderedCell = renderCell({ columnIndex, rowIndex })
434434
let key = `${rowIndex}-${columnIndex}`
435-
436-
child = (
435+
let child = (
437436
<div
438437
key={key}
439438
className='Grid__cell'
@@ -444,7 +443,7 @@ export default class Grid extends Component {
444443
width: this._getColumnWidth(columnIndex)
445444
}}
446445
>
447-
{child}
446+
{renderedCell}
448447
</div>
449448
)
450449

@@ -780,6 +779,12 @@ export default class Grid extends Component {
780779
? SCROLL_POSITION_CHANGE_REASONS.OBSERVED
781780
: SCROLL_POSITION_CHANGE_REASONS.REQUESTED
782781

782+
if (!this.state.isScrolling) {
783+
this.setState({
784+
isScrolling: true
785+
})
786+
}
787+
783788
this._setNextState({
784789
isScrolling: true,
785790
scrollLeft,

0 commit comments

Comments
 (0)