Skip to content

Commit

Permalink
Fix problem with disclosure groups randomly not disclosing by replaci…
Browse files Browse the repository at this point in the history
…ng with custom component

- 99% of the code is the same as we were already massively customising it
  • Loading branch information
stefanceriu committed Jul 25, 2023
1 parent ec76701 commit 9f4479b
Showing 1 changed file with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,24 @@ struct CollapsibleRoomTimelineView: View {
private let groupedViewStates: [RoomTimelineItemViewState]

@State private var isExpanded = false

init(timelineItem: CollapsibleTimelineItem) {
self.timelineItem = timelineItem
groupedViewStates = timelineItem.items.map { .init(item: $0, groupStyle: .single) }
}

var body: some View {
DisclosureGroup(L10n.roomTimelineStateChanges(timelineItem.items.count), isExpanded: $isExpanded) {
Group {
ForEach(groupedViewStates) { viewState in
RoomTimelineItemView(viewState: viewState)
}
}
}
.disclosureGroupStyle(CollapsibleRoomTimelineItemDisclosureGroupStyle())
}
}

private struct CollapsibleRoomTimelineItemDisclosureGroupStyle: DisclosureGroupStyle {
func makeBody(configuration: Configuration) -> some View {
VStack(spacing: 0.0) {
Button {
withElementAnimation {
configuration.isExpanded.toggle()
isExpanded.toggle()
}
} label: {
HStack(alignment: .center) {
configuration.label
Text(L10n.roomTimelineStateChanges(timelineItem.items.count))
Text(Image(systemName: "chevron.forward"))
.rotationEffect(.degrees(configuration.isExpanded ? 90 : 0))
.animation(.elementDefault, value: configuration.isExpanded)
.rotationEffect(.degrees(isExpanded ? 90 : 0))
.animation(.elementDefault, value: isExpanded)
}
.font(.compound.bodySM)
.foregroundColor(.compound.textSecondary)
Expand All @@ -63,8 +50,10 @@ private struct CollapsibleRoomTimelineItemDisclosureGroupStyle: DisclosureGroupS
.frame(maxWidth: .infinity)
.padding(.top, 8.0)

if configuration.isExpanded {
configuration.content
if isExpanded {
ForEach(groupedViewStates) { viewState in
RoomTimelineItemView(viewState: viewState)
}
}
}
}
Expand Down

0 comments on commit 9f4479b

Please sign in to comment.