I have a ScrollView
which content doesn't necessarily exceeds it's size. Let's say it's a form where, upon errors, it expands to add error messages and then it exceeds the ScrollView
size and thus is why I'm using that scroll.
The thing is that I want the content to always be at least of the same size of the ScrollView. I'm aware of the minHeight
property, but the only way I found to use it is re-rendering, which I'd like to avoid.
I'm using redux for state management and this is what I have
<ScrollView
contentContainerStyle={[ownStyles.container, {minHeight: this.props.scrollHeight}]}
style={this.props.style}
showsVerticalScrollIndicator={false}
onLayout={(event) => {
scrollHeight = event.nativeEvent.layout.height;
this.props.setScrollContentHeight(scrollHeight);
}}
>
Where the this.props.setScrollContentHeight
triggers an action which enters the height on the state, and this.props.scrollHeight
is said height. So that after the first render where the onLayout function is triggered, the state is updated with the ScrollView's height
, which I then assign as minHeight
to its content.
If I set the content's style to flex: 1
then the ScrollView won't scroll.
Can you think of a way to avoid that second render for performance purposes?
Thank you!
height: 100%;
doesn't do the job? – Brandiebrandise