Content not refreshed when creating new views
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?
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.
I am also facing exactly the same issue!!
QGrid
Did you figure out a way out for this issue?
Ended up writing my own version from scratch.
On Aug 16, 2020, at 4:06 AM, amrit42087 [email protected] 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.
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?
Very similar to the QGrid source code just without all the configuration options. I divide my list into rows and add them into a vstack of hstacks inside a parent scroll view.
On Aug 16, 2020, at 9:22 AM, amrit42087 [email protected] wrote:
 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?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.