Skip to content

Commit a1153a1

Browse files
author
Trent Guillory
committed
Works in a tabview
1 parent d8194de commit a1153a1

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

ScrollViewReactiveHeaderDemoApp/Sources/ContentView.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ struct ContentView: View {
77

88
var body: some View {
99

10-
// TabView {
11-
//
12-
// StoryListView()
13-
// .tabItem {
14-
// VStack {
15-
// Image(systemName: "book")
16-
// Text("Reader")
17-
// }
18-
// }
19-
// }
20-
VStack {
21-
StoryListView()
10+
TabView {
11+
12+
StoryListView()
13+
.tabItem {
14+
VStack {
15+
Image(systemName: "book")
16+
.foregroundColor(.gray)
17+
Text("Reader")
18+
.foregroundColor(.gray)
19+
}
20+
}
2221
}
23-
22+
.preferredColorScheme(.light)
2423
}
2524
}
2625

ScrollViewReactiveHeaderDemoApp/Sources/Example3/StoryList/Views/StoryListContentView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ struct StoryListContentView: View {
99
var body: some View {
1010

1111
VStack {
12-
13-
VStack {}
14-
.frame(height: 300)
1512

1613
ForEach(viewModel.stories) { story in
1714

1815
StoryListCell(viewModel: story)
1916
}
17+
18+
ForEach(viewModel.stories) { story in
19+
20+
StoryListCell(viewModel: story)
21+
}
2022
}.padding()
2123
}
2224
}

ScrollViewReactiveHeaderDemoApp/Sources/Example3/StoryList/Views/StoryListHeaderOverlay.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct StoryListHeaderOverlay: View {
1010

1111
VStack(alignment: .center) {
1212

13+
Spacer()
14+
1315
ZStack {
1416

1517
Rectangle()
@@ -23,6 +25,8 @@ struct StoryListHeaderOverlay: View {
2325
.font(.system(size: 32, weight: .semibold, design: .serif))
2426
.frame(maxWidth: .infinity)
2527
}
28+
29+
Spacer()
2630
}
2731
}
2832
}

ScrollViewReactiveHeaderDemoApp/Sources/Example3/StoryListView.swift

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,15 @@ struct StoryListView: View {
1313
ScrollViewReactiveHeader(header: {
1414

1515
HeaderView()
16+
.frame(height: 300)
1617
}, headerOverlay: {
1718

1819
StoryListHeaderOverlay(header: viewModel.header)
20+
.frame(height: 300)
1921
}, body: {
2022

2123
StoryListContentView(viewModel: viewModel)
2224
})
23-
24-
// ScrollView {
25-
//
26-
// VStack {
27-
//
28-
// HeaderView()
29-
// .background(GeometryReaderOverlay())
30-
//
31-
// StoryListHeaderOverlay(header: viewModel.header)
32-
//
33-
// StoryListContentView(viewModel: viewModel)
34-
//
35-
// }
36-
// }
37-
// .onPreferenceChange(ScrollViewHeaderKey.self) { preferenceData in
38-
//
39-
// print(preferenceData.rect.height)
40-
// }
4125
}
4226
}
4327

@@ -51,7 +35,6 @@ struct HeaderView: View {
5135
.resizable()
5236
.aspectRatio(contentMode: .fill)
5337
.opacity(0.35)
54-
.frame(height: 300)
5538
}
5639
}
5740

0 commit comments

Comments
 (0)