I need to make SwipeRow close programmatically.
My use case (which may apply to many others):
onRowDidOpen triggers -> Perform action "e.g delete message" -> Close the swipe menu
^ Specific to SwipeRows with only one option rather than multiple buttons
If you get a reference to the SwipeRow using useRef() called myRef then you should be able to call myRef.current.combinedOnPress()
If you get a reference the old fashioned way I think it would be this.refs.myRef.combinedOnPress() or this.myRef.combinedOnPress()
EDIT: as suggested below, .closeRow() is a better option.
Another valid option would be .manuallySwipeRow(0)
Hey @2JJ1, @dcenatiempo's option might work. How about this:
onRowDidOpen = (rowKey, rowMap) => {
const row = rowMap[rowKey];
// do whatever actions you need to do here
row.closeRow();
};
render() {
<SwipeListView
data={this.state.listViewData}
onRowDidOpen={this.onRowDidOpen}
renderItem={data => (
<TouchableHighlight
onPress={() => console.log('You touched me')}
style={styles.rowFront}
underlayColor={'#AAA'}
>
...
</TouchableHighlight>
)}
renderHiddenItem={(data, rowMap) => (
<View style={styles.rowBack}>
@jemise111 Thank you for your reply, but I was looking for a solution with the SwipeRow component API
@2JJ1 oops! Missed that part. In that case how about just:
onRowDidOpen = () => {
// Do whatever actions are needed
this.swipeRowRef.closeRow();
}
render() {
return (
<SwipeRow
ref={ref => this.swipeRowRef = ref}
onRowDidOpen={this.onRowDidOpen}
leftOpenValue={75}
rightOpenValue={-75}
>
@2JJ1 oops! Missed that part. In that case how about just:
onRowDidOpen = () => { // Do whatever actions are needed this.swipeRowRef.closeRow(); }
it should be :
onRowDidOpen = () => {
if (this.swipeRowRef != null) this.swipeRowRef.closeRow();
};
Most helpful comment
@2JJ1 oops! Missed that part. In that case how about just: