NavigationLinks don’t open with List with selection inside NavigationStack. Toolbar between views inside NavigationStack

Community!
I use in my Swift UI application for iOS NavigationViews (as .stack). Also I use nested NavigationView inside NavigationView and everything looked as I needed. But I decied to fefuse to use deprecated NavigationView and migrate to NavigationStack. But I got following issues.

I have 2 tabs (TabView). Each tab has NavigationStack with NavigationLinks. All content is wrapped inside NavigationStack because NavigationLink’s destination views must cover full screen.

Issue 1: I can’t show “toolbar” of List over List.
Insede first tab I have some content which cover top part of Screen. Under this content I have List with EditMode. And when user clicks “Edit button” than “toolbar” with actions for List items must be right over this List (not on the top of screen). With NavigationViews this was solved by using additional NavigationView inside “main” NavigationView. But NavigatioinStack doesn’t allow it.
How I can display “toolbar” with action buttons right over List?

Issue 2: NavigationLink does not work with NavigationStack if List (which is inside) use “selection”.
On the first tab NavigatonLinks inside List must follow to view with details (which can folow to other actions like “edit” etc). But for “EditMode” I have to use List with “selection”. And after adding “selection” NavigationLinks become “unclickable”. “Selection” (with editMode=.active) works but clicks (with editMode=.inactive) on NavigationLinks don’t work.

