Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll View inside view not working react native

Here I am trying a simple code but the scroll view is not working if kept inside another view. Code is like this:

  return(
  <View>
    <Toolbar title={this.props.title}>
    </Toolbar>

    <ScrollView>

      <HomeScreenTop />
      <HomeScreenBottom navigator={navigator}/>

      </ScrollView>

  </View>
 );

But if scroll view kept as parent view it works perfectly. Code is as below:

  return(
  <ScrollView>
    <Toolbar title={this.props.title}>
    </Toolbar>

      <HomeScreenTop />
      <HomeScreenBottom navigator={navigator}/>

  </ScrollView>
 );

Now the problem is I don't want my toolbar to scroll up and down, I just want the contents below the toolbar to move. How can I achieve that?

And next question: Is scroll view has to be parent view to be returned to work?

like image 770
Riten Avatar asked Jul 01 '16 05:07

Riten


People also ask

Why scroll is not working in React Native?

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.

How do I use scroll view in React Native?

How to set ScrollView horizontal in React Native. To set the ScrollView as Horizontal in React Native, use the ScrollView's prop as Horizontal = { true } . This makes this scroll view in a Horizontal format. If you want to make this scroll view in the vertical format, don't add this prop, and you are good to go.

How do I make my screen scrollable in React Native?

well its pretty simple, just warp your components in <ScrollView> ... </ScrollView> and style it as per your need. if height of components together exceeds for <ScrollView> , it becomes scrollable.

How do you scroll horizontally React Native?

In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).


3 Answers

Use the property flexGrow in the style, flex didnt worked for me.

 <ScrollView contentContainerStyle={{ flexGrow: 1 }}>     ... </ScrollView> 
like image 161
Led Machine Avatar answered Sep 19 '22 18:09

Led Machine


you should wrap toolbar in view like this:

<View><Toolbar/></View>

Wrap those component which you want to scroll inside scrollview as:

<ScrollView>your expected components...</ScrollView>

And provide flex to root view as:

<View style={{flex:1}}>

Finally your code will run as you expected.

like image 22
Chiranjhivi Ghimire Avatar answered Sep 17 '22 18:09

Chiranjhivi Ghimire


Top <View> must has style flex:1, and also <ScrollView> has too

like image 23
Stephen Kingsley Avatar answered Sep 21 '22 18:09

Stephen Kingsley