Skip to content

Expose more props for added flexability #157

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

Merged
merged 6 commits into from
Nov 26, 2019
Merged
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
45 changes: 38 additions & 7 deletions src/SortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export default class SortableList extends Component {
showsHorizontalScrollIndicator: PropTypes.bool,
refreshControl: PropTypes.element,
autoscrollAreaSize: PropTypes.number,
snapToAlignment: PropTypes.string,
rowActivationTime: PropTypes.number,
manuallyActivateRows: PropTypes.bool,
scrollEventThrottle: PropTypes.number,
decelerationRate: PropTypes.oneOf([PropTypes.string, PropTypes.number]),
pagingEnabled: PropTypes.bool,
nestedScrollEnabled: PropTypes.bool,
disableIntervalMomentum: PropTypes.bool,

Expand All @@ -39,15 +43,21 @@ export default class SortableList extends Component {
onChangeOrder: PropTypes.func,
onActivateRow: PropTypes.func,
onReleaseRow: PropTypes.func,
onScroll: PropTypes.func,
};

static defaultProps = {
sortingEnabled: true,
scrollEnabled: true,
autoscrollAreaSize: 60,
snapToAlignment: 'start',
manuallyActivateRows: false,
showsVerticalScrollIndicator: true,
showsHorizontalScrollIndicator: true
showsHorizontalScrollIndicator: true,
scrollEventThrottle: 2,
decelerationRate: 'normal',
pagingEnabled: false,
onScroll: () => {}
}

/**
Expand Down Expand Up @@ -134,12 +144,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}) {
Expand Down Expand Up @@ -194,7 +207,20 @@ export default class SortableList extends Component {
}

render() {
let {contentContainerStyle, innerContainerStyle, horizontal, style, showsVerticalScrollIndicator, showsHorizontalScrollIndicator, nestedScrollEnabled, disableIntervalMomentum} = this.props;
let {
contentContainerStyle,
innerContainerStyle,
horizontal,
style,
showsVerticalScrollIndicator,
showsHorizontalScrollIndicator,
snapToAlignment,
scrollEventThrottle,
decelerationRate,
pagingEnabled,
nestedScrollEnabled,
disableIntervalMomentum,
} = this.props;
const {animated, contentHeight, contentWidth, scrollEnabled} = this.state;
const containerStyle = StyleSheet.flatten([style, {opacity: Number(animated)}])
innerContainerStyle = [
Expand All @@ -219,11 +245,15 @@ 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}
onScroll={this._onScroll}>
snapToAlignment={snapToAlignment}
onScroll={this._onScroll}
>
{this._renderHeader()}
<View style={innerContainerStyle}>
{this._renderRows()}
Expand Down Expand Up @@ -625,8 +655,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) => {
Expand Down