Thanks in advance for advices.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import SwiftUI
struct MyItemEntity: Hashable {let id: UUID, name: String}
struct TestNavigationStackView: View {
@Environment(.dismiss) var dismiss
@State private var selectedTab: Int = 0
@State var showSettingsOne: Bool = false
@State var showSettingsTwo: Bool = false
@State var showSettingsThree: Bool = false
@State var editModeList: EditMode = .inactive //<- Declare the @State var for editMode
var body: some View {
if #available(iOS 16.0, *) {
TabView(selection: $selectedTab) {
NavigationStack {
VStack {
VStack {
Text("Home view")
Text("Some content on top part")
Spacer()
Button("Edit item", systemImage: "pencil") {
editModeList = editModeList == .inactive ? .active : .inactive
}
.foregroundColor(editModeList == .active ? .gray : .accentColor)
}
.frame(width: .infinity, height: 200)
ItemsListView(editModeList: $editModeList)
}
}
.tabItem() {
Image(systemName: "house.fill")
}
.tag(0)
.navigationBarTitle("")
.navigationBarHidden(true)
NavigationStack {
List {
Button("Settings one") { showSettingsThree.toggle() }
Button("Settings two") { showSettingsThree.toggle() }
Button("Settings three") { showSettingsThree.toggle() }
}
.navigationDestination(isPresented: $showSettingsOne, destination: {
Text("Screen with settings one")
})
.navigationDestination(isPresented: $showSettingsTwo, destination: {
Text("Screen with settings two")
})
.navigationDestination(isPresented: $showSettingsThree, destination: {
Text("Screen with settings three")
})
}
.tabItem() {
Image(systemName: "gear")
}
.tag(1)
.navigationBarTitle("")
.navigationBarHidden(true)
}
} else {
// Fallback on earlier versions
}
}
}
struct ItemsListView: View {
@Binding var editModeList: EditMode
@State private var selectedItems = Set<MyItemEntity>()
var data = [
MyItemEntity(id: UUID(), name: "John"),
MyItemEntity(id: UUID(), name: "Bob"),
MyItemEntity(id: UUID(), name: "Jack"),
MyItemEntity(id: UUID(), name: "Garry"),
]
var body: some View {
if #available(iOS 16.0, *) {
// !!! Click on NavigationLink does not work (details don't open) if use "selection"
List(selection: self.$selectedItems) {
// List {
ForEach(data, id: .id) { item in
NavigationLink(value: item) {
Text(item.name)
}
.tag(item)
}
}
.navigationDestination(for: MyItemEntity.self) { item in
ItemDetailsView(item: item)
}
// !!! I need this toolbar right here - over this List (not on the top of the screen)
.toolbar(content: {
ToolbarItem(placement: .topBarLeading) {
Button("", systemImage: selectedItems.count == 0 ? "circle" : "xmark.circle.fill") {
if selectedItems.count == 0 {
data.forEach { item in selectedItems.insert(item) }
} else {
selectedItems = Set<MyItemEntity>()
}
} // select/deselect all items button
}
ToolbarItem { Button("", systemImage: "trash") {} }
ToolbarItem { Button("", systemImage: "tag") {} }
ToolbarItem { Button("", systemImage: "ellipsis") {} }
})
.environment(.editMode, $editModeList)
.navigationBarHidden(editModeList == .active ? false : true)
} else {
// Fallback on earlier versions
}
}
}
struct ItemDetailsView: View {
var item: MyItemEntity
var body: some View {
VStack {
Text("Item name: (item.name)")
Button("Edit") {}
}
}
}
#Preview {
TestNavigationStackView()
}
</code>
<code>import SwiftUI struct MyItemEntity: Hashable {let id: UUID, name: String} struct TestNavigationStackView: View { @Environment(.dismiss) var dismiss @State private var selectedTab: Int = 0 @State var showSettingsOne: Bool = false @State var showSettingsTwo: Bool = false @State var showSettingsThree: Bool = false @State var editModeList: EditMode = .inactive //<- Declare the @State var for editMode var body: some View { if #available(iOS 16.0, *) { TabView(selection: $selectedTab) { NavigationStack { VStack { VStack { Text("Home view") Text("Some content on top part") Spacer() Button("Edit item", systemImage: "pencil") { editModeList = editModeList == .inactive ? .active : .inactive } .foregroundColor(editModeList == .active ? .gray : .accentColor) } .frame(width: .infinity, height: 200) ItemsListView(editModeList: $editModeList) } } .tabItem() { Image(systemName: "house.fill") } .tag(0) .navigationBarTitle("") .navigationBarHidden(true) NavigationStack { List { Button("Settings one") { showSettingsThree.toggle() } Button("Settings two") { showSettingsThree.toggle() } Button("Settings three") { showSettingsThree.toggle() } } .navigationDestination(isPresented: $showSettingsOne, destination: { Text("Screen with settings one") }) .navigationDestination(isPresented: $showSettingsTwo, destination: { Text("Screen with settings two") }) .navigationDestination(isPresented: $showSettingsThree, destination: { Text("Screen with settings three") }) } .tabItem() { Image(systemName: "gear") } .tag(1) .navigationBarTitle("") .navigationBarHidden(true) } } else { // Fallback on earlier versions } } } struct ItemsListView: View { @Binding var editModeList: EditMode @State private var selectedItems = Set<MyItemEntity>() var data = [ MyItemEntity(id: UUID(), name: "John"), MyItemEntity(id: UUID(), name: "Bob"), MyItemEntity(id: UUID(), name: "Jack"), MyItemEntity(id: UUID(), name: "Garry"), ] var body: some View { if #available(iOS 16.0, *) { // !!! Click on NavigationLink does not work (details don't open) if use "selection" List(selection: self.$selectedItems) { // List { ForEach(data, id: .id) { item in NavigationLink(value: item) { Text(item.name) } .tag(item) } } .navigationDestination(for: MyItemEntity.self) { item in ItemDetailsView(item: item) } // !!! I need this toolbar right here - over this List (not on the top of the screen) .toolbar(content: { ToolbarItem(placement: .topBarLeading) { Button("", systemImage: selectedItems.count == 0 ? "circle" : "xmark.circle.fill") { if selectedItems.count == 0 { data.forEach { item in selectedItems.insert(item) } } else { selectedItems = Set<MyItemEntity>() } } // select/deselect all items button } ToolbarItem { Button("", systemImage: "trash") {} } ToolbarItem { Button("", systemImage: "tag") {} } ToolbarItem { Button("", systemImage: "ellipsis") {} } }) .environment(.editMode, $editModeList) .navigationBarHidden(editModeList == .active ? false : true) } else { // Fallback on earlier versions } } } struct ItemDetailsView: View { var item: MyItemEntity var body: some View { VStack { Text("Item name: (item.name)") Button("Edit") {} } } } #Preview { TestNavigationStackView() } </code>
import SwiftUI

struct MyItemEntity: Hashable {let id: UUID, name: String}

struct TestNavigationStackView: View {
    
    @Environment(.dismiss) var dismiss
    
    @State private var selectedTab: Int = 0
    
    @State var showSettingsOne: Bool = false
    @State var showSettingsTwo: Bool = false
    @State var showSettingsThree: Bool = false
    
    @State var editModeList: EditMode = .inactive //<- Declare the @State var for editMode
    
    var body: some View {
        if #available(iOS 16.0, *) {
            TabView(selection: $selectedTab) {
                NavigationStack {
                    VStack {
                        VStack {
                            Text("Home view")
                            Text("Some content on top part")
                            Spacer()
                            Button("Edit item", systemImage: "pencil") {
                                editModeList = editModeList == .inactive ? .active : .inactive
                            }
                            .foregroundColor(editModeList == .active ? .gray : .accentColor)
                        }
                        .frame(width: .infinity, height: 200)
                        ItemsListView(editModeList: $editModeList)
                    }
                }
                .tabItem() {
                    Image(systemName: "house.fill")
                }
                .tag(0)
                .navigationBarTitle("")
                .navigationBarHidden(true)
                
                NavigationStack {
                    List {
                        Button("Settings one") { showSettingsThree.toggle() }
                        Button("Settings two") { showSettingsThree.toggle() }
                        Button("Settings three") { showSettingsThree.toggle() }
                    }
                    .navigationDestination(isPresented: $showSettingsOne, destination: {
                        Text("Screen with settings one")
                    })
                    .navigationDestination(isPresented: $showSettingsTwo, destination: {
                        Text("Screen with settings two")
                    })
                    .navigationDestination(isPresented: $showSettingsThree, destination: {
                        Text("Screen with settings three")
                    })
                }
                .tabItem() {
                    Image(systemName: "gear")
                }
                .tag(1)
                .navigationBarTitle("")
                .navigationBarHidden(true)
            }
        } else {
            // Fallback on earlier versions
        }
    }
}

