-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTalksScreen.swift
74 lines (66 loc) · 2.63 KB
/
TalksScreen.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
import SwiftUI
struct TalksScreen: View {
/// `true` if the footer should be stuck to the bottom of the screen.
var isFooterStuckToBottom: Bool {
scrollingFooterFrame.minY < stuckToBottomFooterFrame.minY
}
/// The frame of the scrollable footer view.
@State var scrollingFooterFrame: CGRect = .zero
/// The frame of the non-scrollable footer view.
@State var stuckToBottomFooterFrame: CGRect = .zero
@Namespace var namespace
@State var selectedTalk: Talk? = nil
var body: some View {
ZStack(alignment: .bottom) {
if let talk = selectedTalk {
DetailScreen(namespace: namespace, talk: talk)
.navigationBarItems(trailing: HStack {
Button(
action: { tapTalk(nil) },
label: { Text("Done") }
)
})
.navigationBarBackButtonHidden(true)
} else {
ScrollView {
VStack(spacing: 0) {
HeaderContentView()
ForEach(Talk.list) { talk in
TalkView(title: talk.title, date: talk.date) {
Image(talk.imageName)
.resizable()
.imageScale(.large)
.clipShape(Circle())
.overlay(
Circle()
.stroke(.gray, lineWidth: 1)
)
.matchedGeometryEffect(id: talk.imageName, in: namespace)
.frame(width: smallImageSize, height: smallImageSize)
}
.onTapGesture {
tapTalk(talk)
}
}
FooterView()
.readFrame(into: $scrollingFooterFrame)
.opacity(isFooterStuckToBottom ? 0 : 1)
}
}
FooterView()
.readFrame(into: $stuckToBottomFooterFrame)
.opacity(isFooterStuckToBottom ? 1 : 0)
}
}
}
func tapTalk(_ talk: Talk?) {
withAnimation(.easeInOut(duration: 0.3)) { self.selectedTalk = talk }
}
}
struct ListScreen_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
TalksScreen()
}
}
}