Giter Site home page Giter Site logo

Comments (6)

stefangerard avatar stefangerard commented on May 20, 2024 2

I had the same issue. It's because of the ScrollView inside the Grid. ScrollView can not be initialized with an empty array.
In my opinion it is a bug and Apple should fix it.

A workaround is to check if the data are empty or not. See following link.
https://forums.raywenderlich.com/t/swiftui-dont-update-scrollview-content-via-api/88875/4

For now I am using a copy of QGrid in my Project and I modified it like this (see 3rd line):

    public var body: some View {
        GeometryReader { geometry in
            if !self.data.isEmpty {
                ScrollView(showsIndicators: false) {
                    VStack(spacing: self.vSpacing) {
                        ForEach((0..<self.rows).map { JGridIndex(id: $0) }) { row in
                            self.rowAtIndex(row.id * self.cols,
                                            geometry: geometry)
                        }
                        // Handle last row
                        if self.data.count % self.cols > 0 {
                            self.rowAtIndex(self.cols * self.rows,
                                            geometry: geometry,
                                            isLastRow: true)
                        }
                    }
                }
                .padding(.horizontal, self.hPadding)
                .padding(.vertical, self.vPadding)
            }
        }
    }

from qgrid.

Svantulden avatar Svantulden commented on May 20, 2024 2

If I take the example from the first post here:

struct ContentView: View {
	
	@ObservedObject var viewModel = ContentViewModel()
	
	var body: some View {
		VStack {
			Button("Get all values") {
				self.viewModel.tap()
			}
			Text(String(self.viewModel.models.count))
			QGrid(self.viewModel.models, columns: 3) {
				GridCell(value: $0)
			}.id(UUID())
		}
	}
}

This seemed to work for me

from qgrid.

brandFromNSK avatar brandFromNSK commented on May 20, 2024

Anyway, I think QGrid should have any workaround

from qgrid.

Svantulden avatar Svantulden commented on May 20, 2024

Somehow, adding .id(UUID() to the QGrid view worked for me 🤔. Don't know why, because the empty scrollview would be the logical explanation for my case too, as I also load the data asynchronously, so the array is empty as first.

from qgrid.

mightyquinn408 avatar mightyquinn408 commented on May 20, 2024

@Svantulden Where did you add .id(UUID() to the QGrid?

from qgrid.

chabose avatar chabose commented on May 20, 2024

WA mentioned above leads unpredicted behavior on tap gestures for me
Also, I found It can be avoided by checking if data is empty on the library.
I will send a pull request shortly.

from qgrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.