From 923ea923abe2159b20ac3978c0b8b77c79fd2517 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 19 Apr 2022 18:45:08 +0200 Subject: [PATCH] Fix active profile not preselected on launch Function called multiple times sets isFirstLaunch to true even if not active profile. --- .../App/Views/OrganizerView+Profiles.swift | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Passepartout/App/Views/OrganizerView+Profiles.swift b/Passepartout/App/Views/OrganizerView+Profiles.swift index b2a49ce7..f1f11c06 100644 --- a/Passepartout/App/Views/OrganizerView+Profiles.swift +++ b/Passepartout/App/Views/OrganizerView+Profiles.swift @@ -101,7 +101,7 @@ extension OrganizerView { ProfileHeaderRow(header: header) } }.onAppear { - preselectActiveProfile(header.id) + preselectIfActiveProfile(header.id) } } } @@ -134,23 +134,22 @@ extension OrganizerView.ProfilesList { } extension OrganizerView.ProfilesList { - private func preselectActiveProfile(_ id: UUID) { - guard isFirstLaunch else { - return - } - isFirstLaunch = false + private func preselectIfActiveProfile(_ id: UUID) { // do not push profile if: // // - an alert is active, as it would break navigation // - on iPad, as it's already shown // - if alertType == nil, - themeIdiom != .pad, - id == profileManager.activeHeader?.id { - - selectedProfileId = id + guard alertType == nil, themeIdiom != .pad, id == profileManager.activeHeader?.id else { + return } + guard isFirstLaunch else { + return + } + isFirstLaunch = false + + selectedProfileId = id } private func performMigrationsIfNeeded() {