fixing bug regarding profile edit page as the lazygrid was rebuilt everytimte but now it's smooth

This commit is contained in:
talksik
2022-01-02 19:31:41 -08:00
parent 7275899dd0
commit 61dac1dba1
@@ -13,8 +13,8 @@ struct AddBasicInfoView: View {
@EnvironmentObject var authSessionStore: AuthSessionStore
@ObservedObject var addInfoViewModel: AddBasicInfoViewModel = AddBasicInfoViewModel()
@State var nickname = ""
@State var selectedAvatarIndex: Int = 0
@State private var nickname: String = ""
@State private var selectedAvatarIndex: Int = 0
var columns: [GridItem] =
Array(
@@ -55,7 +55,7 @@ struct AddBasicInfoView: View {
.foregroundColor(NirvanaColor.teal)
.multilineTextAlignment(.center)
Text("Select an avatar you like, then make a username! You can always change this later.")
Text("Select an avatar you like, then put your nickname! You can always change this later.")
.font(.subheadline)
.foregroundColor(Color.black.opacity(0.7))
}
@@ -63,7 +63,7 @@ struct AddBasicInfoView: View {
// Horizontal scroll view to allow user to select the avatar he or she wants
ScrollView([.horizontal, .vertical], showsIndicators: false) {
LazyVGrid(columns: columns) {
ForEach(0..<Avatars.avatarSystemNames.count) { index in
ForEach(0..<Avatars.avatarSystemNames.count, id: \.self) { index in
Image(Avatars.avatarSystemNames[index])
.resizable()
.scaledToFit()
@@ -81,6 +81,7 @@ struct AddBasicInfoView: View {
.animation(.spring())
}
}.padding(.top, 20)
.id(UUID())
}
// input nickname
@@ -134,18 +135,11 @@ struct AddBasicInfoView: View {
.onAppear {
// get current user nickname and avatar if they have one
self.nickname = self.authSessionStore.user?.nickname ?? ""
if self.authSessionStore.user?.avatar != nil { // if user has previously selected an avatar
self.selectedAvatarIndex = Avatars.avatarSystemNames.firstIndex(of: (self.authSessionStore.user?.avatar)!) ?? 0 // 0 in case the system names doesn't have it anymore
}
}
//TODO: hook up the alert with the view model
// .alert(isPresented: Binding<Bool>(
// get: { self.addInfoViewModel.state == ProfileRegistrationState.failed},
// set: { _ in self.addInfoViewModel.state = ProfileRegistrationState.na }
// )) {
// Alert(title: Text("Important message"), message: Text("Wear sunscreen"), dismissButton: .default(Text("Got it!")))
// }
}
}