React-native-swipe-list-view: Request: Close SwipeRow programmatically

Created on 22 Oct 2019  路  5Comments  路  Source: jemise111/react-native-swipe-list-view

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

Most helpful comment

@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}
    >

All 5 comments

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();
}; 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

baicuhaha picture baicuhaha  路  6Comments

mohitmishra22 picture mohitmishra22  路  6Comments

grigy picture grigy  路  4Comments

ramisalem picture ramisalem  路  5Comments

kyangy picture kyangy  路  3Comments