Maintain aspect ratio of image with full width in React Native

前端 未结 12 1542
终归单人心
终归单人心 2020-12-07 13:02

I have a query regarding tag. I want an image to take entire width of parent which I do using alignSelf:stretch, but I also want the height to be according to the aspect ra

12条回答
  •  情话喂你
    2020-12-07 13:59

    Typically, doing the following would give us an image rendered to max width/height depending on orientation while maintaining the aspect ratio of the image itself:

    render(){
        return();
    }
    

    Using 'contain' with resizeMode: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).

    Update: * Unfortunately, it seems that there is a common bug with resizeMode's 'contain' specifically when using react native for Android: https://github.com/facebook/react-native/pull/5738*

提交回复
热议问题