Post

Replies

Boosts

Views

Activity

SwiftUI Hierarchical List on macOS represents incorrect results.
A item is replaced by the last uncle. Conditions are: Target to macOS The item "X" is placed next to the folded sibling with children. The parent of the "X" is not the last sibling. The last uncle "Y" has no children. then, "X" will be replaced by "Y", and "Y" appears twice. It's amazing that the very fundamental operations are broken. As this issue only occurs on macOS, it is not reproduced on playground preview or iOS. import SwiftUI struct TreeViewTest: View {     var items: [Item]     var body: some View {         List(             items,             children: \.children         ) { item in             Text(item.id)         }     }     struct Item: Hashable, Identifiable {         var id: String         var children: [Self]?     } } struct TreeViewTest_Previews: PreviewProvider {     static var previews: some View {         TreeViewTest(items: [             .init(id: "0", children: [                 .init(id: "00"),                 .init(id: "01", children: [                     .init(id: "010"),                     .init(id: "011"),                     .init(id: "012")                 ]),                 .init(id: "02"),                 .init(id: "03")             ]),             .init(id: "1")         ])     } } It represents: 0 -00 +01 -1 /* <- should be 02 */ -03 1 Is there anything wrong with my code? If it is a bug, is there a temporary hacky workaround?
1
1
822
Nov ’20
.itemProvider in OutlineGroup is not working on macOS
OutlineGroup in List: Not Work Hierarchical List: Not Work Pure List: Work Is it a bug or SwiftUI doesn't support it yet? Should I use cocoa OutlineView for this feature? Reproduce: Copy and Paste code below, and drag items. import SwiftUI import PlaygroundSupport var greeting = "Hello, playground" struct FileItem: Hashable, Identifiable {     var id: Self { self }     var name: String     var children: [FileItem]? = nil } let data = FileItem(name: "users", children: [FileItem(name: "user1234", children:     [FileItem(name: "Photos", children:       [FileItem(name: "photo001.jpg"), FileItem(name: "photo002.jpg")]),      FileItem(name: "Movies", children:          [FileItem(name: "movie001.mp4")]),           FileItem(name: "Documents", children: [])]),      FileItem(name: "newuser", children:        [FileItem(name: "Documents", children: [])])]) struct ContentView: View {     var body: some View {         VStack {             Text("Not Work - OutlineGroup in List")             List {                 OutlineGroup(data, children: \.children) { item in                     Text("\(item.name)")                         .itemProvider { NSItemProvider(object: item.name as NSString) }                 }             }             Text("Not Work - Hierarchical List")             List {                 OutlineGroup(data, children: \.children) { item in                     Text("\(item.name)")                         .itemProvider { NSItemProvider(object: item.name as NSString) }                 }             }             Text("Work - Pure List")             List([                 FileItem(name: "Documents", children: []),                 FileItem(name: "Files", children: [])             ]) { item in                 Text("\(item.name)")                     .itemProvider { NSItemProvider(object: item.name as NSString) }             }         }         .frame(width: 320, height: 800)     } } PlaygroundPage.current.setLiveView(ContentView())
0
0
386
Nov ’21