-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecksView.swift
80 lines (73 loc) · 2 KB
/
DecksView.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
73
74
75
76
77
78
79
80
import SwiftUI
struct DecksView: View {
static let horizontalPadding: CGFloat = 23
@EnvironmentObject var currentStore: CurrentStore
@Binding var isDeckOptionsPopUpShowing: Bool
@Binding var selectedSection: Deck.Section?
@Binding var isSectionOptionsPopUpShowing: Bool
let isSectionExpanded: (Deck.Section) -> Bool
let toggleSectionExpanded: (Deck.Section, User) -> Void
var selectedDeck: Deck {
if currentStore.selectedDeck == nil {
currentStore.selectedDeck = currentStore.user.decks.first
}
return currentStore.selectedDeck!
}
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .top) {
HomeViewTopGradient(
addedHeight: geometry.safeAreaInsets.top
)
.edgesIgnoringSafeArea(.all)
VStack {
DecksViewTopControls(
selectedDeck: self.selectedDeck,
isDeckOptionsPopUpShowing: self.$isDeckOptionsPopUpShowing
)
VStack(spacing: 0) {
ZStack {
Rectangle()
.foregroundColor(.lightGrayBackground)
ScrollView {
DecksViewSections(
selectedDeck: self.selectedDeck,
selectedSection: self.$selectedSection,
isSectionOptionsPopUpShowing: self.$isSectionOptionsPopUpShowing,
isSectionExpanded: self.isSectionExpanded,
toggleSectionExpanded: self.toggleSectionExpanded
)
.frame(maxWidth: .infinity)
.padding(
[.horizontal, .bottom],
Self.horizontalPadding
)
.padding(.top)
}
}
DecksViewBottomControls(
selectedDeck: self.selectedDeck
)
}
}
}
}
.onAppear {
self.selectedDeck.loadSections()
}
}
}
#if DEBUG
struct DecksView_Previews: PreviewProvider {
static var previews: some View {
DecksView(
isDeckOptionsPopUpShowing: .constant(false),
selectedSection: .constant(nil),
isSectionOptionsPopUpShowing: .constant(false),
isSectionExpanded: { _ in true },
toggleSectionExpanded: { _, _ in }
)
.environmentObject(PREVIEW_CURRENT_STORE)
}
}
#endif