Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content not refreshed when creating new views #42

Open
razyalov opened this issue Jul 25, 2020 · 6 comments
Open

Content not refreshed when creating new views #42

razyalov opened this issue Jul 25, 2020 · 6 comments

Comments

@razyalov
Copy link

razyalov commented Jul 25, 2020

I have the QGrid setup to render a list of objects that are converted to views inside the QGrid’s block.
When my API fetches updated data the view is rebuilt.
I confirmed that the QGrid is called again, yet, it keeps rendering the initial list of views and not the newly created views.
If I switch to List it works properly. Only with QGrid it doesn’t refresh.
Here is the code in question:

    var body: some View { self.makeView()
        .onReceive(timer) { _ in
            self.refreshView()
        }
    }
    
    private func makeView() -> some View {
        VStack {
                Text("Dashboard").font(.largeTitle)
            if self.circuits.count > 0 {
                // need to use an if, b/c showing scrollable view without content will not refresh later on
                    QGrid<[CircuitInfo], CircuitCell>(self.circuits, columns: 2, columnsInLandscape: 4, vSpacing: 10, vPadding: 10, isScrollable: true) { circuit in
                        CircuitCell(circuit: circuit)
                }
            }
            Spacer()
            HStack {
                Text("\(self.circuitsCount())").font(.footnote).padding(5)
                Spacer()
                Text("Updated: \(lastUpdated)").font(.footnote).padding(5)
            }
        }
    }

Any ideas as to what I might be doing wrong?

@brandtdaniels
Copy link

brandtdaniels commented Jul 29, 2020

I also have a data source being updated and the grid is not being refreshed

  @ObservedObject var viewModel: ViewModel

  var body: some View {

    QGrid(
      viewModel.attachments,
      columns: horizontalSizeClass == .compact ? 2 : 3,
      vSpacing: 24,
      hSpacing: 16,
      vPadding: 16,
      hPadding: 16
    ) {

      AttachmentButton(
        viewModel: AttachmentViewModel(attachment: $0)
      )

    }
    .onAppear(perform: viewModel.load)
    .navigationBarTitle("Attachments")

  }

Replacing QGrid with List works, but not the desired layout.

@amrit42087
Copy link

I am also facing exactly the same issue!!

@amrit42087
Copy link

QGrid

Did you figure out a way out for this issue?

@razyalov
Copy link
Author

razyalov commented Aug 16, 2020 via email

@amrit42087
Copy link

Ended up writing my own version from scratch.

On Aug 16, 2020, at 4:06 AM, amrit42087 @.***> wrote:  QGrid Did you figure out a way out for this issue? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Thanks for replying. Even I had to create my own solution. But mine is not generic. I have to create a grid for every type of data. Is it possible for you to share the approach you followed?

@razyalov
Copy link
Author

razyalov commented Aug 16, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants