React-native-swipe-list-view: I am using <SwipeRow> on hidden row click I want to close the swipeRow, but only last index is getting closed

Created on 14 Sep 2017  路  1Comment  路  Source: jemise111/react-native-swipe-list-view

If you are using the standalone you can just keep a ref to the component and call closeRow() on that ref.

could you please give the example for the above sentence.

this is how I am using now (Pseudo code).

RenderItem=>
<SwipeRow  ref={(SwipeRow) => { this.refSwipeRow = SwipeRow; }} >
   <TouchableOpacity onPress={this.refSwipeRow.closeRow()}> 
        <Text> Hello </Text>
  </TouchableOpacity>

Most helpful comment

Hey @sandeep-t2s this is because as each row is rendered you are setting this.refSwipeRow to the newly rendered row. Therefore each new row over writes the previous one and you only keep a reference to the last rendered row.

In order to close a specific row you'll have to keep track of the ref to each SwipeRow, likely in an object.

For example let's say you just have a list of data, and each item has its own id. You could do something like this:

constructor() {
  this.rows = {};
}
...
renderItem={({item}) => {
  <SwipeRow
     ref={ref => { this.rows[item.id] = ref }}
  >
    <TouchableHighlight onPress={() => this.rows[item.id].closeRow()} />
  </SwipeRow>
}

Hope that helps! Going to close this as I do not believe it is an issue with the library itself. Please let me know and re-open if you're still having problems, thanks!

>All comments

Hey @sandeep-t2s this is because as each row is rendered you are setting this.refSwipeRow to the newly rendered row. Therefore each new row over writes the previous one and you only keep a reference to the last rendered row.

In order to close a specific row you'll have to keep track of the ref to each SwipeRow, likely in an object.

For example let's say you just have a list of data, and each item has its own id. You could do something like this:

constructor() {
  this.rows = {};
}
...
renderItem={({item}) => {
  <SwipeRow
     ref={ref => { this.rows[item.id] = ref }}
  >
    <TouchableHighlight onPress={() => this.rows[item.id].closeRow()} />
  </SwipeRow>
}

Hope that helps! Going to close this as I do not believe it is an issue with the library itself. Please let me know and re-open if you're still having problems, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Elijen picture Elijen  路  5Comments

jjhesk picture jjhesk  路  3Comments

Slapbox picture Slapbox  路  6Comments

m-ruhl picture m-ruhl  路  6Comments

2JJ1 picture 2JJ1  路  5Comments