I am having the same problem with code below:
import SwiftUI
struct MainView: View {
var body: some View {
NavigationView {
NavigationLink(destination: TestView()) {
MainButton(title: "Press Me")
}
.navigationTitle("Welcome")
}
.navigationViewStyle(.stack)
}
}
struct MainButton: View {
var title: String
var body: some View {
Text(title).font(.title)
}
}
struct TestView: View {
@State var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
List { ForEach(0..<100) { i in Text("Test Tab 0 row \(i)") } }
.listStyle(.plain)
.tag(0)
.navigationBarTitle("Page 1 Tab 1")
.tabItem {
Image(systemName: "face.smiling")
Text("tab1")
}
.tag(0)
List { ForEach(0..<20) { i in Text("Test Tab 1 row \(i)") } }
.listStyle(.plain)
.tag(1)
.navigationBarTitle("Page 1 Tab 2")
.tabItem {
Image(systemName: "face.smiling.inverse")
Text("tab2")
}
.tag(1)
}
.navigationTitle("Tab Views")
.background()
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}
I have .navigationViewStyle(.stack) next to NavigationView but still scrolling up and down the list does not trigger animation similar to animation when there is no TabView.
E.g. If I comment TabView in the code above, animations in NavigationBar are working correctly.
import SwiftUI
struct MainView: View {
var body: some View {
NavigationView {
NavigationLink(destination: TestView()) {
MainButton(title: "Press Me")
}
.navigationTitle("Welcome")
}
.navigationViewStyle(.stack)
}
}
struct MainButton: View {
var title: String
var body: some View {
Text(title).font(.title)
}
}
struct TestView: View {
@State var selectedTab = 0
var body: some View {
//TabView(selection: $selectedTab) {
List { ForEach(0..<100) { i in Text("Test Tab 0 row \(i)") } }
.listStyle(.plain)
.tag(0)
.navigationBarTitle("Page 1 Tab 1")
.tabItem {
Image(systemName: "face.smiling")
Text("tab1")
}
.tag(0)
/*List { ForEach(0..<20) { i in Text("Test Tab 1 row \(i)") } }
.listStyle(.plain)
.tag(1)
.navigationBarTitle("Page 1 Tab 2")
.tabItem {
Image(systemName: "face.smiling.inverse")
Text("tab2")
}
.tag(1)
}
.navigationTitle("Tab Views")
.background()*/
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}
Post
Replies
Boosts
Views
Activity
Have the same problem, as author of the post. Seems to me that NavigationLink is not working when editMode=.active. gesture helps to register tap on List item element, however, NavigationLink and transition to EditView still NOT handled as expected.
import SwiftUI
import PlaygroundSupport
struct DetailView: View {
var body: some View { Text("Hello DetailView World") }
}
struct EditView: View {
var body: some View { Text("Hello EditView World") }
}
struct ContentView: View {
@State var editMode: EditMode = .inactive
var body: some View {
NavigationView {
List {
Text("Testing EditMode")
ZStack {
if self.editMode == .active {
NavigationLink(destination: EditView()) {
Text("Go To Edit View")
.gesture(tapGesture)
}
.padding()
} else {
NavigationLink(destination: DetailView()) {
Text("Go To Detail View")
}
.padding()
}
}
}
.navigationBarTitle("EditMode Problem")
.navigationBarItems(trailing: EditButton())
.environment(\.editMode, $editMode)
}
}
var tapGesture: some Gesture {
TapGesture().onEnded{
print("Tap In Go To Detail View")
}
}
}
PlaygroundPage.current.setLiveView(ContentView())