react-native-expandable-section-list
react-native-expandable-section-list copied to clipboard
how to prevent expandablelist closing when click on any button.
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?
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?
I solved this. This can happen if you change state in the button onPress function. What you need to do is the following:
- Add an array to hold ids of open sections in the state. (mine is called open)
this.state = {
list: [],
open: []
};
- When configuring
ExpandableList
, add theopenOptions
prop and assign the above state to it.
openOptions = {this.state.open}
- 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.