Q-Mobile / QGrid

🎛 QGrid: The missing SwiftUI collection view.
MIT License
1.64k stars 104 forks source link

Demo of QGridTestApp problem #20

Closed writing-shed closed 4 years ago

writing-shed commented 4 years ago

If you embed the ZStack in a List as in the following:

var body: some View {
    GeometryReader { geometry in
        List {
            ZStack {
                self.backgroundGradient
                    .edgesIgnoringSafeArea(.all)
                VStack {
                    if (QConstants.showDesigner) { self.designerView(geometry) }
                    self.gridView(geometry)
                }
            }
        }
    }
}

Then you get this in the simulator:

Screenshot 2019-11-12 at 12 42 31

I have tried various experiments and the best I can come up with is to add a frame modifier as in:

var body: some View {
    GeometryReader { geometry in
        List {
            ZStack {
                self.backgroundGradient
                    .edgesIgnoringSafeArea(.all)
                VStack {
                    if (QConstants.showDesigner) { self.designerView(geometry) }
                    self.gridView(geometry)
                    .frame(width: geometry.size.width,
                           height: geometry.size.height)
                }
            }
        }
    }
}

But this is still wrong because the grid is in the wrong place (see screenshot) and I can't work out how to fix it. Any ideas?

Screenshot 2019-11-12 at 12 50 06
karolkulesza commented 4 years ago

Hi there,

ZStack is used here just for specifying the background gradient, so if you'd like to embed the content in a List view, you should rather do something like this:

  var body: some View {
    GeometryReader { geometry in
      ZStack {
        self.backgroundGradient
        .edgesIgnoringSafeArea(.all)
        List {
          self.gridView(geometry)
            .frame(height: geometry.size.height)
        }
      }
    }
  }

This assumes that you'd like the grid to occupy the whole screen. (in case of embedding it in a List you have to explicitly set QGrid's height. Not sure, however, what is your purpose of embedding it in a List, especially that there might be a conflict of vertical scrolling gestures in such case (embedding QGrid in a List)