Permalink
Browse files

Properly clear openRowID when a row is swiped to closed position.

Summary:
If a SwipeableRow does not have background color defined, QuickAction is rendered below the row. In such case, you can leverage openRowID defined in dataSource. For instance, one can render quickAction only for the open row. The openRowID, however, does not clear when the row is closed. It only clears when the ListView is scrolled. This is s small PR to fix address it.
Closes #11380

Differential Revision: D4500952

Pulled By: mkonicek

fbshipit-source-id: a965dfb45b77cc1669de405b627d13e2cee59420
  • Loading branch information...
cryptobiote authored and facebook-github-bot committed Feb 2, 2017
1 parent 5938e16 commit 2edd455c652a2b84dd9f4f4b1ee9de805171822a
@@ -196,6 +196,7 @@ class SwipeableListView extends React.Component {
maxSwipeDistance={this._getMaxSwipeDistance(rowData, sectionID, rowID)}
key={rowID}
onOpen={() => this._onOpen(rowData.id)}
onClose={() => this._onClose(rowData.id)}
onSwipeEnd={() => this._setListViewScrollable(true)}
onSwipeStart={() => this._setListViewScrollable(false)}
shouldBounceOnMount={shouldBounceOnMount}>
@@ -209,6 +210,12 @@ class SwipeableListView extends React.Component {
dataSource: this.state.dataSource.setOpenRowID(rowID),
});
}
_onClose(rowID: string): void {
this.setState({
dataSource: this.state.dataSource.setOpenRowID(null),
});
}
}
module.exports = SwipeableListView;
@@ -85,6 +85,7 @@ const SwipeableRow = React.createClass({
isOpen: PropTypes.bool,
maxSwipeDistance: PropTypes.number.isRequired,
onOpen: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
onSwipeEnd: PropTypes.func.isRequired,
onSwipeStart: PropTypes.func.isRequired,
// Should bounce the row on mount
@@ -120,6 +121,7 @@ const SwipeableRow = React.createClass({
isOpen: false,
maxSwipeDistance: 0,
onOpen: emptyFunction,
onClose: emptyFunction,
onSwipeEnd: emptyFunction,
onSwipeStart: emptyFunction,
swipeThreshold: 30,
@@ -369,6 +371,7 @@ const SwipeableRow = React.createClass({
this._animateToOpenPositionWith(gestureState.vx, horizontalDistance);
} else {
// Swiped right
this.props.onClose();
this._animateToClosedPosition();
}
} else {

0 comments on commit 2edd455

Please sign in to comment.