I'm trying to run flex on a ScrollView
, and as long as the ScrollView has flex: 1
the scroll inside does not work. here is the expo fiddle (that you can run this code and play with) https://snack.expo.io/SySerKNp-
note that if you remove the flex: 1
from the ScrollView
it does let scroll but then you lose the flex power ( the ability to let the red container down to push up the upper box (the ScrollView) ) so I must have a flex there.
p.s - I'm working only on android, and I haven't tested it on iPhone( I don't mind the result there )
any idea what am I missing ? why the ScrollView
won't function right when it has a flex: 1
? thanks !
So when you apply flex: 1 to contentContainer it takes full height of ScrollView whose height is also flex: 1 as its parent View . Show activity on this post. The best thing to do is to wrap your ScrollView in a View and control that view with flex, your scroll view will follow.
To fix ScrollView Not scrolling with React Native, we wrap the content of the ScrollView with the ScrollView. to wrap ScrollView around the Text components that we render inside. As a result, we should see text inside and we can scroll up and down.
In Android, a ScrollView is a view group that is used to make vertically scrollable views.
Description. SafeAreaView is dynamic, if the first element on a screen is a ScrollView , and has children SafeAreaView s, when the user scrolls down, the SafeAreaView reduces in height because it's not touching the safe area anymore, which in contrast scrolls the content back up.
Try using flexGrow: 1 instead of flex: 1 in scrollView content container style as follows.
<ScrollView contentContainerStyle={{ flexGrow: 1, borderColor: 'green', borderWidth: 5 }}> <View style={styles.box1} /> <View style={styles.box2} /> <View style={styles.box1} /> </ScrollView>
https://snack.expo.io/HkkEVoh6Z
I believe your problem is that you are telling the ScrollView to occupy all available space with flex=1 but the thing is that ScrollView works differently. It automatically renders all its children so it does work different with flex. That is the difference against a normal ListView or FlatList which have better performance.
I believe this snack solves that issue: https://snack.expo.io/SkxN9GOT-
Basically, I am getting the height of the device and setting the ScrollView with a fixed height, based on (screenHeight - the current height of the red box).
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