Reputation: 510
<View style={{
flex: 1,
height: 1200,
width: 200,
alignItems: 'flex-start',
flexWrap: 'wrap',
flexDirection: 'column',
justifyContent: 'center'
}}>
<View style={{
flex: 1,
width: 100,
height: 100,
backgroundColor: 'powderblue'
}}>
<Image source={require('./assets/zodiac/Aries.svg.png')} style={{width: undefined, height: '100%', resizeMode: 'contain'}}/>
</View>
{/* 11 more similarly sized images in View containers */}
</View>
When the height
property of the parent View
is 1200, the following is the result:
But when the height
is changed to 600, instead of wrapping around as it should because of the flexWrap: 'wrap'
property, the child Views get squeezed to accommodate the new height
.
Why does this happen?
Upvotes: 0
Views: 52
Reputation: 46
The issue here is with how you have defined the style in the child view components
style={{
flex: 1,
width: 100,
height: 100,
backgroundColor: 'powderblue'
}}
Replace this with
style={{
width: 100,
height: 100,
backgroundColor: 'powderblue'
}}
This should do the job for you. What happens when you define a flex for each of the child view components is it fits them within the parent view according to the relative flex values set, irrespective of what you set as the heights and width.
Upvotes: 1
Reputation: 176
When the height of the content is greater than the height of the Screen, always think to use ScrollVIew
instead
You for a better UI it's also better to use Dimension
package like
import {Dimension} from 'react-native';
//////////
const HEIGHT_DEVICE = Dimension.get('window').height;
///////////
Then use this prop as you like
Upvotes: 0