diff --git a/example/src/lists/CompareList.jsx b/example/src/lists/CompareList.jsx index cd85a17..d306c0b 100644 --- a/example/src/lists/CompareList.jsx +++ b/example/src/lists/CompareList.jsx @@ -1,3 +1,4 @@ +/* eslint-disable no-shadow */ import React from "react"; import { FlatList, diff --git a/lib/BigList.jsx b/lib/BigList.jsx index 27b4452..c0f07a9 100644 --- a/lib/BigList.jsx +++ b/lib/BigList.jsx @@ -242,6 +242,45 @@ class BigList extends PureComponent { return this.scrollTo(options); } + /** + * Scroll to item. + * @param {object} item + * @param {bool} animated + * @returns {bool} + */ + scrollToItem({ item, animated = false }) { + let index; + if (this.hasSections()) { + const coords = JSON.stringify( + this.map((a) => { + return a[0] + "|" + a[1]; + }), + ); + index = coords.indexOf(item[0] + "|" + item[1]) !== -1; + } else { + index = this.props.data.indexOf(item); + } + return this.scrollTo({ index, animated }); + } + + /** + * Scroll to offset. + * @param {number} offset + * @param {bool} animated + * @returns {bool} + */ + scrollToOffset({ offset, animated = false }) { + if (this.scrollView.current != null) { + this.scrollView.current.scrollTo({ + x: 0, + y: offset, + animated, + }); + return true; + } + return false; + } + /** * Scroll to top. * @param {bool} animated