Reputation: 542
I've the following layout, and it need scroll when data is greater of screen:
Image:
Code:
export default () => (
<Container hasNavBar={false}>
<View style={{flex: 1}}>
<View style={Styles.container}>
<View style={{
flex: 1, backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>Area 1</Text>
</View>
<View style={{
flex: 2, backgroundColor: 'yellow',
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>Area 2</Text>
</View>
</View>
</View>
</Container>
);
Following the documentation of react-native for add scroll I need create a wraper of my layout using ScrollView component, but when added scrollView component my layout broke:
Image:
Code:
export default () => (
<Container hasNavBar={false}>
<ScrollView style={{flex: 1}}>
<View style={Styles.container}>
<View style={{
flex: 1, backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>Area 1</Text>
</View>
<View style={{
flex: 2, backgroundColor: 'yellow',
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>Area 2</Text>
</View>
</View>
</ScrollView>
</Container>
);
Container Component
<View style={flex: 1}>
{this.props.children}
<DropdownAlert
closeInterval={10000}
updateStatusBar={false}
ref={(ref) => this.dropdown = ref}
onClose={() => null}/>
</View>
How i solve it ?
Upvotes: 0
Views: 772
Reputation: 1977
After re-reading the question with better understanding of your complete code it became obvious that the quickest fix would be to define minHeight
on Area 1 and Area 2's views. We can calculate it from window's Dimensions
. This allows you to obtain the 33%/66% ratio with minimal content and expand either Area as needed with additional content.
Place this at the top of render():
const { height } = Dimensions.get('window');
Add to Area 1's style
minHeight: height / 3
And to Area 2's style
minHeight: (height / 3) * 2
Upvotes: 3