How to close all "swiped" rows after an action? I'm trying to do this using refs, but I'm stucked
Hey @lucasfjportela, this wasn't possible before but I've added a prop called closeOnRowOpen that will allow rows to stay open all the time. It is available in the latest version. Here's an example of how to achieve what you want to do:
class App extends Component {
constructor(props) {
super(props);
this.openRowRefs = [];
}
onRowDidOpen = (rowKey, rowMap) => {
this.openRowRefs.push(rowMap[rowKey]);
}
closeAllOpenRows() {
this.openRowRefs.forEach(ref => {
ref.closeRow && ref.closeRow();
});
}
render() {
return (
<SwipeListView
onRowDidOpen={this.onRowDidOpen}
closeOnRowOpen={false}
Going to close this but please reopen if you still have problems, thanks!
I'd found a workaround through using refs, but it's a really nice official solution! Thanks for the support! @jemise111
<SwipeListView
useFlatList
data={myData}
renderItem={(data, rowMap) => <ReactComponent [...] />}
onRowDidOpen={(foo, bar) => console.log("on row did open", foo, bar)}
closeOnRowOpen={false}
renderHiddenItem={({ item }) => <UnderComponent />}
keyExtractor={(item) => item.id.toString()}
/>
Running something like this crashes my app. If I change onRowDidOpen={(foo, bar) => console.log("on row did open", foo, bar)} to onRowDidOpen={(foo) => console.log("on row did open", foo)}, it does not crash. But if I remove bar, then I don't get rowMap and therefore can't use this solution, correct?
@BrendanBerkley I believe this has happened to me too. rowMap is actually a very large object and trying to log it to the console myData.length number of times is probably what's crashing your app.
You can try onRowDidOpen={(foo, bar) => console.log("on row did open", foo, !!bar)} to verify that bar is there. If so then the solution I posted above should work.
Hope that helps!
It does! Thank you for your prompt response.
class App extends Component {
constructor(props) {
super(props);
this.openRowRefs = [];
}
onRowDidOpen = (rowKey, rowMap) => {
this.openRowRefs.push(rowMap[rowKey]);
}
closeAllOpenRows() {
this.openRowRefs.forEach(ref => {
ref.closeRow && ref.closeRow();
});
}
render() {
return (
<SwipeListView
onRowDidOpen={this.onRowDidOpen}
closeOnRowOpen={false}
I am trying to close all right opened button at once using your code, but failed!
could u let me know the solution?
@Native0629 I don't see where you are invoking closeAllOpenRows?
Most helpful comment
Hey @lucasfjportela, this wasn't possible before but I've added a prop called
closeOnRowOpenthat will allow rows to stay open all the time. It is available in the latest version. Here's an example of how to achieve what you want to do:Going to close this but please reopen if you still have problems, thanks!