Skip to content

Commit

Permalink
Deep navigation issue with iOS 14.x
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverwinterMoon committed Oct 12, 2020
1 parent 14fe8bb commit a98fd5f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CountriesSwiftUI/Injected/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension AppState {
struct ViewRouting: Equatable {
var countriesList = CountriesList.Routing()
var countryDetails = CountryDetails.Routing()
var bla = BlaView.Routing()
}
}

Expand Down
48 changes: 48 additions & 0 deletions CountriesSwiftUI/UI/Screens/CountryDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ struct CountryDetails: View {
}

var body: some View {
ZStack {
NavigationLink(
destination: BlaView(),
isActive: routingBinding.someNewView,
label: { EmptyView() }
)

content
}
.navigationBarTitle(country.name(locale: locale))
.onReceive(routingUpdate) { self.routingState = $0 }
.onReceive(inspection.notice) { self.inspection.visit(self, $0) }
Expand Down Expand Up @@ -88,7 +96,9 @@ private extension CountryDetails {
func loadedView(_ countryDetails: Country.Details) -> some View {
List {
country.flag.map { url in
Button(action: { injected.appState[\.routing.countryDetails.someNewView] = true } , label: {
flagView(url: url)
})
}
basicInfoSectionView(countryDetails: countryDetails)
if countryDetails.currencies.count > 0 {
Expand Down Expand Up @@ -165,6 +175,7 @@ private extension Country.Currency {
extension CountryDetails {
struct Routing: Equatable {
var detailsSheet: Bool = false
var someNewView: Bool = false
}
}

Expand All @@ -187,3 +198,40 @@ struct CountryDetails_Previews: PreviewProvider {
}
}
#endif

struct BlaView: View {
@Environment(\.injected) private var injected: DIContainer

@State private var routingState: Routing = .init()
private var routingBinding: Binding<Routing> {
$routingState.dispatched(to: injected.appState, \.routing.bla)
}

var body: some View {
ZStack {
NavigationLink(
destination: Text("BLU"),
isActive: routingBinding.anotherView,
label: { EmptyView() }
)

Button(action: { injected.appState[\.routing.bla.anotherView] = true } , label: {
Text("Go to BLU")
})
}
.onReceive(routingUpdate) { self.routingState = $0 }
}
}

extension BlaView {
struct Routing: Equatable {
var anotherView: Bool = false
}
}

private extension BlaView {

var routingUpdate: AnyPublisher<Routing, Never> {
injected.appState.updates(for: \.routing.bla)
}
}

0 comments on commit a98fd5f

Please sign in to comment.