React-Native, Scroll View Not Scrolling

React Native

React Native Problem Overview


When I wrap content like this example below, it scrolls Perfectly..

return(
    <ScrollView>
        <Text> TEST </Text>
        <Text> TEST </Text>
        <Text> TEST </Text>
        <Text> TEST </Text>
        ...
    </ScrollView>
);

However, whenever I wrap it in another View, It will not scroll.

return(
    <View>
        <ScrollView>
            <Text> TEST </Text>
            <Text> TEST </Text>
            <Text> TEST </Text>
            <Text> TEST </Text>
            ...    
        </SCrollView>
    </View>
);

Is there some sort of fix to this. I am trying to put a nav bar header above all of the content, couldn't really figure it out though.

React Native Solutions


Solution 1 - React Native

It's a typo:
Your closing ScrollView tag is: </SCrollView> rather than </ScrollView>. You also need to add a style to the View container, here's an example of what it should look like:

return(
  <View style={{flex: 1}}>
    <ScrollView>
      <Text> TEST </Text>
      <Text> TEST </Text>
      <Text> TEST </Text>
      <Text> TEST </Text>
      ...    
    </ScrollView>
  </View>
);

Solution 2 - React Native

Try next code:

<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
  <Text> TEST </Text>
  <Text> TEST </Text>
  <Text> TEST </Text>
  <Text> TEST </Text>
</ScrollView>

Solution 3 - React Native

Try adding style={{flex:1}} to <View> and <ScrollView> components. You also have a typo on your code: </SCrollView> in line 9. An example code will look like this:

<View style={{backgroundColor:'white', flex:1}}>
	<NavigationBar title="Title" />
	<ScrollView style={{flex:1, backgroundColor:'white'}}>
			<View style={{flex:1,justifyContent:'center'}}>
				<RegisterForm />
			</View>
	</ScrollView>
</View>

Solution 4 - React Native

If your ScrollView is within something that handles touch (Pressable, TouchableWithoutFeedback etc) then you either need to stop the touch event propagating up to that parent handler or else the ScrollView won't handle the touch event and therefore won't scroll.

This can be done either with onStartShouldSetResponder={() => true} or by wrapping the children in an element which itself handles the touch event (e.g. Pressable):

return (
  <ScrollView>
    <Pressable>
      <Text>This is scrollable</Text>
    <Pressable>
    <Pressable>
      <Text>As is this</Text>
    <Pressable>
  </ScrollView>
);

Solution 5 - React Native

Another solution is to add a height property to the parent View container. This sometimes works well when calculating the height against the screen height.

render () {
  const screenHeight = Dimensions.get('window').height

  return(
    <View style={{height: screenHeight}}>
      <ScrollView>
        <Text> TEST </Text>
        <Text> TEST </Text>
        <Text> TEST </Text>
        <Text> TEST </Text>
           ...    
      </ScrollView>
    </View>
  )
}

Solution 6 - React Native

I have tried all of these solutions and none were working. Then I just fully restarted the app and the metro server and everything worked fine.

Solution 7 - React Native

As @Evan Siroky has answered above it's working well I'm just adding on thing for a auto height in case you don't want to reserve the space

render () {
  const screenHeight = Dimensions.get('window').height
  return(
    <View style={{ Height: "auto", maxHeight: screenHeight}}>
      <ScrollView>
        <Text> TEST </Text>
        <Text> TEST </Text>
        <Text> TEST </Text>
        <Text> TEST </Text>
           ...    
      </ScrollView>
    </View>
  )
}

Solution 8 - React Native

Set nestedScrollEnabled as true for Hybrid Android + react app as it might be issue with gesture/click for scrolling issue.

Solution 9 - React Native

I had a similar issues, it got solved by removing height/width if set to '100%'.

Just adding here if someone faces the same issues. :D

Solution 10 - React Native

Just if anyone is as desperate as I was: My view was inside a StackNavigator. In the StackNavigator you can assign a default cardStyle. This card style needs height: "100%".

For me this was the case but I had overwritten it within the cardStyle of the Stack.Screen definition.

See this working example:

// This is the stack navigator

<ModalStack.Navigator screenOptions={() => ({
    cardStyle: {height: "100%"}
});}}>
    <ModalStack.Screen name={ScreenItemDetail} options={{
        // cardStyle: {} be sure to not override card style again! 
        
    }} component={ItemDetailScreen} />

    // ...

</ModalStack.Navigator>

Solution 11 - React Native

I think the best way of doing this is to put all requires inside an array and map this array.

const images = [
  require('../your/path/here'),
  require('../other/image/here'),
  ...
];

return ( {images.map((image) => <Image ... source={image} />)

note that if you want it as a background image with other elements above the image, you may use BackgroundImage and either render elements for each image or position absolute the image map and zIndex it behind all things

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoe CaraccioView Question on Stackoverflow
Solution 1 - React Nativegran33View Answer on Stackoverflow
Solution 2 - React NativeOleksandr CherniavenkoView Answer on Stackoverflow
Solution 3 - React Nativeleo7rView Answer on Stackoverflow
Solution 4 - React NativefredrivettView Answer on Stackoverflow
Solution 5 - React NativeEvan SirokyView Answer on Stackoverflow
Solution 6 - React NativeEJ ThayerView Answer on Stackoverflow
Solution 7 - React NativeMuhammad BilalView Answer on Stackoverflow
Solution 8 - React NativeAndroid_ITView Answer on Stackoverflow
Solution 9 - React NativeNevetsKuroView Answer on Stackoverflow
Solution 10 - React NativebastianowiczView Answer on Stackoverflow
Solution 11 - React NativenishiView Answer on Stackoverflow