@@ -19,31 +19,39 @@ struct SettingsInfoViewModelPage: Hashable {
19
19
20
20
struct SettingsInfoView : View {
21
21
let viewModel : SettingsInfoViewModel
22
- @State var height : CGFloat = 0
23
22
24
23
// Extra spacing to allow for some room around the page indicators.
25
24
var pageIndicatorSpacing : CGFloat {
26
25
viewModel. pages. count > 1 ? 72 : 24
27
26
}
28
27
29
28
var body : some View {
30
- TabView {
31
- ForEach ( viewModel. pages, id: \. self) { page in
32
- VStack {
33
- contentView ( for: page)
34
- Spacer ( )
29
+ ZStack {
30
+ // Renders (and hide) the content of each page, to push the view to the maximum possible size.
31
+ VStack {
32
+ ZStack {
33
+ ForEach ( viewModel. pages, id: \. self) { page in
34
+ contentView ( for: page)
35
+ }
35
36
}
36
- . padding ( UIMetrics . SettingsInfoView. layoutMargins)
37
+ Spacer ( )
38
+ . frame ( height: pageIndicatorSpacing)
39
+ }
40
+ . hidden ( )
41
+ TabView {
42
+ ForEach ( viewModel. pages, id: \. self) { page in
43
+ VStack {
44
+ contentView ( for: page)
45
+ Spacer ( )
46
+ }
47
+ . padding ( UIMetrics . SettingsInfoView. layoutMargins)
48
+ }
49
+ }
50
+ . tabViewStyle ( . page)
51
+ . foregroundColor ( Color ( . primaryTextColor) )
52
+ . background {
53
+ Color ( . secondaryColor)
37
54
}
38
- }
39
- . frame (
40
- height: height + pageIndicatorSpacing
41
- )
42
- . tabViewStyle ( . page)
43
- . foregroundColor ( Color ( . primaryTextColor) )
44
- . background {
45
- Color ( . secondaryColor)
46
- preRenderViewSize ( )
47
55
}
48
56
}
49
57
@@ -57,23 +65,6 @@ struct SettingsInfoView: View {
57
65
. opacity ( 0.6 )
58
66
}
59
67
}
60
-
61
- // Renders the content of each page, determining the maximum height between them
62
- // when laid out on screen. Since we only want this to update the real view
63
- // this function should be called from a .background() and its contents hidden.
64
- private func preRenderViewSize( ) -> some View {
65
- ZStack {
66
- ForEach ( viewModel. pages, id: \. self) { page in
67
- contentView ( for: page)
68
- }
69
- }
70
- . hidden ( )
71
- . sizeOfView { size in
72
- if size. height > height {
73
- height = size. height
74
- }
75
- }
76
- }
77
68
}
78
69
79
70
#Preview( " Single page " ) {
0 commit comments