nice working version of the dynamic background color based on photo url

This commit is contained in:
talksik
2021-12-14 17:06:39 -08:00
parent 58b6b1068d
commit 08458a764b
4 changed files with 64 additions and 42 deletions
+11 -4
View File
@@ -9,7 +9,7 @@ import SwiftUI
struct HeaderView: View {
@EnvironmentObject var authStore:AuthSessionStore
private var averageColor: UIColor?
@State var averageColor: UIColor? = UIColor(NirvanaColor.teal)
var body: some View {
HStack(alignment:.center) {
@@ -28,12 +28,19 @@ struct HeaderView: View {
.clipShape(Circle())
.padding()
.shadow(radius:5)
.onAppear {
self.setAverageColor()
}
}
}
.background(Color(self.averageColor!))
.frame(maxWidth: .infinity)
.onAppear{
// set background color based on profile picture tint
if authStore.sessionState == SessionState.isAuthenticated {
if let userPicUrl = authStore.user?.profilePictureUrl {
self.averageColor = NirvanaImage.getAverageColor(url: userPicUrl)
}
// self.averageColor = NirvanaImage.getAverageColor(url: "https://avatars.githubusercontent.com/u/41487836")
}
}
}
private func setAverageColor() {