Issue #837
I usually use GeometryReader
in background
to get size of view, and encapsulate it inside a ViewModifier
struct GetHeightModifier: ViewModifier {
@Binding var height: CGFloat
func body(content: Content) -> some View {
content.background(
GeometryReader { geo -> Color in
DispatchQueue.main.async {
height = geo.size.height
}
return Color.clear
}
)
}
}
This is useful to constrain NavigationView
height when in use inside a bottom sheet
struct FilterView: View {
@State private var height: CGFloat = 0
var body: some View {
BottomSheet {
NavigationView {
VStack {
Text("content")
}
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
.modifier(GetHeightModifier(height: $height))
}
.frame(height: height)
}
}
}