struct ItemsListView: View {
    
    @Binding var editModeList: EditMode
    @State private var selectedItems = Set<MyItemEntity>()
    
    var data = [
        MyItemEntity(id: UUID(), name: "John"),
        MyItemEntity(id: UUID(), name: "Bob"),
        MyItemEntity(id: UUID(), name: "Jack"),
        MyItemEntity(id: UUID(), name: "Garry"),
    ]
    
    var body: some View {
        if #available(iOS 16.0, *) {
            // !!! Click on NavigationLink does not work (details don't open) if use "selection"
            List(selection: self.$selectedItems) {
//            List {
                ForEach(data, id: .id) { item in
                    NavigationLink(value: item) {
                        Text(item.name)
                    }
                    .tag(item)
                }
            }
            .navigationDestination(for: MyItemEntity.self) { item in
                ItemDetailsView(item: item)
            }
            // !!! I need this toolbar right here - over this List (not on the top of the screen)
            .toolbar(content: {
                ToolbarItem(placement: .topBarLeading) {
                    Button("", systemImage: selectedItems.count == 0 ? "circle" : "xmark.circle.fill") {
                        if selectedItems.count == 0 {
                            data.forEach { item in selectedItems.insert(item) }
                        } else {
                            selectedItems = Set<MyItemEntity>()
                        }
                    } // select/deselect all items button
                }
                ToolbarItem { Button("", systemImage: "trash") {} }
                ToolbarItem { Button("", systemImage: "tag") {} }
                ToolbarItem { Button("", systemImage: "ellipsis") {} }
            })
            .environment(.editMode, $editModeList)
            .navigationBarHidden(editModeList == .active ? false : true)
        } else {
            // Fallback on earlier versions
        }
    }
}

struct ItemDetailsView: View {
    var item: MyItemEntity
    var body: some View {
        VStack {
            Text("Item name: (item.name)")
            Button("Edit") {}
        }
    }
}

#Preview {
    TestNavigationStackView()
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật