ReactNative之Image组件自适应高度,图片自适应大小


  

const handleWechatQRCodeHeight = () => {
    const { wechatQRCode } = getAdminInfo()

    Image.getSize(wechatQRCode, (width, height) => {
      let wechatQRCodeHeight = (height / width) * 300
      console.log(wechatQRCodeHeight)
      setWechatQRCodeHeight(wechatQRCodeHeight)
    })
  }

  useEffect(() => {
    handleWechatQRCodeHeight()
    // eslint-disable-next-line
  }, [])


                <Image
                  style={{
                    ...styles.mExchangeWechatQRCode,
                    height: wechatQRCodeHeight,
                  }}
                  uri={wechatQRCode}
                  resizeMode={'cover'}
                ></Image>

posted @ 2023-08-14 14:56  徐同保  阅读(56)  评论(0编辑  收藏  举报  来源