[docs] ScrollView height clarification
Currently, the only way I can implement a working ScrollView is if it's nested within a view of bounded height or {flex: 1}. The docs make it sound as if only the height of the ScrollView itself needs to be set in order to function.
I could be implementing it wrong but rendering a plain ScrollView with a set height that's not nested produces a ScrollView that bounces but does not scroll.
Experiencing the same thing. This sure seems like a bug to me, but if it's not the docs should definitely reflect that you need to nest it in another View and can't set height on the ScrollView directly.
Check this out to see it happen: https://rnplay.org/apps/pTCbwA
After you see the full screen ScrollView, just wrap the ScrollView in an unstyled view to see it display at the correct height.
wasted too much time trying to figure it out :/ :+1: needs fix or doc update
Neither my profile component or the dashboard component is scrolling. Even when i cut and paste the code from Branch 13 in this egghead.io tutorial Repo i still cant get scrolling. https://github.com/eggheadio/react-native-gh-notetaker/blob/13-finish-repositories-component/App/Components/Profile.js
This is the component code which works for rendering the data but does not scroll the data. Anything stand out here?
var React = require('react-native');
var Badge = require('./Badge');
var Separator = require('./Helpers/Separator');
var {
Text,
View,
ListView,
StyleSheet,
ScrollView
} = React;
var styles = StyleSheet.create({
container: {
flex: 1
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
rowContainer: {
padding: 10
},
rowTitle: {
color: '#48BBEC',
fontSize: 16
},
rowContent: {
fontSize: 19
}
});
class Profile extends React.Component{
getRowTitle(user, item){
item = (item === 'public_repos') ? item.replace('_', ' ') : item;
return item[0] ? item[0].toUpperCase() + item.slice(1) : item;
}
render(){
var userInfo = this.props.userInfo;
var topicArr = ['company', 'location', 'followers', 'following', 'email', 'bio', 'public_repos'];
var list = topicArr.map((item, index) => {
if(!userInfo[item]){
return <View key={index}/>
} else {
return (
<View key={index}>
<View style={styles.rowContainer}>
<Text style={styles.rowTitle}> {this.getRowTitle(userInfo, item)} </Text>
<Text style={styles.rowContent}> {userInfo[item]} </Text>
</View>
<Separator />
</View>
)
}
});
return (
<ScrollView style={styles.container}>
<Badge userInfo={this.props.userInfo}/>
{list}
</ScrollView>
)
}
};
Profile.propTypes = {
userInfo: React.PropTypes.object.isRequired
}
module.exports = Profile;
https://jsfiddle.net/lokal/v7zdb16g/
Thank you.
Exactely the same problem...
How to set the ScrollView to "take all the remaining space" instead of setting height: XX ?
Depending on the device which is being used, the remaining height varies a lot...
How is this not trivial? I only get a working scrollView with fixed height so far (no specific scrollview wrapper needed), setting flex:1 on contentContainerStyle, style or wrapper style, setting it on any or all of them does not work for me. It just renders the entire view, overflowing the screen, no scroll.
edit: check all flex values on the page. In my case, there was another flex element above the scroll view that made things weird.
I also have this issue...
+1, btw, your views root container should contain flex: 1, to avoid the inner scrollview container to overflow off the screen
Use contentContainerStyle={{flex:1}} on ScrollView tag, that should fix your problem.
style={{ flex: 1}} isn't working for me. The content in our ScrollView is loaded in dynamically from an API call. The component that holds that dynamic content is resizing correctly, but it's as though the parent isn't taking that height change into account and I can't scroll to the bottom of our list. Do I need to do something with onLayout to notify that parent ScrollView of the height change?
@gkrinc how are you setting the inner state of the scrollview once you receive your API call data? you can try triggering a re-render via this.setState({...}) or using this.forceUpdate().
Thanks @ospfranco I got it working. I ended up with a static height on something that was causing the issue. Totally my fault :s
I ended up solving this problem by wrapping the ScrollView in a View with {flex:1} and setting nothing about height in my ScrollView style nor contentContainerStyle. Takes the full height and goes deep down the screen.
But with this solution you cannot really rely on "flex" in direct children. If the screen isn't initially filled with content you'll have some unused spaces.
I tried to set up a bounded height scrollview, but it seems like to automatically take up all remaining height of parent, the only way to do it for me is to use a wrapper view outside of scrollview
For me contentContainerStyle={{flex: 0}} did the trick.
@alexindigo Makes sense because the size of the contentContainer should not flex, it should match the size of the contents.
{flex: 1} works in 0.43. or
{flexGrow: 1,flexShrink: 1, flexBasis: 1,}
I also experience the same thing. Except that scrolling to bottom would not be actual bottom, I would have content cut off. Unless I wrap it with <View> and set flex:1. Setting flexGrow:1 on the view did not fix it for me. I would get this content cut off bug when adding a marginVertical to the ScrollView or FlastList too.
In my case also the scrollview doesnot scrolls inside a view conmponent. Any solutions for it?
Just ran into this. I wanted a horizontal ScrollView to take as little height as possible. The ScrollView by itself displayed as if it had flex: 1 specified, which it didn't. Thanks to @bistacos, wrapping it in a View solves my problem.
none of the solutions above worked for me, perhaps because we all tested these solutions on different versions of RN... I'm on RN47, and the only solution that worked for me, was manually measuring out the 3 different heights i needed, and then dynamically swapping between heights based on what content needed the extra height. So in the end it, this is what finally worked for me:
contentContainerStyle={{ height: userType === 'SHOPPER' ? 600 : userType === 'DIST' && !DistributorId ? 660 : DistributorId ? 860 : 700 }}