Reputation: 586
Is there a way how to control image position with resizeMode
set to cover
? I'm looking for similar result as can be achieve by using background-positon: center bottom
in traditional CSS.
Here is an illustration of the situation:
My code:
<Image
source={require('./eifell.jpg')}
resizeMode={Image.resizeMode.cover}
style={{
height: 300
}}
/>
Upvotes: 5
Views: 3216
Reputation: 1511
I believe you'll have to achieve this by using the transforms
prop on the image style and utilize the translateY
transformation.
It will involve a little math... off the top of my head I believe you would need to follow these steps:
Use Image.getSize() to find the dimensions of your image
Then based on the size of your window from Dimensions.get('window')
calculate how many pixels your image will scale to.
Find the difference between the height displayed (say 667px) and the desired height of the image (300px in your example)
Then translate the image up that many pixels.
Upvotes: 3