Consider an iOS SwiftUI project that has the following coordinator structure:
App
MainCoordinator
ContentViewCoordinator (@Root of MainCoordinator)
SecondaryCoordinator (@Route(.fullScreen) from ContentViewCoordinator)
In iOS 14.4, performing route(to:) from ContentViewCoordinator to SecondaryCoordinator by some reason has no effect (just nothing happens, no crashes, no console logs), while it works perfectly fine in iOS 14.5 and iOS 15. The issue is reproducible on simulators with Xcode 13.4.
Here's a full source code of an app that illustrates the issue:
import Stinsen
import SwiftUI
@main
struct StinsenNavigationIssueExampleApp: App {
var body: some Scene {
WindowGroup {
MainCoordinator().view()
}
}
}
final class MainCoordinator: NavigationCoordinatable {
var stack = NavigationStack(initial: \MainCoordinator.start)
@Root private var start = makeStart
private func makeStart() -> ContentViewCoordinator {
ContentViewCoordinator()
}
}
final class ContentViewCoordinator: NavigationCoordinatable {
var stack = NavigationStack(initial: \ContentViewCoordinator.start)
@Root private var start = makeContentView
@Route(.fullScreen) private var secondary = makeSecondaryCoordinator
private func makeContentView() -> some View {
ContentView(buttonAction: { [weak self] in
self?.route(to: \.secondary)
})
}
private func makeSecondaryCoordinator() -> SecondaryCoordinator {
SecondaryCoordinator()
}
}
final class SecondaryCoordinator: NavigationCoordinatable {
var stack = NavigationStack(initial: \SecondaryCoordinator.start)
@Root private var start = makeSecondaryView
private func makeSecondaryView() -> some View {
SecondaryView()
}
}
struct ContentView: View {
var buttonAction: (() -> Void)?
var body: some View {
Button {
buttonAction?()
} label: {
Text("Open secondary view")
}
}
}
struct SecondaryView: View {
var body: some View {
ZStack {
Color.yellow.ignoresSafeArea()
Text("Secondary")
}
}
}
Tapping on the "Open secondary view" button has no effect in iOS 14.4 simulator, but works well in iOS 14.5 and iOS 15. I was not able to confirm if it's reproducible on a physical device because I don't have any devices running that particular iOS version.
Interestingly enough, if I just get rid of the MainCoordinator and instantiate ContentViewCoordinator right in the App's body, it starts working fine on iOS 14.4.
Consider an iOS SwiftUI project that has the following coordinator structure:
In iOS 14.4, performing
route(to:)
from ContentViewCoordinator to SecondaryCoordinator by some reason has no effect (just nothing happens, no crashes, no console logs), while it works perfectly fine in iOS 14.5 and iOS 15. The issue is reproducible on simulators with Xcode 13.4.Here's a full source code of an app that illustrates the issue:
Tapping on the "Open secondary view" button has no effect in iOS 14.4 simulator, but works well in iOS 14.5 and iOS 15. I was not able to confirm if it's reproducible on a physical device because I don't have any devices running that particular iOS version.
Interestingly enough, if I just get rid of the MainCoordinator and instantiate ContentViewCoordinator right in the App's body, it starts working fine on iOS 14.4.
The full source code of the example app is also available on GitHub: https://github.com/vadimbelyaev/StinsenNavigationIssueExample
Let me know if I can provide any additional info that can help resolving the issue.