@@ -270,8 +270,6 @@ export default class Grid extends PureComponent {
270270 this . _invokeOnGridRenderedHelper = this . _invokeOnGridRenderedHelper . bind ( this )
271271 this . _onScroll = this . _onScroll . bind ( this )
272272 this . _setScrollingContainerRef = this . _setScrollingContainerRef . bind ( this )
273- this . _updateScrollLeftForScrollToColumn = this . _updateScrollLeftForScrollToColumn . bind ( this )
274- this . _updateScrollTopForScrollToRow = this . _updateScrollTopForScrollToRow . bind ( this )
275273
276274 this . _columnWidthGetter = this . _wrapSizeGetter ( props . columnWidth )
277275 this . _rowHeightGetter = this . _wrapSizeGetter ( props . rowHeight )
@@ -387,6 +385,40 @@ export default class Grid extends PureComponent {
387385 } )
388386 }
389387
388+ /**
389+ * Ensure offset position is visible
390+ * Useful for animating position changes
391+ */
392+ scrollToPosition ( {
393+ scrollLeft,
394+ scrollTop
395+ } = { } ) {
396+ this . _setScrollPosition ( { scrollLeft, scrollTop } )
397+ }
398+
399+ /**
400+ * Gets offsets for a given cell and alignment
401+ */
402+ getOffsetForCell ( {
403+ columnIndex,
404+ rowIndex,
405+ scrollToAlignment = this . props . scrollToAlignment
406+ } = { } ) {
407+ const scrollToColumn = columnIndex >= 0 ? columnIndex : this . props . scrollToColumn
408+ const scrollToRow = rowIndex >= 0 ? rowIndex : this . props . scrollToRow
409+ const offsetProps = {
410+ ...this . props ,
411+ scrollToColumn,
412+ scrollToRow,
413+ scrollToAlignment
414+ }
415+
416+ return {
417+ scrollLeft : this . _getCalculatedScrollLeft ( offsetProps ) ,
418+ scrollTop : this . _getCalculatedScrollTop ( offsetProps )
419+ }
420+ }
421+
390422 componentDidMount ( ) {
391423 const { getScrollbarSize, scrollLeft, scrollToColumn, scrollTop, scrollToRow } = this . props
392424
@@ -1006,7 +1038,7 @@ export default class Grid extends PureComponent {
10061038 return this . _wrapPropertyGetter ( size )
10071039 }
10081040
1009- _updateScrollLeftForScrollToColumn ( props = this . props , state = this . state ) {
1041+ _getCalculatedScrollLeft ( props = this . props , state = this . state ) {
10101042 const { columnCount, height, scrollToAlignment, scrollToColumn, width } = props
10111043 const { scrollLeft } = state
10121044
@@ -1015,22 +1047,27 @@ export default class Grid extends PureComponent {
10151047 const totalRowsHeight = this . _rowSizeAndPositionManager . getTotalSize ( )
10161048 const scrollBarSize = totalRowsHeight > height ? this . _scrollbarSize : 0
10171049
1018- const calculatedScrollLeft = this . _columnSizeAndPositionManager . getUpdatedOffsetForIndex ( {
1050+ return this . _columnSizeAndPositionManager . getUpdatedOffsetForIndex ( {
10191051 align : scrollToAlignment ,
10201052 containerSize : width - scrollBarSize ,
10211053 currentOffset : scrollLeft ,
10221054 targetIndex
10231055 } )
1056+ }
1057+ }
10241058
1025- if ( scrollLeft !== calculatedScrollLeft ) {
1026- this . _setScrollPosition ( {
1027- scrollLeft : calculatedScrollLeft
1028- } )
1029- }
1059+ _updateScrollLeftForScrollToColumn ( props = this . props , state = this . state ) {
1060+ const { scrollLeft } = state
1061+ const calculatedScrollLeft = this . _getCalculatedScrollLeft ( props , state )
1062+
1063+ if ( calculatedScrollLeft >= 0 && scrollLeft !== calculatedScrollLeft ) {
1064+ this . _setScrollPosition ( {
1065+ scrollLeft : calculatedScrollLeft
1066+ } )
10301067 }
10311068 }
10321069
1033- _updateScrollTopForScrollToRow ( props = this . props , state = this . state ) {
1070+ _getCalculatedScrollTop ( props = this . props , state = this . state ) {
10341071 const { height, rowCount, scrollToAlignment, scrollToRow, width } = props
10351072 const { scrollTop } = state
10361073
@@ -1039,18 +1076,23 @@ export default class Grid extends PureComponent {
10391076 const totalColumnsWidth = this . _columnSizeAndPositionManager . getTotalSize ( )
10401077 const scrollBarSize = totalColumnsWidth > width ? this . _scrollbarSize : 0
10411078
1042- const calculatedScrollTop = this . _rowSizeAndPositionManager . getUpdatedOffsetForIndex ( {
1079+ return this . _rowSizeAndPositionManager . getUpdatedOffsetForIndex ( {
10431080 align : scrollToAlignment ,
10441081 containerSize : height - scrollBarSize ,
10451082 currentOffset : scrollTop ,
10461083 targetIndex
10471084 } )
1085+ }
1086+ }
10481087
1049- if ( scrollTop !== calculatedScrollTop ) {
1050- this . _setScrollPosition ( {
1051- scrollTop : calculatedScrollTop
1052- } )
1053- }
1088+ _updateScrollTopForScrollToRow ( props = this . props , state = this . state ) {
1089+ const { scrollTop } = state
1090+ const calculatedScrollTop = this . _getCalculatedScrollTop ( props , state )
1091+
1092+ if ( calculatedScrollTop >= 0 && scrollTop !== calculatedScrollTop ) {
1093+ this . _setScrollPosition ( {
1094+ scrollTop : calculatedScrollTop
1095+ } )
10541096 }
10551097 }
10561098
0 commit comments