-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContainerRelativeFrame.swift
41 lines (37 loc) · 1.36 KB
/
ContainerRelativeFrame.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
import SwiftUI
struct ContainerRelativeFrame: View {
@State var data = FakeItem.build(20)
var body: some View {
VStack {
horizontalScrollView(splitScreenInto: 5, splitForOneItem: 2)
horizontalScrollView(splitScreenInto: 10, splitForOneItem: 2)
}
.frame(maxHeight: .infinity, alignment: .top)
}
@ViewBuilder
func horizontalScrollView(splitScreenInto count: Int, splitForOneItem span: Int) -> some View {
VStack {
headerViewForScrollView(splitCount: count, span: span)
ScrollView(.horizontal) {
HStack {
ForEach(data) { item in
Text(item.id.description)
.padding()
.frame(maxWidth: .infinity)
.background(Color.red)
// 1: As the method description says, the count will represent the number of splits that the screen is
// divided to, and the span will represent the number of visible splits for one item.
.containerRelativeFrame(.horizontal, count: count, span: span, spacing: 8)
}
}
}
}
}
@ViewBuilder
func headerViewForScrollView(splitCount: Int, span: Int) -> some View {
Text("Screen is divided in \(splitCount) splits, and a single cell fills \(span) splits.")
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
}
}