ProfileHost
struct ProfileHost: View { @State private var editMode: EditMode = .inactive @ObservedObject var viewModel = ProfileViewModel() @EnvironmentObject var user: LoginViewModel @State private var showingOptions = false var profileLabel: [String] = ["Edit account", "Change password", "Favourites", "Notification", "Role", "Contact us"] var profileImageName: [String] = ["profile_account", "profile_password", "profile_fav", "profile_noti", "profile_role", "profile_contact"] var profileSetting: [ProfileSetting] { var result: [ProfileSetting] = [] for n in 1...6 { result.append(ProfileSetting(id: n, imageName: profileImageName[n-1], labelName: profileLabel[n-1])) } return result } var body: some View { NavigationView { List { ForEach(profileSetting) { profile in switch profile.id { case 1: NavigationLink(destination: ProfileEditor(profileViewModel: viewModel)) { ProfileRow(profileSetting: profile) } .onAppear { viewModel.fetchData(userId: user.session?.uid) } } }
ProfileEditorProfile
struct ProfileEditorProfile: View { @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode> @ObservedObject var profileViewModel: ProfileViewModel @EnvironmentObject var loginViewModel : LoginViewModel @State var profileItem: [String] = [] @State var profileEditorRow: [ProfileEditorItem] = [] var body: some View { VStack { ForEach(profileEditorRow) { editori in // show last line on the last row if editor.id == 5 { ProfileEditorRow(editor: editor, showLastLine: true) } else { ProfileEditorRow(editori: editor, showLastLine: false) } .onAppear() { profileItem = [profileViewModel.user.name, profileViewModel.user.birthDay, profileViewModel.user.gender, profileViewModel.user.role.first ?? "", profileViewModel.user.birthDay] for n in 1...5 { profileEditorRow.append(ProfileEditorItem(id: n, label: profileLabel[n-1], item: profileItem[n-1])) } } } } Button("Save") { profileViewModel.updateData(userId: loginViewModel.session?.uid) } }
ProfileEditorRowProfileRow
struct ProfileEditorRowProfileRow: View { @State var editor: ProfileEditorItem var body: some View { ZStack(alignment: .bottom) { HStack(alignment: .center) { Text(editor.label) .fontWeight(.none) .font(.custom("Poppins-Regular", size: 16)) .frame(maxWidth: 70, alignment: .leading) .padding(.trailing, 20) .padding(.top,-10) VStack(alignment: .center) { TextField("",text: $editor.item) .poppinsRegularFont(size: 16) .foregroundColor(ColorManager.textGray) .frame(maxHeight:40) } Rectangle().fill(ColorManager.lineGray) .frame(height: 1, alignment: .bottom) .frame(maxWidth: .infinity) } } .padding(.leading, 15) } }