From 0ec862d1503e71ec9e80f1e412d03b30cf44ae12 Mon Sep 17 00:00:00 2001 From: Wei-Wei Wu Date: Tue, 8 May 2018 10:04:32 -0700 Subject: [PATCH] Revert "fix for #998 (#1001)" This reverts commit 6226f56b4ed91c23db2521b5ba772374aeaca680. --- source/Grid/Grid.jest.js | 81 ---------------------------------------- source/Grid/Grid.js | 12 +----- 2 files changed, 2 insertions(+), 91 deletions(-) diff --git a/source/Grid/Grid.jest.js b/source/Grid/Grid.jest.js index 845940d07..e7a23d0a8 100644 --- a/source/Grid/Grid.jest.js +++ b/source/Grid/Grid.jest.js @@ -637,87 +637,6 @@ describe('Grid', () => { expect(node.scrollTop).toBe(1920); }); - // See issue #998 - it('call to recomputeGridSize should not reset position to scrollTo[Row|Column] when scrolling forward', () => { - const cellRendererCalls = []; - function cellRenderer({columnIndex, key, rowIndex, style}) { - cellRendererCalls.push({columnIndex, rowIndex}); - return defaultCellRenderer({columnIndex, key, rowIndex, style}); - } - const props = { - cellRenderer, - columnWidth: 100, - height: 40, - rowHeight: 20, - scrollToRow: 0, - scrollToColumn: 0, - width: 100, - }; - - const grid = render(getMarkup(props)); - expect(cellRendererCalls).toEqual([ - {columnIndex: 0, rowIndex: 0}, - {columnIndex: 0, rowIndex: 1}, - ]); - - //scroll forward to row 45 - simulateScroll({grid, scrollTop: 900, scrollLeft: 2400}); - - expect(grid.state.scrollDirectionVertical).toEqual( - SCROLL_DIRECTION_FORWARD, - ); - cellRendererCalls.splice(0); - - grid.recomputeGridSize({rowIndex: 45, columnIndex: 24}); - - //grid should still be at row 45, column 24 - expect(cellRendererCalls).toEqual([ - {columnIndex: 24, rowIndex: 45}, - {columnIndex: 24, rowIndex: 46}, - ]); - }); - // see #998 - it('call to recomputeGridSize should not reset position to scrollTo[Row|Column] when scrolling backward', () => { - const cellRendererCalls = []; - function cellRenderer({columnIndex, key, rowIndex, style}) { - cellRendererCalls.push({columnIndex, rowIndex}); - return defaultCellRenderer({columnIndex, key, rowIndex, style}); - } - const props = { - cellRenderer, - columnWidth: 100, - height: 40, - rowHeight: 20, - scrollToRow: 99, - scrollToColumn: 49, - width: 100, - }; - - const grid = render(getMarkup(props)); - expect(cellRendererCalls).toEqual([ - {columnIndex: 0, rowIndex: 0}, - {columnIndex: 0, rowIndex: 1}, - {columnIndex: 49, rowIndex: 98}, - {columnIndex: 49, rowIndex: 99}, - ]); - - //scroll backward to row 45 - simulateScroll({grid, scrollTop: 900, scrollLeft: 2400}); - - expect(grid.state.scrollDirectionVertical).toEqual( - SCROLL_DIRECTION_BACKWARD, - ); - cellRendererCalls.splice(0); - - grid.recomputeGridSize({rowIndex: 45, columnIndex: 24}); - - //grid should still be at row 45 and column 24 - expect(cellRendererCalls).toEqual([ - {columnIndex: 24, rowIndex: 45}, - {columnIndex: 24, rowIndex: 46}, - ]); - }); - it('should restore scroll offset for column when row count increases from 0 (and vice versa)', () => { const props = { columnWidth: 50, diff --git a/source/Grid/Grid.js b/source/Grid/Grid.js index 61e3d4aae..a3e0fc3b7 100644 --- a/source/Grid/Grid.js +++ b/source/Grid/Grid.js @@ -522,16 +522,8 @@ class Grid extends React.PureComponent { // In this case the cDU handler can't know if they changed. // Store this flag to let the next cDU pass know it needs to recompute the scroll offset. this._recomputeScrollLeftFlag = - scrollToColumn >= 0 && - (this.state.scrollDirectionHorizontal === SCROLL_DIRECTION_FORWARD - ? columnIndex <= scrollToColumn - : columnIndex >= scrollToColumn); - - this._recomputeScrollTopFlag = - scrollToRow >= 0 && - (this.state.scrollDirectionVertical === SCROLL_DIRECTION_FORWARD - ? rowIndex <= scrollToRow - : rowIndex >= scrollToRow); + scrollToColumn >= 0 && columnIndex <= scrollToColumn; + this._recomputeScrollTopFlag = scrollToRow >= 0 && rowIndex <= scrollToRow; // Clear cell cache in case we are scrolling; // Invalid row heights likely mean invalid cached content as well.