diff --git a/src/Row.js b/src/Row.js index 32718a8..0376d8c 100644 --- a/src/Row.js +++ b/src/Row.js @@ -1,7 +1,7 @@ -import React, {Component, cloneElement} from 'react'; +import React, { Component, cloneElement } from 'react'; import PropTypes from 'prop-types'; -import {Animated, PanResponder, StyleSheet, ViewPropTypes} from 'react-native'; -import {shallowEqual} from './utils'; +import { Animated, PanResponder, StyleSheet, ViewPropTypes } from 'react-native'; +import { shallowEqual } from './utils'; export default class Row extends Component { static propTypes = { @@ -30,7 +30,7 @@ export default class Row extends Component { }; static defaultProps = { - location: {x: 0, y: 0}, + location: { x: 0, y: 0 }, activationTime: 200, }; @@ -96,7 +96,7 @@ export default class Row extends Component { const elementMove = this._mapGestureToMove(this._prevGestureState, gestureState); this.moveBy(elementMove); - this._prevGestureState = {...gestureState}; + this._prevGestureState = { ...gestureState }; if (this.props.onMove) { this.props.onMove(e, gestureState, this._nextLocation); @@ -151,11 +151,11 @@ export default class Row extends Component { shouldComponentUpdate(nextProps, nextState) { return this.props.disabled !== nextProps.disabled || - this.props.children !== nextProps.children || - !shallowEqual(this.props.style, nextProps.style); + this.props.children !== nextProps.children || + !shallowEqual(this.props.style, nextProps.style); } - moveBy({dx = 0, dy = 0, animated = false}) { + moveBy({ dx = 0, dy = 0, animated = false }) { this._nextLocation = { x: this._location.x + dx, y: this._location.y + dy, @@ -164,7 +164,7 @@ export default class Row extends Component { } render() { - const {children, style, horizontal} = this.props; + const { children, style, horizontal } = this.props; const rowStyle = [ style, styles.container, this._animatedLocation.getLayout(), horizontal ? styles.horizontalContainer : styles.verticalContainer, @@ -206,27 +206,29 @@ export default class Row extends Component { } _toggleActive = (e, gestureState) => { - const callback = this._active ? this.props.onRelease : this.props.onActivate; + if (!this.props.disabled) { + const callback = this._active ? this.props.onRelease : this.props.onActivate; - this._active = !this._active; + this._active = !this._active; - if (callback) { - callback(e, gestureState, this._location); + if (callback) { + callback(e, gestureState, this._location); + } } }; _mapGestureToMove(prevGestureState, gestureState) { return this.props.horizontal - ? {dx: gestureState.moveX - prevGestureState.moveX} - : {dy: gestureState.moveY - prevGestureState.moveY}; + ? { dx: gestureState.moveX - prevGestureState.moveX } + : { dy: gestureState.moveY - prevGestureState.moveY }; } _isDisabled() { - return this.props.disabled || - this._isAnimationRunning; - } + return this.props.disabled || + this._isAnimationRunning; + } - _isTouchInsideElement({nativeEvent}) { + _isTouchInsideElement({ nativeEvent }) { return this._layout && nativeEvent.locationX >= 0 && nativeEvent.locationX <= this._layout.width && @@ -239,11 +241,11 @@ export default class Row extends Component { }; _onLayout = (e) => { - this._layout = e.nativeEvent.layout; + this._layout = e.nativeEvent.layout; - if (this.props.onLayout) { - this.props.onLayout(e); - } + if (this.props.onLayout) { + this.props.onLayout(e); + } }; } diff --git a/src/SortableList.js b/src/SortableList.js index 78cd576..8eea855 100644 --- a/src/SortableList.js +++ b/src/SortableList.js @@ -223,6 +223,7 @@ export default class SortableList extends Component { nestedScrollEnabled, disableIntervalMomentum, keyboardShouldPersistTaps, + ...scrollViewProps } = this.props; const {animated, contentHeight, contentWidth, scrollEnabled} = this.state; const containerStyle = StyleSheet.flatten([style, {opacity: Number(animated)}]) @@ -242,6 +243,7 @@ export default class SortableList extends Component { return ( { @@ -629,17 +636,21 @@ export default class SortableList extends Component { _onReleaseRow = (rowKey) => { this._stopAutoScroll(); - this.setState(({activeRowKey}) => ({ - activeRowKey: null, - activeRowIndex: null, - releasedRowKey: activeRowKey, - scrollEnabled: this.props.scrollEnabled, - })); - - if (this.props.onReleaseRow) { - this.props.onReleaseRow(rowKey, this.state.order); - } - }; + this.setState(({ activeRowKey, activeRowIndex, order }) => { + if (this.props.onReleaseRow) { + this.props.onReleaseRow(rowKey, activeRowIndex); + } + if (this.props.onChangeOrderFinished) { + this.props.onChangeOrderFinished(order) + } + return ({ + activeRowKey: null, + activeRowIndex: null, + releasedRowKey: activeRowKey, + scrollEnabled: this.props.scrollEnabled, + }) + }); + } _onMoveRow = (e, gestureState, location) => { const prevMovingRowX = this._activeRowLocation.x;