Files
Nextcloud-Cookbook-iOS/Nextcloud Cookbook iOS Client/Views/ReusableViews/CollapsibleView.swift
VincentMeilinger 10cb851a5a Code cleanup
2024-01-25 22:51:08 +01:00

51 lines
1.3 KiB
Swift

//
// CollapsibleView.swift
// Nextcloud Cookbook iOS Client
//
// Created by Vincent Meilinger on 15.12.23.
//
import Foundation
import SwiftUI
struct CollapsibleView<C: View, T: View>: View {
@State var titleColor: Color = .white
@State var isCollapsed: Bool = true
@State var content: () -> C
@State var title: () -> T
@State private var rotationAngle: Double = -90
var body: some View {
VStack(alignment: .leading) {
Button {
withAnimation(.easeInOut(duration: 0.2)) {
isCollapsed.toggle()
if isCollapsed {
rotationAngle += 90
} else {
rotationAngle -= 90
}
}
rotationAngle = isCollapsed ? -90 : 0
} label: {
HStack {
Image(systemName: "chevron.down")
.bold()
.rotationEffect(Angle(degrees: rotationAngle))
title()
}.foregroundStyle(titleColor)
}
if !isCollapsed {
content()
.padding(.top)
}
}
.onAppear {
rotationAngle = isCollapsed ? -90 : 0
}
}
}