react-native-expandable-section-list icon indicating copy to clipboard operation
react-native-expandable-section-list copied to clipboard

how to prevent expandablelist closing when click on any button.

Open ZeroCool00 opened this issue 6 years ago • 2 comments

In my app i have button in toolbar. when i click that button expandable view close.. i dont see any relation between my button and expandable list, still its react to my button click, why?

ZeroCool00 avatar Jun 02 '18 05:06 ZeroCool00

I am having this issue as well. How can we solve this. Is this a bug or a design choice? How do we get around this?

hirani89 avatar Dec 21 '18 02:12 hirani89

I solved this. This can happen if you change state in the button onPress function. What you need to do is the following:

  1. Add an array to hold ids of open sections in the state. (mine is called open)
this.state = {
      list: [],
      open: []
    };
  1. When configuring ExpandableList, add the openOptions prop and assign the above state to it.
openOptions = {this.state.open}
  1. At the end of your button.onPress, add the following
this.setState({'open':[sectionId]});

In my scenario, I only need one section expanded. and this works for me. If you need to keep multiple sections open, add multiple section ids to the open array.

hirani89 avatar Jan 07 '19 03:01 hirani89