I am designing a scroll component to looks like a gallery of images. I am trying to center the images based on the device height with equivalent padding on both top and bottom. But based on the devices the top padding is not looking good. I need help to make it consistent in all the devices.
To get Height and Width of the device i am using Dimension
const {width: screenWidth, height: screenHeight} =
Dimensions.get('window');
const width = screenWidth ;
const height = screenHeight;
<View style={styles.DefaultView}>
<ScrollView
maximumZoomScale={1}
minimumZoomScale={1}
bouncesZoom={true}
style={styles.scrollView}
automaticallyAdjustContentInsets={true}
pagingEnabled={true}
horizontal={true}
showsHorizontalScrollIndicator={false}
onScroll={this._onScroll}
contentContainerStyle={{flexGrow : 1, justifyContent : 'center'}}
>
{images.map((row, i) => (
<View key={i}>
<Image
resizeMode='contain'
style={{width, height}}
source={{uri: row.src}}
/>
</View>
))}
</ScrollView>
</View>
const styles = StyleSheet.create({
scrollView: {
flex: 1,
flexDirection: 'row',
},
DefaultView: {
flex: 1,
backgroundColor: '#000',
},
});
Please refer attached image for the current output 
there is a prop for this called contentContainerStyle
<ScrollView
contentContainerStyle={{
paddingTop: 25,
paddingBottom: 25,
}}>
*** CONTENT ***
</ScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With