Post

Replies

Boosts

Views

Activity

Reply to Section(isExpanded:) bug on macOS?
Here's an interesting little gotcha. If I initialize the expansion bools to FALSE, like so: @State private var isExpanded_1 = false @State private var isExpanded_2 = false then the Sections don't expand although the chevrons toggle. By the way, what OS version are you running?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Section(isExpanded:) bug on macOS?
Hmm, the reply won't fit in 500 characters so I have to reply out-of-line. FWIW, I'm not seeing a disclosure chevron with .listStyle(.sidebar). Here's the code for SummaryHeader and Expander: struct Expander: View { @Binding var isExpanded: Bool var body: some View { Button { isExpanded.toggle() } label: { Image(systemName: (isExpanded) ? "chevron.down" : "chevron.right") } .buttonStyle(PlainButtonStyle()) .padding(EdgeInsets(top: 6, leading: 6, bottom: 0, trailing: 6)) .accessibilityLabel(Text((isExpanded) ? "Show" : "Hide")) } } struct SummaryHeader: View { @Binding var isSummaryExpanded: Bool var body: some View { HStack { Expander(isExpanded: $isSummaryExpanded) Text("Summary") .font(.headline) Text(isSummaryExpanded ? "expanded" : "collapsed") Spacer() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Section(isExpanded:) bug on macOS?
I used a VStack because I usually associate a List with a homogeneous set of values a.o.t. a VStack which seems to be a more heterogeneous grouping. (I'm still newish to SwiftUI so I try to keep things simple for my own sake.) I tried using a List per your suggestion but retaining the header: and, interestingly, the "toggling" of both isExpanded bools now work but the Section bodies don't collapse. Also, the second Section looks to be "graphically subordinate" with relation to the first Section (i.e. the first Section's header divider is drawn all the way to the left edge of the containing view but the second Section's divider is drawn indented - go figure). List { Section(isExpanded: $isExpanded_1) { Text("Working section") } header: { SummaryHeader(isSummaryExpanded: $isExpanded_1) } Section(isExpanded: $isExpanded_2) { Text("Broken section") } header: { SummaryHeader(isSummaryExpanded: $isExpanded_2) } Spacer() } FWIW, I want/need to use header: because it contains the disclosure chevron that toggles the isExpanded bool. FWIW#2, I'm using this instead of a DisclosureGroup because DisclosureGroups seem to have their own set of problems.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Xcode 15 assert when running app
Adding to my own reply, curiously it (having nested NavigationSplitViews) seemed to work fine in Playgrounds. Maybe it's triggering an assertion that only shows up when debugging in Xcode and is suppressed when running in Playgrounds (i.e. a less severe form of debugging).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Xcode 15 assert when running app
Yes, I did have nested NavigationSplitViews. I ended up working around the crash by replacing the inner NavigationSplitView with a different navigation mechanism. I figured that having nested NavigationSplitViews might not be a supported configuration. It's not as if it's well documented.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23