How to calculate remaining available vertical space

Viewed 164

I have a few VStacks in my SwiftUI ContentView and I'm wondering how calculate remaning vertical space at the bottom of screen. Reason is to draw chart there and I need to know y-axis scale. Thanks.

1 Answers

Here is a demo of possible approach - use GeometryReader that consumes all available space and gives metrics

struct DemoView: View {
    @State private var height = CGFloat.zero

    var body: some View {
        VStack {
            View1()
            View2()
 
            // GeometryReader consumes all remaining space here
            GeometryReader { gp in

               // use gp.size here

            }
        }
    }
}

Related