Skip to content

Added props forwarding for scrollview and row #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/Row.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -30,7 +30,7 @@ export default class Row extends Component {
};

static defaultProps = {
location: {x: 0, y: 0},
location: { x: 0, y: 0 },
activationTime: 200,
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 &&
Expand All @@ -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);
}
};
}

Expand Down
37 changes: 24 additions & 13 deletions src/SortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}])
Expand All @@ -242,6 +243,7 @@ export default class SortableList extends Component {
return (
<View style={containerStyle} ref={this._onRefContainer}>
<ScrollView
{...scrollViewProps}
nestedScrollEnabled={nestedScrollEnabled}
disableIntervalMomentum={disableIntervalMomentum}
refreshControl={refreshControl}
Expand Down Expand Up @@ -269,7 +271,7 @@ export default class SortableList extends Component {
}

_renderRows() {
const {horizontal, rowActivationTime, sortingEnabled, renderRow} = this.props;
const {horizontal, rowActivationTime, sortingEnabled, renderRow, rowProps} = this.props;
const {animated, order, data, activeRowKey, releasedRowKey, rowsLayouts} = this.state;


Expand Down Expand Up @@ -299,6 +301,7 @@ export default class SortableList extends Component {

return (
<Row
{...rowProps}
key={uniqueRowKey(key)}
ref={this._onRefRow.bind(this, key)}
horizontal={horizontal}
Expand Down Expand Up @@ -594,8 +597,12 @@ export default class SortableList extends Component {
this._autoScrollInterval = null;
}

_onLayoutRow(rowKey, {nativeEvent: {layout}}) {
_onLayoutRow(rowKey, e) {
const {nativeEvent: {layout}} = e;
this._resolveRowLayout[rowKey]({rowKey, layout});
if (this.props.onLayoutRow) {
this.props.onLayoutRow(rowKey, e)
}
}

_onLayoutHeader = ({nativeEvent: {layout}}) => {
Expand Down Expand Up @@ -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;
Expand Down