From 4882fe3387992de1eafac88fdfe889f6ca0ff5a9 Mon Sep 17 00:00:00 2001 From: David Pett Date: Thu, 15 Feb 2018 10:13:42 -0600 Subject: [PATCH 1/5] accept onScroll prop --- src/SortableList.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SortableList.js b/src/SortableList.js index 3d3ff9f..7c003cc 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -37,6 +37,7 @@ export default class SortableList extends Component { onChangeOrder: PropTypes.func, onActivateRow: PropTypes.func, onReleaseRow: PropTypes.func, + onScroll: PropTypes.func, }; static defaultProps = { @@ -45,7 +46,8 @@ export default class SortableList extends Component { autoscrollAreaSize: 60, manuallyActivateRows: false, showsVerticalScrollIndicator: true, - showsHorizontalScrollIndicator: true + showsHorizontalScrollIndicator: true, + onScroll: () => {} } /** @@ -621,8 +623,9 @@ export default class SortableList extends Component { } }; - _onScroll = ({nativeEvent: {contentOffset}}) => { - this._contentOffset = contentOffset; + _onScroll = (e) => { + this._contentOffset = e.nativeEvent.contentOffset; + this.props.onScroll(e) }; _onRefContainer = (component) => { From 96cd9f54074cf3776ad3847bdbe687340a7ce4f9 Mon Sep 17 00:00:00 2001 From: David Pett Date: Thu, 15 Feb 2018 12:34:26 -0600 Subject: [PATCH 2/5] snap --- src/SortableList.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SortableList.js b/src/SortableList.js index 7c003cc..3ba26e3 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -27,6 +27,7 @@ export default class SortableList extends Component { showsHorizontalScrollIndicator: PropTypes.bool, refreshControl: PropTypes.element, autoscrollAreaSize: PropTypes.number, + snapToAlignment: PropTypes.string, rowActivationTime: PropTypes.number, manuallyActivateRows: PropTypes.bool, @@ -44,6 +45,7 @@ export default class SortableList extends Component { sortingEnabled: true, scrollEnabled: true, autoscrollAreaSize: 60, + snapToAlignment: 'start', manuallyActivateRows: false, showsVerticalScrollIndicator: true, showsHorizontalScrollIndicator: true, @@ -194,7 +196,7 @@ export default class SortableList extends Component { } render() { - let {contentContainerStyle, innerContainerStyle, horizontal, style, showsVerticalScrollIndicator, showsHorizontalScrollIndicator} = this.props; + let {contentContainerStyle, innerContainerStyle, horizontal, style, showsVerticalScrollIndicator, showsHorizontalScrollIndicator, snapToAlignment} = this.props; const {animated, contentHeight, contentWidth, scrollEnabled} = this.state; const containerStyle = StyleSheet.flatten([style, {opacity: Number(animated)}]) innerContainerStyle = [ @@ -221,7 +223,9 @@ export default class SortableList extends Component { scrollEnabled={scrollEnabled} showsHorizontalScrollIndicator={showsHorizontalScrollIndicator} showsVerticalScrollIndicator={showsVerticalScrollIndicator} - onScroll={this._onScroll}> + snapToAlignment={snapToAlignment} + onScroll={this._onScroll} + > {this._renderHeader()} {this._renderRows()} From 4c776158bcbfa064809eeea69f291c5281dd8484 Mon Sep 17 00:00:00 2001 From: David Pett Date: Thu, 15 Feb 2018 13:08:52 -0600 Subject: [PATCH 3/5] added scrollEnabled update prop --- src/SortableList.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SortableList.js b/src/SortableList.js index 3ba26e3..0f9ab3b 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -136,12 +136,15 @@ export default class SortableList extends Component { } componentDidUpdate(prevProps, prevState) { - const {data} = this.state; + const {data, scrollEnabled} = this.state; const {data: prevData} = prevState; if (data && prevData && !shallowEqual(data, prevData)) { this._onUpdateLayouts(); } + if (prevProps.scrollEnabled !== scrollEnabled) { + this.setState({scrollEnabled: prevProps.scrollEnabled}) + } } scrollBy({dx = 0, dy = 0, animated = false}) { From 51d5c28cd859a77ecc3b42cc2c5ce5d13b2bfee1 Mon Sep 17 00:00:00 2001 From: Zachary Mayry Date: Mon, 29 Jul 2019 21:07:44 -0500 Subject: [PATCH 4/5] fix paging --- src/SortableList.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/SortableList.js b/src/SortableList.js index 0f9ab3b..969f3f9 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -49,6 +49,9 @@ export default class SortableList extends Component { manuallyActivateRows: false, showsVerticalScrollIndicator: true, showsHorizontalScrollIndicator: true, + scrollEventThrottle: 2, + decelerationRate: 'normal', + pagingEnabled: false, onScroll: () => {} } @@ -199,7 +202,18 @@ export default class SortableList extends Component { } render() { - let {contentContainerStyle, innerContainerStyle, horizontal, style, showsVerticalScrollIndicator, showsHorizontalScrollIndicator, snapToAlignment} = this.props; + let { + contentContainerStyle, + innerContainerStyle, + horizontal, + style, + showsVerticalScrollIndicator, + showsHorizontalScrollIndicator, + snapToAlignment, + scrollEventThrottle, + decelerationRate, + pagingEnabled, + } = this.props; const {animated, contentHeight, contentWidth, scrollEnabled} = this.state; const containerStyle = StyleSheet.flatten([style, {opacity: Number(animated)}]) innerContainerStyle = [ @@ -222,7 +236,9 @@ export default class SortableList extends Component { ref={this._onRefScrollView} horizontal={horizontal} contentContainerStyle={contentContainerStyle} - scrollEventThrottle={2} + scrollEventThrottle={scrollEventThrottle} + pagingEnabled={pagingEnabled} + decelerationRate={decelerationRate} scrollEnabled={scrollEnabled} showsHorizontalScrollIndicator={showsHorizontalScrollIndicator} showsVerticalScrollIndicator={showsVerticalScrollIndicator} From a6a05852a9e748d757f48474f3ff2c069621b784 Mon Sep 17 00:00:00 2001 From: Zachary Mayry Date: Mon, 29 Jul 2019 21:37:32 -0500 Subject: [PATCH 5/5] fix propTypes --- src/SortableList.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SortableList.js b/src/SortableList.js index 969f3f9..bf39bcb 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -30,6 +30,9 @@ export default class SortableList extends Component { snapToAlignment: PropTypes.string, rowActivationTime: PropTypes.number, manuallyActivateRows: PropTypes.bool, + scrollEventThrottle: PropTypes.number, + decelerationRate: PropTypes.oneOf([PropTypes.string, PropTypes.number]), + pagingEnabled: PropTypes.bool, renderRow: PropTypes.func.isRequired, renderHeader: PropTypes.func,