diff --git a/Packages/Feature/Sources/Feature/CountrySelecting/Adapters/CountryListAdapter.swift b/Packages/Feature/Sources/Feature/CountrySelecting/Adapters/CountryListAdapter.swift index cc3b6ac..1377775 100644 --- a/Packages/Feature/Sources/Feature/CountrySelecting/Adapters/CountryListAdapter.swift +++ b/Packages/Feature/Sources/Feature/CountrySelecting/Adapters/CountryListAdapter.swift @@ -18,11 +18,10 @@ public struct CountryListAdapter: View { private var onCountrySelected: ((Country) -> Void)? private var onAboutThisAppSelected: (() -> Void)? + @Binding var destination: Destinations? - public init(onCountrySelected: ((Country) -> Void)? = nil, - onAboutThisAppSelected: (() -> Void)? = nil) { - self.onCountrySelected = onCountrySelected - self.onAboutThisAppSelected = onAboutThisAppSelected + public init(destination: Binding) { + self._destination = destination } public var body: some View { @@ -36,10 +35,17 @@ public struct CountryListAdapter: View { .onReceive(viewModel.$navigationDestination, perform: { country in guard let country = country else { return } - self.onCountrySelected?(country) + self.destination = Destinations.details(regionCode: country.regionCode) + }) + .onReceive(Just($destination), perform: { newValue in + if newValue.wrappedValue == nil && viewModel.navigationDestination != nil { + viewModel.navigationDestination = nil + } }) .pss_notify(item: $viewModel.error, alertBuilder: { - $0.asFloatingAlert(viewModel: viewModel, onAboutThisAppSelected: onAboutThisAppSelected) + $0.asFloatingAlert(viewModel: viewModel, onAboutThisAppSelected: { + self.destination = Destinations.aboutThisApp + }) }) } } diff --git a/Packages/Feature/Sources/Feature/Destinations.swift b/Packages/Feature/Sources/Feature/Destinations.swift new file mode 100644 index 0000000..82cb547 --- /dev/null +++ b/Packages/Feature/Sources/Feature/Destinations.swift @@ -0,0 +1,13 @@ +// +// File.swift +// +// +// Created by Eric Silverberg on 12/28/22. +// + +import Foundation + +public enum Destinations { + case details(regionCode: String) + case aboutThisApp +} diff --git a/Shared/TravelAdvisoriesNavHost.swift b/Shared/TravelAdvisoriesNavHost.swift index efa8c31..950dd69 100644 --- a/Shared/TravelAdvisoriesNavHost.swift +++ b/Shared/TravelAdvisoriesNavHost.swift @@ -19,11 +19,6 @@ public struct TravelAdvisoriesNavHost: View { @State var destination: Destinations? - enum Destinations { - case details(regionCode: String) - case aboutThisApp - } - public init(resolver: Swinject.Resolver = InjectSettings.resolver!) { self.resolver = resolver } @@ -45,11 +40,7 @@ public struct TravelAdvisoriesNavHost: View { } @ViewBuilder func buildBaseView() -> some View { - CountryListAdapter(onCountrySelected: { country in - self.destination = Destinations.details(regionCode: country.regionCode) - }) { - self.destination = Destinations.aboutThisApp - } + CountryListAdapter(destination: $destination) } @ViewBuilder func buildChildViewFromState() -> some View {