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 @EnvironmentObject var authSessionStore: AuthSessionStore
@ObservedObject var addInfoViewModel: AddBasicInfoViewModel = AddBasicInfoViewModel() @ObservedObject var addInfoViewModel: AddBasicInfoViewModel = AddBasicInfoViewModel()
@State var nickname = "" @State private var nickname: String = ""
@State var selectedAvatarIndex: Int = 0 @State private var selectedAvatarIndex: Int = 0
var columns: [GridItem] = var columns: [GridItem] =
Array( Array(
@@ -55,7 +55,7 @@ struct AddBasicInfoView: View {
.foregroundColor(NirvanaColor.teal) .foregroundColor(NirvanaColor.teal)
.multilineTextAlignment(.center) .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) .font(.subheadline)
.foregroundColor(Color.black.opacity(0.7)) .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 // Horizontal scroll view to allow user to select the avatar he or she wants
ScrollView([.horizontal, .vertical], showsIndicators: false) { ScrollView([.horizontal, .vertical], showsIndicators: false) {
LazyVGrid(columns: columns) { LazyVGrid(columns: columns) {
ForEach(0..<Avatars.avatarSystemNames.count) { index in ForEach(0..<Avatars.avatarSystemNames.count, id: \.self) { index in
Image(Avatars.avatarSystemNames[index]) Image(Avatars.avatarSystemNames[index])
.resizable() .resizable()
.scaledToFit() .scaledToFit()
@@ -75,14 +75,15 @@ struct AddBasicInfoView: View {
.clipShape(Circle()) .clipShape(Circle())
.onTapGesture { .onTapGesture {
print("selected another avatar: \(index)") print("selected another avatar: \(index)")
self.selectedAvatarIndex = index self.selectedAvatarIndex = index
} }
.animation(.spring()) .animation(.spring())
} }
}.padding(.top, 20) }.padding(.top, 20)
.id(UUID())
} }
// input nickname // input nickname
VStack { VStack {
TextField("nickname", text: self.$nickname) TextField("nickname", text: self.$nickname)
@@ -134,18 +135,11 @@ struct AddBasicInfoView: View {
.onAppear { .onAppear {
// get current user nickname and avatar if they have one // get current user nickname and avatar if they have one
self.nickname = self.authSessionStore.user?.nickname ?? "" self.nickname = self.authSessionStore.user?.nickname ?? ""
if self.authSessionStore.user?.avatar != nil { // if user has previously selected an avatar 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 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!")))
// }
} }
} }