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