Post

Replies

Boosts

Views

Activity

Programmatically expand a list in SwiftUI 2
Hi there, I have a question regarding the new expandable lists in SwiftUI 2. When I create a sidebar with an expandable list its collapsed by default. Is there any way to either programmatically expand certain items via a binding or to store the expansions so that the app will remember which items where expanded after the app is opened again? Here is my code: struct SidebarMenu2: Identifiable {     let id: String     let title: String     let icon: String?     let action: (() -> Void)?     var menues: [SidebarMenu2]?     init(title: String, icon: String? = nil, action: @escaping () -> Void) {         self.id = title         self.title = title         self.icon = icon         self.action = action         self.menues = nil     }     init(title: String, icon: String? = nil, menues: [SidebarMenu2]?) {         self.id = title         self.title = title         self.icon = icon         self.action = nil         self.menues = menues     } } struct Sidebar2: View {     var menu: [SidebarMenu2] { [         SidebarMenu2(             title: "My Library",             menues: [                 SidebarMenu2(title: "Profiles", icon: "person.fill") {                     print("Profiles")                 },                 SidebarMenu2(title: "Categories", icon: "tray.full.fill") {                     print("Profiles2")                 },             ]         )]     }     var body: some View {         VStack(alignment: .leading) {             List(menu, children: \.menues) { menu in                 Label(menu.title, systemImage: menu.icon!)             }         }     } }
0
0
1.5k
Jul ’20
Are NavigationLinks broken?
Hi, with the previous beta all navigation links place within a toolbar like view.toolbar { ToolbarItem(placement: .navigationBarTrailing) { NavigationLink(destination: SearchView()) { Label("Search", systemImage: "magnifyingglass").font(.title2) } } } stopped working. Buttons still worked though. As a temporary solution I placed on my toolbar items into a Menu like view.toolbar { ToolbarItem(placement: .navigationBarTrailing) { Menu { NavigationLink(destination: SearchView()) { Label("Search", systemImage: "magnifyingglass").font(.title2) } } label: { Image(systemName: "ellipsis.circle").imageScale(.large) } } Now, in beta 5 this has stopped working as well. Again buttons still work and placing navigation links outside of the navigation bar works as well. Does anyone else have this issue?
2
0
1.6k
Aug ’20