Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native ScrollView height issues

I would like to create a horizontal ScrollView, but I faced some issues. The ScrollView takes all the remaining space of my screen, but what I want is the ScrollView to only take the height of the biggest children. How can I achieve that?

I have tried to set a fixed height on the style, but that didn't work. Any help?

<ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.guessList}>
{guessList.map((guess, index) => (
    <NumberContainer style={styles.guessItem} key={guess}>#{guessList.length - index} {guess}</NumberContainer>
))}
const styles= StyleSheet.create({
guessList: {
    height: 70
},
guessItem: {
    marginRight: 5
}

});

like image 652
Daniel Chan Avatar asked Jun 12 '26 23:06

Daniel Chan


2 Answers

I just tried to add {flexGrow: 0} on the style of ScrollView and now it works. It's only taking the space enough for cotaining the children components.

like image 114
Daniel Chan Avatar answered Jun 15 '26 14:06

Daniel Chan


Like @Vignesh say, this should do the work

<ScrollView contentContainerStyle={{flexGrow: 1} ... >
like image 43
BloodyMonkey Avatar answered Jun 15 '26 13:06

BloodyMonkey