Apply avatar style to local account avatar images

This commit is contained in:
Shadowfacts 2020-05-10 19:26:54 -04:00
parent 5a098df931
commit 04496aca1d
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 11 additions and 3 deletions

View File

@ -10,19 +10,27 @@ import SwiftUI
struct LocalAccountAvatarView: View { struct LocalAccountAvatarView: View {
let localAccountInfo: LocalData.UserAccountInfo let localAccountInfo: LocalData.UserAccountInfo
@State @State var avatarImage: UIImage? = nil
var avatarImage: UIImage? = nil @ObservedObject var preferences = Preferences.shared
var body: some View { var body: some View {
let image: Image let image: Image
if avatarImage == nil { if avatarImage == nil {
image = Image(systemName: "person.crop.square") let imageName: String
switch preferences.avatarStyle {
case .circle:
imageName = "person.crop.circle"
case .roundRect:
imageName = "person.crop.square"
}
image = Image(systemName: imageName).resizable()
} else { } else {
image = Image(uiImage: self.avatarImage!).renderingMode(.original) image = Image(uiImage: self.avatarImage!).renderingMode(.original)
} }
return image return image
.resizable() .resizable()
.frame(width: 30, height: 30) .frame(width: 30, height: 30)
.cornerRadius(preferences.avatarStyle.cornerRadiusFraction * 30)
.onAppear(perform: self.loadImage) .onAppear(perform: self.loadImage)
} }