React-native-swipe-list-view: Close all opened rows

Created on 18 Oct 2018  路  8Comments  路  Source: jemise111/react-native-swipe-list-view

How to close all "swiped" rows after an action? I'm trying to do this using refs, but I'm stucked

Most helpful comment

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!

All 8 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VitaliiK91 picture VitaliiK91  路  3Comments

benoitvallon picture benoitvallon  路  6Comments

grigy picture grigy  路  4Comments

Slapbox picture Slapbox  路  6Comments

jwilliamson-qb picture jwilliamson-qb  路  3Comments