4.5 C
New York
Monday, January 13, 2025

ios – Spacer in LazyVStack doesn’t occupy all out there house


I’m attempting to make a listing utilizing LazyVStack the place the content material occupies the whole house with a footer that can keep on the backside of the display screen. Nevertheless, if the checklist has many objects, it ought to occupy the whole thing of the display screen with the footer exhibiting solely when the person has scrolled to the underside of the checklist (so pinned view/sticky footer).

Here is a code snippet to demo what I am at present seeing:

struct ContentView: View {
  @Bindable var viewModel: MockViewModel // Simply comprises an array of knowledge
  
    var physique: some View {
      GeometryReader { reader in
        ScrollView {
          VStack { // Replace this to LazyVStack
            if viewModel.dataSet.isEmpty {
              EmptyListView()
            } else {
              ForEach(viewModel.dataSet, id: .id) { viewData in
                VStack(spacing: 0) {
                  DataCell(viewData: viewData)
                    .background()
                    .padding(.backside, 16)
                  if (viewData.id != viewModel.dataSet.final?.id) {
                    Divider()
                  }
                }
              }
            }

            /* Footer that will increase to take up any unused house */
            VStack(spacing: 0) {
              Spacer()
              FooterView()
            }.body(maxHeight: .infinity, alignment: .backside)
          }.background()
            .body(minHeight: reader.measurement.peak)
        }
      }.ignoresSafeArea(edges:.backside)
    }
}

What the checklist would appear to be if it was crammed with knowledge.

What the checklist would appear to be as soon as it reached the underside.

What the checklist would appear to be if it contained just one merchandise. That is utilizing the VStack.

Nevertheless, that is what I see with utilizing a LazyVStack. It looks like the Spacer element does not increase to fill out there house.

With the code included (utilizing a VStack), I’m capable of obtain the outcomes I’m in search of. Nevertheless, with a LazyVStack, it looks like the Spacer all the time leads to a peak of 0. I get the identical end result as if the identical content material was positioned within a Record. Is there a technique to obtain what we’re in search of in a LazyVStack? We quite be utilizing a LazyVStack to keep away from pre-rendering the whole view when it masses.

Any clues can be enormously appreciated! Thanks.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles