Skip to content

Support deleting data from the list & add support for keyboardShouldPersistTaps prop #149

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

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ npm i react-native-sortable-list --save
- **showsHorizontalScrollIndicator** (boolean) when false, the horizontal scroll indicator will not be visible. The default value is true.
- **sortingEnabled?** (boolean) when false, rows are not sortable. The default value is true.
- **scrollEnabled?** (boolean) when false, the content does not scrollable. The default value is true.
- **keyboardShouldPersistTaps** (string)<br />
Determines when the keyboard should stay visible after a tap.
- 'never' (the default), tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap.
- 'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps.
- 'handled', the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor.<br/>
- **manuallyActivateRows?** (bool) whether you intend to use the `toggleRowActive` method to activate a row or use the out of box solution.
- **autoscrollAreaSize?** (number) determines the height for vertical list and the width for horizontal list of the area at the begining and the end of the list that will trigger autoscrolling. Defaults to 60.<br />
- **rowActivationTime?** (number) determines time delay in ms before pressed row becomes active. Defaults to 200 ms.<br />
Expand Down
27 changes: 11 additions & 16 deletions src/SortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class SortableList extends Component {
autoscrollAreaSize: PropTypes.number,
rowActivationTime: PropTypes.number,
manuallyActivateRows: PropTypes.bool,
keyboardShouldPersistTaps: PropTypes.oneOf(['never', 'always', 'handled']),

renderRow: PropTypes.func.isRequired,
renderHeader: PropTypes.func,
Expand All @@ -42,6 +43,7 @@ export default class SortableList extends Component {
static defaultProps = {
sortingEnabled: true,
scrollEnabled: true,
keyboardShouldPersistTaps: 'never',
autoscrollAreaSize: 60,
manuallyActivateRows: false,
showsVerticalScrollIndicator: true,
Expand Down Expand Up @@ -111,21 +113,13 @@ export default class SortableList extends Component {
});
});

if (Object.keys(nextData).length > Object.keys(data).length) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be
if (Object.keys(nextData).length > Object.keys(data).length || Object.keys(nextData).length < Object.keys(data).length)

this.setState({
animated: false,
data: nextData,
containerLayout: null,
rowsLayouts: null,
order: nextOrder
});
} else {
this.setState({
data: nextData,
order: nextOrder
});
}

this.setState({
animated: false,
data: nextData,
containerLayout: null,
rowsLayouts: null,
order: nextOrder
});
} else if (order && nextOrder && !shallowEqual(order, nextOrder)) {
this.setState({order: nextOrder});
}
Expand Down Expand Up @@ -192,7 +186,7 @@ export default class SortableList extends Component {
}

render() {
let {contentContainerStyle, innerContainerStyle, horizontal, style, showsVerticalScrollIndicator, showsHorizontalScrollIndicator} = this.props;
let {contentContainerStyle, innerContainerStyle, horizontal, style, showsVerticalScrollIndicator, showsHorizontalScrollIndicator, keyboardShouldPersistTaps} = this.props;
const {animated, contentHeight, contentWidth, scrollEnabled} = this.state;
const containerStyle = StyleSheet.flatten([style, {opacity: Number(animated)}])
innerContainerStyle = [
Expand All @@ -217,6 +211,7 @@ export default class SortableList extends Component {
contentContainerStyle={contentContainerStyle}
scrollEventThrottle={2}
scrollEnabled={scrollEnabled}
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
showsHorizontalScrollIndicator={showsHorizontalScrollIndicator}
showsVerticalScrollIndicator={showsVerticalScrollIndicator}
onScroll={this._onScroll}>
Expand Down