Hi. I am using Kingfisher library to load images. My problem is that when i resize the width, the calculated height does not follow. the height of the image when displayed is still short.
What could possibly be wrong in my code?
import SwiftUI
import Kingfisher
struct MyView: View {
var geometryProxy: GeometryProxy
var body: some View {
HStack {
HStack {
KFImage.url(URL(string: "https://volcano.si.edu/gallery/photos/GVP-11076.jpg"))
.cancelOnDisappear(true)
.fade(duration: 0.25)
.resizable()
.scaledToFit()
}
.frame(maxWidth: geometryProxy.size.width * 0.4, maxHeight: getHeight(Float(geometryProxy.size.width) * 0.4, Float(geometryProxy.size.height), Float(geometryProxy.size.width)))
Text("Text 1 Label")
.frame(maxWidth: geometryProxy.size.width * 0.65, alignment: .topLeading)
.padding(.leading, 10)
.padding(.top, 3)
Image(systemName: "chevron.right")
.frame(maxWidth: geometryProxy.size.width * 0.05)
.padding(.leading, 0)
}
.contentShape(Rectangle())
}
private func getHeight(_ imageWidth: Float, _ imageHeight: Float, _ screenWidth: Float) -> CGFloat {
// let ratio = Float(placeholder!.size.height / placeholder!.size.width)
// print(ratio)
// print(ratio * width)
// print("______")
// return CGFloat(ratio * width)
let ratio = screenWidth / imageWidth
return CGFloat(imageHeight * ratio)
}
}
The Image should expand since i set the width of the image to at least 40% of the screen width.
Or could my calculation for getting the height may be wrong? Thougts?