From 06d9f984dfc15a9ff5203feeaad43045a8cb2626 Mon Sep 17 00:00:00 2001 From: Sumner Warren <sumner_warren@brown.edu> Date: Tue, 16 Jun 2020 17:07:35 -0400 Subject: [PATCH 1/5] Fix proptype for decelerationRate --- src/SortableList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SortableList.js b/src/SortableList.js index 78cd576..2f0e3a3 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -32,7 +32,7 @@ export default class SortableList extends Component { manuallyActivateRows: PropTypes.bool, keyboardShouldPersistTaps: PropTypes.oneOf(['never', 'always', 'handled']), scrollEventThrottle: PropTypes.number, - decelerationRate: PropTypes.oneOf([PropTypes.string, PropTypes.number]), + decelerationRate: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), pagingEnabled: PropTypes.bool, nestedScrollEnabled: PropTypes.bool, disableIntervalMomentum: PropTypes.bool, From 8fac14be37752affc83c3fbff1653ed2a6e78b01 Mon Sep 17 00:00:00 2001 From: Sumner Warren <sumner_warren@brown.edu> Date: Tue, 16 Jun 2020 17:28:05 -0400 Subject: [PATCH 2/5] Fix sorting on android --- src/SortableList.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SortableList.js b/src/SortableList.js index 78cd576..4287952 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -152,9 +152,11 @@ export default class SortableList extends Component { if (data && prevData && !shallowEqual(data, prevData)) { this._onUpdateLayouts(); } - if (prevProps.scrollEnabled !== scrollEnabled) { - this.setState({scrollEnabled: prevProps.scrollEnabled}) - } + + // See https://github.com/gitim/react-native-sortable-list/issues/188 + // if (prevProps.scrollEnabled !== scrollEnabled) { + // this.setState({scrollEnabled: prevProps.scrollEnabled}); + // } } scrollBy({dx = 0, dy = 0, animated = false}) { From e20d29943a82405a57f85f2f6f2c8e92e07933f7 Mon Sep 17 00:00:00 2001 From: thanhlam2410 <thanhlam24101991@gmail.com> Date: Wed, 17 Jun 2020 12:13:38 +0700 Subject: [PATCH 3/5] update deprecated lifecycle --- src/Row.js | 11 ++++++----- src/SortableList.js | 21 ++++++++------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Row.js b/src/Row.js index 32718a8..a9b46f8 100644 --- a/src/Row.js +++ b/src/Row.js @@ -142,10 +142,11 @@ export default class Row extends Component { }, }); - componentWillReceiveProps(nextProps) { - if (!this._active && !shallowEqual(this._location, nextProps.location)) { - const animated = !this._active && nextProps.animated; - this._relocate(nextProps.location, animated); + componentDidUpdate() { + const {animated, location} = this.props; + + if (!this._active && !shallowEqual(this._location, location)) { + this._relocate(location, !this._active && animated); } } @@ -259,4 +260,4 @@ const styles = StyleSheet.create({ left: 0, right: 0, }, -}); +}); \ No newline at end of file diff --git a/src/SortableList.js b/src/SortableList.js index 73d3396..d7f968e 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -2,7 +2,7 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {ScrollView, View, StyleSheet, Platform, RefreshControl, ViewPropTypes} from 'react-native'; import {shallowEqual, swapArrayElements} from './utils'; -import Row from './Row'; +import Row from './row'; const AUTOSCROLL_INTERVAL = 100; const ZINDEX = Platform.OS === 'ios' ? 'zIndex' : 'elevation'; @@ -88,7 +88,7 @@ export default class SortableList extends Component { scrollEnabled: this.props.scrollEnabled }; - componentWillMount() { + componentDidMount() { this.state.order.forEach((key) => { this._rowsLayouts[key] = new Promise((resolve) => { this._resolveRowLayout[key] = resolve; @@ -100,20 +100,20 @@ export default class SortableList extends Component { this._resolveHeaderLayout = resolve; }); } + if (this.props.renderFooter && !this.props.horizontal) { this._footerLayout = new Promise((resolve) => { this._resolveFooterLayout = resolve; }); } - } - componentDidMount() { this._onUpdateLayouts(); } - componentWillReceiveProps(nextProps) { - const {data, order} = this.state; - let {data: nextData, order: nextOrder} = nextProps; + componentDidUpdate(prevProps, prevState) { + const {data, order, scrollEnabled} = this.state; + let {data: nextData, order: nextOrder} = this.props; + const {data: prevData} = prevState; if (data && nextData && !shallowEqual(data, nextData)) { nextOrder = nextOrder || Object.keys(nextData) @@ -143,11 +143,6 @@ export default class SortableList extends Component { } else if (order && nextOrder && !shallowEqual(order, nextOrder)) { this.setState({order: nextOrder}); } - } - - componentDidUpdate(prevProps, prevState) { - const {data, scrollEnabled} = this.state; - const {data: prevData} = prevState; if (data && prevData && !shallowEqual(data, prevData)) { this._onUpdateLayouts(); @@ -688,4 +683,4 @@ const styles = StyleSheet.create({ flex: 1, zIndex: 1, }, -}); +}); \ No newline at end of file From b858768f1e2d8f6d349fd63e8af08c524edc0b28 Mon Sep 17 00:00:00 2001 From: Sumner Warren <sumner_warren@brown.edu> Date: Wed, 17 Jun 2020 09:04:48 -0400 Subject: [PATCH 4/5] Remove unnecessary changes --- src/Row.js | 2 +- src/SortableList.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Row.js b/src/Row.js index a9b46f8..b11caa1 100644 --- a/src/Row.js +++ b/src/Row.js @@ -260,4 +260,4 @@ const styles = StyleSheet.create({ left: 0, right: 0, }, -}); \ No newline at end of file +}); diff --git a/src/SortableList.js b/src/SortableList.js index d7f968e..8809be8 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -2,7 +2,7 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {ScrollView, View, StyleSheet, Platform, RefreshControl, ViewPropTypes} from 'react-native'; import {shallowEqual, swapArrayElements} from './utils'; -import Row from './row'; +import Row from './Row'; const AUTOSCROLL_INTERVAL = 100; const ZINDEX = Platform.OS === 'ios' ? 'zIndex' : 'elevation'; @@ -683,4 +683,4 @@ const styles = StyleSheet.create({ flex: 1, zIndex: 1, }, -}); \ No newline at end of file +}); From 59d41faa89d6e10113557a2d6c0bf0e2ec9075e0 Mon Sep 17 00:00:00 2001 From: Sumner Warren <sumner_warren@brown.edu> Date: Thu, 18 Jun 2020 17:23:14 -0400 Subject: [PATCH 5/5] Add optional prop for computing row disabled state --- src/SortableList.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/SortableList.js b/src/SortableList.js index 8809be8..3d1b169 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -45,6 +45,8 @@ export default class SortableList extends Component { onActivateRow: PropTypes.func, onReleaseRow: PropTypes.func, onScroll: PropTypes.func, + + rowIsDisabled: PropTypes.func, }; static defaultProps = { @@ -289,6 +291,14 @@ export default class SortableList extends Component { const active = activeRowKey === key; const released = releasedRowKey === key; + const disabled = this.props.rowIsDisabled + ? this.props.rowIsDisabled({ + key, + data: data[key], + active, + index, + }) + : !sortingEnabled; if (active || released) { style[ZINDEX] = 100; @@ -301,7 +311,7 @@ export default class SortableList extends Component { horizontal={horizontal} activationTime={rowActivationTime} animated={animated && !active} - disabled={!sortingEnabled} + disabled={disabled} style={style} location={location} onLayout={!rowsLayouts ? this._onLayoutRow.bind(this, key) : null} @@ -313,7 +323,7 @@ export default class SortableList extends Component { {renderRow({ key, data: data[key], - disabled: !sortingEnabled, + disabled, active, index, })}