Open onmyway133 opened 3 years ago
I usually use GeometryReader in background to get size of view, and encapsulate it inside a ViewModifier
GeometryReader
background
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
NavigationView
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) } } }
I usually use
GeometryReader
inbackground
to get size of view, and encapsulate it inside aViewModifier
This is useful to constrain
NavigationView
height when in use inside a bottom sheet