Is it possible to have a layout which is wrapped with ScrollView
:
<ScrollView>
<View>dynamic height</View>
<View>flex with minHeight</View>
<View>static height</View>
</ScrollView>
and meets below prerequisites:
Height of the first View
is dynamic (depends on text length). Height of the third View
is static (always three buttons inside). Rest of the screen should be filled with View
with map, but the minimal height is set to 250.
Now the tricky part: if there is a lot of text in first View
, so that map doesn't fit, a scroll should appear. I couldn't achieve that. I was trying to give the map View
flex: 1
and minHeight: 250
, but it's not rendered at all.
Ok, I've found a way to fix it. In first render, I get screen height (Dimensions
) and height of first and third view (onLayout
). Then, I calculate the height of second view (screenHeight - view1 - view3 - naviagtionHeight
) and forceUpdate()
to re-render it.
Add contentContainerStyle={{flexGrow: 1}}
prop to ScrollView
and its children's flex:1
would work. So you don't need to calculate it manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With