-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFoldView.swift
74 lines (58 loc) · 1.71 KB
/
FoldView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// FoldView.swift
// Foldable List
//
// Created by gwwo on 27/7/2022.
//
import SwiftUI
struct FoldView: View {
@EnvironmentObject var list: ListModel
var content: EntryContent?
var role: FoldRole
var degree: Double
var height: CGFloat = 60
@State private var dynamic: FoldDynamic = FoldDynamic(degree: 90, height: 0)
var body: some View {
Button(action: {
if let content = content {
list.tap(entry: content.entry)
}
}) {
VStack(spacing: 0){
Rectangle().fill(Color.gray.opacity(0.2)).frame(height: role.needTopBorder ? 1 : 0)
EntryView(content: dynamic.degree > 84 ? nil : content)
}
.frame(height: role.needTopBorder ? height : height - 1)
.contentShape(Rectangle())
}
.buttonStyle(FoldButtonStyle())
.padding(.bottom, role.bottomPadding)
.backgroundColor(.white)
.fold(for: role, to: degree, updating: $dynamic)
.drawingGroup()
.frame(height: dynamic.height, alignment: role.alignment)
.disabled(list.state != .unfolded)
}
}
struct FoldButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
ZStack{
configuration.label
Color.gray.opacity(configuration.isPressed ? 0.3: 0)
}
}
}
extension View {
func backgroundColor(_ color: Color) -> some View {
modifier(BackgroundView(color: color))
}
}
struct BackgroundView : ViewModifier{
let color: Color
func body(content: Content) -> some View {
ZStack {
color
content
}
}
}