Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make component stick to bottom in ScrollView but still alow other content to push it down

I have three views: one at the top, middle and bottom. The scroll view takes the whole screen. The problem is that now scroll view is not scrollable.

<ScrollView contentContainerStyle={{flex: 1, backgroundColor: '#00ff00', flexDirection: 'column', justifyContent: 'space-between'}}>   <View><SomeContent /></View>   <View><SomeContent /></View>   <View><SomeContent /></View> </ScrollView> 

If I remove flex: 1 scroll view takes about 50% of the screen. How do I make a scroll view with top, middle and bottom elements like on the image bellow.

Screenshot of an iPhone. The background of the screen is white. It has three boxes that are different shades of blue: one at the top, one in the middle, and one at bottom. The boxes are aligned to the left and there is a lot of white space between the boxes.

The bottom element should be at the bottom all the time but when the top two components' height is large they should push the bottom component down so I can use scroll view to move up/down.

like image 492
1110 Avatar asked May 05 '17 13:05

1110


People also ask

How do I align an item to the bottom in React Native?

To move the button to the bottom, we use justifyContent to lay out items in the main axis, with flex-end , which aligns the flex items at the end of the container.


1 Answers

Use flexGrow instead of flex. Example code is given bellow.

<ScrollView    contentContainerStyle={{    flexGrow: 1,    flexDirection: 'column',    justifyContent: 'space-between' }}>   <View style={{ width: 50, height: 1000, backgroundColor:'orange' }} />   <View style={{ width: 50, height: 50, backgroundColor:'black'}} />   <View style={{ width: 50, height: 50, backgroundColor:'blue'}} /> </ScrollView> 

Here is the screenshot

[1]

like image 68
Ijharul Islam Avatar answered Sep 28 '22 07:09

Ijharul Islam