Preselect profile on NavigationLink appearance

More accurate than ForEach and maybe the only right place.
This commit is contained in:
Davide De Rosa 2022-04-18 22:34:30 +02:00
parent 5d85699ce4
commit b1882dcf80
1 changed files with 5 additions and 4 deletions

View File

@ -79,7 +79,6 @@ extension OrganizerView {
Section { Section {
ForEach(headers.sorted(), content: navigationLink(forHeader:)) ForEach(headers.sorted(), content: navigationLink(forHeader:))
.onDelete(perform: removeProfiles) .onDelete(perform: removeProfiles)
.onAppear(perform: selectActiveProfile)
} }
} }
} }
@ -101,6 +100,8 @@ extension OrganizerView {
} else { } else {
ProfileHeaderRow(header: header) ProfileHeaderRow(header: header)
} }
}.onAppear {
preselectActiveProfile(header.id)
} }
} }
} }
@ -133,7 +134,7 @@ extension OrganizerView.ProfilesList {
} }
extension OrganizerView.ProfilesList { extension OrganizerView.ProfilesList {
private func selectActiveProfile() { private func preselectActiveProfile(_ id: UUID) {
guard isFirstLaunch else { guard isFirstLaunch else {
return return
} }
@ -146,9 +147,9 @@ extension OrganizerView.ProfilesList {
// //
if alertType == nil, if alertType == nil,
themeIdiom != .pad, themeIdiom != .pad,
let activeProfileId = profileManager.activeHeader?.id { id == profileManager.activeHeader?.id {
selectedProfileId = activeProfileId selectedProfileId = id
} }
} }