Closed arbyruns closed 2 years ago
hi, you need to force unwrap your URL, change URL(string: logURL) to URL(string: logURL)!
For this issue, a demo url is better to reproduce this and fix (maybe) bugs.
The unit test in our repo for sd_color(with:)
runs correctly. So this must be some rare case.
I forced unwrapped the URL and I'm still getting back nil
. Here's my sample code with a URL.
var body: some View {
VStack {
GeometryReader { geo in
let frame = geo.frame(in: CoordinateSpace.local)
WebImage(url: URL(string: "https://logo.clearbit.com/google.com")!)
.onSuccess { image, _, _ in
print("webImage \(String(describing: image.sd_color(at: CGPoint(x: frame.origin.x + 40, y: frame.origin.y + 40))))")
print("webImage \(String(describing: image.sd_colors(with: CGRect(x: frame.origin.x + 40, y: frame.origin.y + 40, width: geo.size.width, height: geo.size.height))))")
}
Text("Hello, World!")
.position(x: frame.origin.x + 40, y: frame.origin.y + 40)
}
}
}
Print console:
webImage Optional(UIExtendedSRGBColorSpace 0.980392 0.992157 0.984314 1)
webImage nil
I guess you misunderstand the API of sd_colors(at:)
point.
The point is based on the Image itself resolution and space. So, you should use CGPoint(x: 40, y: 40)
, not the frame origin.
sd_colors(at:)
has only image information, not know about the coordinate space of the container view. (For example, 100 UIView
can host single UIImage
at the same time :))
I'm trying to use
sd_colors(with: )
and getting back nil. Here's the code that I'm using and I've tried a few differentCGRect
values and I get the same thing. I know I'm getting an image back because I can see the image and I can successfully useimage.sd_color(at: CGPoint(x: 50, y: 50))
and get back a color.