Hello,
On the recent iOS / iPadOS 16, SwiftUI 4, and Xcode Version 14.0 beta (14A5228q), my app contains a NavigationStack within the content view; and the stack contains a ForEach that iterates over a list of fruits / items. The form loop outputs a navigation link, the label being a view, and the destination being another NavigationStack. And whenever I go to click on that link, the app shoots me back to the root view instantly. This seems to happen whenever I have any kind of content in the StackNavigation that's within the NavigationLink. I will post the code snippets below, along with a GIF showing the bug in action.
ContentView.Swift:
struct ContentView: View {
@State private var isShowingSettings: Bool = false
var fruits: [Fruit] = fruitsData
var body: some View {
NavigationStack {
List(fruits.shuffled()) { fruit in
NavigationLink(destination: FruitDetailView(fruit: fruit)) {
FruitRowView(fruit: fruit)
.padding(.vertical, 4)
}
}
.navigationBarTitle("Fruits")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
isShowingSettings = true
}) {
Image(systemName: "slider.horizontal.3")
}
.sheet(isPresented: $isShowingSettings) {
SettingsView()
}
}
}
}
}
}
FruitDetailView.Swift:
// Code is shortened, but has the same bug as the actual code
struct FruitDetailView: View {
var fruit: Fruit
var body: some View {
NavigationStack {
ScrollView(.vertical, showsIndicators: false) {
Text(fruit.name)
}
.edgesIgnoringSafeArea(.top)
}
}
Preview: