mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-08-03 12:37:15 -04:00
Make first and single item non-collapsible
This commit is contained in:
parent
25bba5a23a
commit
1164425624
@ -86,20 +86,28 @@ struct Language: Identifiable, Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
class OutlineItem: ObservableObject, Identifiable {
|
||||
final class OutlineItem: ObservableObject, Identifiable {
|
||||
let id: String
|
||||
let index: Int
|
||||
let text: String
|
||||
let level: Int
|
||||
let isCollapsible: Bool
|
||||
private(set) var children: [OutlineItem]?
|
||||
|
||||
@Published var isExpanded = true
|
||||
|
||||
func asNonCollapsible() -> OutlineItem {
|
||||
let copy = OutlineItem(id: id, index: index, text: text, level: level, isCollapsible: false)
|
||||
copy.children = children
|
||||
return copy
|
||||
}
|
||||
|
||||
init(id: String, index: Int, text: String, level: Int) {
|
||||
init(id: String, index: Int, text: String, level: Int, isCollapsible: Bool = true) {
|
||||
self.id = id
|
||||
self.index = index
|
||||
self.text = text
|
||||
self.level = level
|
||||
self.isCollapsible = isCollapsible
|
||||
}
|
||||
|
||||
convenience init(index: Int, text: String, level: Int) {
|
||||
|
@ -760,10 +760,9 @@ final class BrowserViewModel: NSObject, ObservableObject,
|
||||
}
|
||||
}
|
||||
|
||||
// if there is only one h1, flatten one level
|
||||
// if there is only one h1, make the first item non collapsible
|
||||
if let rootChildren = root.children, rootChildren.count == 1, let rootFirstChild = rootChildren.first {
|
||||
let children = rootFirstChild.removeAllChildren()
|
||||
self.outlineItemTree = [rootFirstChild] + children
|
||||
self.outlineItemTree = [rootFirstChild.asNonCollapsible()]
|
||||
} else {
|
||||
self.outlineItemTree = root.children ?? []
|
||||
}
|
||||
|
@ -90,7 +90,8 @@ struct OutlineButton: View {
|
||||
|
||||
var body: some View {
|
||||
if let children = item.children {
|
||||
DisclosureGroup(isExpanded: $item.isExpanded) {
|
||||
let isExpanded = item.isCollapsible ? $item.isExpanded : .constant(true)
|
||||
DisclosureGroup(isExpanded: isExpanded) {
|
||||
ForEach(children) { child in
|
||||
OutlineNode(item: child, action: action)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user