mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-18 10:45:15 +00:00
Optimize avatar view (#950)
* Reduce AvatarPlaceholderView body calls * Resize avatars
This commit is contained in:
parent
76be2b5671
commit
da289dbc1f
1 changed files with 23 additions and 16 deletions
|
@ -56,19 +56,19 @@ public struct AvatarView: View {
|
||||||
.fill(.gray)
|
.fill(.gray)
|
||||||
.frame(width: size.size.width, height: size.size.height)
|
.frame(width: size.size.width, height: size.size.height)
|
||||||
} else {
|
} else {
|
||||||
if isInCaptureMode, let image = Nuke.ImagePipeline.shared.cache.cachedImage(for: .init(url: url))?.image {
|
if isInCaptureMode, let url = url, let image = Nuke.ImagePipeline.shared.cache.cachedImage(for: makeImageRequest(for: url))?.image {
|
||||||
Image(uiImage: image)
|
Image(uiImage: image)
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
.frame(width: size.size.width, height: size.size.height)
|
.frame(width: size.size.width, height: size.size.height)
|
||||||
} else {
|
} else {
|
||||||
LazyImage(url: url) { state in
|
LazyImage(request: url.map(makeImageRequest)) { state in
|
||||||
if let image = state.image {
|
if let image = state.image {
|
||||||
image
|
image
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
} else {
|
} else {
|
||||||
placeholderView
|
AvatarPlaceholderView(size: size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.animation(nil)
|
.animation(nil)
|
||||||
|
@ -82,6 +82,10 @@ public struct AvatarView: View {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func makeImageRequest(for url: URL) -> ImageRequest {
|
||||||
|
ImageRequest(url: url, processors: [.resize(size: size.size)])
|
||||||
|
}
|
||||||
|
|
||||||
private var clipShape: some Shape {
|
private var clipShape: some Shape {
|
||||||
switch theme.avatarShape {
|
switch theme.avatarShape {
|
||||||
case .circle:
|
case .circle:
|
||||||
|
@ -90,17 +94,20 @@ public struct AvatarView: View {
|
||||||
return AnyShape(RoundedRectangle(cornerRadius: size.cornerRadius))
|
return AnyShape(RoundedRectangle(cornerRadius: size.cornerRadius))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@ViewBuilder
|
|
||||||
private var placeholderView: some View {
|
private struct AvatarPlaceholderView: View {
|
||||||
if size == .badge {
|
let size: AvatarView.Size
|
||||||
Circle()
|
|
||||||
.fill(.gray)
|
var body: some View {
|
||||||
.frame(width: size.size.width, height: size.size.height)
|
if size == .badge {
|
||||||
} else {
|
Circle()
|
||||||
RoundedRectangle(cornerRadius: size.cornerRadius)
|
.fill(.gray)
|
||||||
.fill(.gray)
|
.frame(width: size.size.width, height: size.size.height)
|
||||||
.frame(width: size.size.width, height: size.size.height)
|
} else {
|
||||||
}
|
RoundedRectangle(cornerRadius: size.cornerRadius)
|
||||||
}
|
.fill(.gray)
|
||||||
|
.frame(width: size.size.width, height: size.size.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue