oblador / react-native-collapsible

Animated collapsible component for React Native, good for accordions, toggles etc
MIT License
2.43k stars 455 forks source link

Parent Collapsible does not dynamically calculate height for any nested Collapsible(s) #391

Open havi-b opened 3 years ago

havi-b commented 3 years ago

I currently have a collapsible view with style { flex: 1} and another collapsible within it. When the inner collapsible is expanded the height of the outer collapsible view does not increase/adjust.

mwegener-com commented 2 years ago

same problem, do you have any solution?

oussamanm commented 2 years ago

💯 i solved that by Calculate the Height the Child view of Collapsible, and create a new state that will hold that height to use it in attribute height of Collapsible Component.

const [calculatedHieght, setCalculatedHieght] = useState();

declare an event that will Calculate the hieght :

 const onLayout=(event)=> {
        const {x, y, height, width} = event.nativeEvent.layout;
        console.log("~~~~~~ height = ", height);
        setCalculatedHieght(height + 20)
 }

use our state that hold the calculated hieght :

<Collapsible collapsed={!variantes[0].collapsed} style={{width: '100%', height: calculatedHieght}} >

and also set onLayout event in the child view of Collapsible component :

<View style={{width: '100%', padding: 7,}} onLayout={onLayout}>