Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Last active June 30, 2020 02:07
Show Gist options
  • Save prafullakumar/7b13b5c090e3573b781e6de8d09fdce0 to your computer and use it in GitHub Desktop.
Save prafullakumar/7b13b5c090e3573b781e6de8d09fdce0 to your computer and use it in GitHub Desktop.
ios -14 Collapsible List
// Created by Prafulla Singh on 29/6/20.
//
import SwiftUI
struct FamilyTree: Identifiable {
let id = UUID()
let name: String
let childrens: [FamilyTree]?
}
func generateData() -> [FamilyTree] {
return [FamilyTree.init(name: "A", childrens: [FamilyTree.init(name: "Aa", childrens: nil)]), FamilyTree.init(name: "B", childrens: [FamilyTree.init(name: "BB", childrens: nil)])]
}
struct DemoCollapsibleVIew: View {
let familyTreeRoot = generateData()
var body: some View {
List(familyTreeRoot, children: \.childrens) { familyTree in
Text(familyTree.name)
}
}
}
struct DemoCollapsibleVIew_Previews: PreviewProvider {
static var previews: some View {
DemoCollapsibleVIew()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment