Comments (6)
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.
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.
Anyway, I think QGrid should have any workaround
from qgrid.
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.
@Svantulden Where did you add .id(UUID()
to the QGrid?
from qgrid.
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)
- Crash on macOS with images in the grid
- On iPad, NavigationLink sometimes doesn't work in DoubleColumnNavigationViewStyle() HOT 1
- Not Lazy? HOT 2
- How to use navigation for a cell? HOT 1
- Multiple items navigation HOT 1
- add to project
- Trouble importing package HOT 1
- Is there a way to make it so that the QGrid view doesn't take up the whole height of the screen? HOT 1
- if apply search on QGrid, it will crash app, but the old version was fine
- how to detect the height of each row? under the section
- support Core Data NSManagedObjects for initial data
- Inconsistent state after rotation HOT 2
- Different cells based on row,col
- Content not refreshed when creating new views HOT 6
- Error when importing QGrid in project with lower deployment target HOT 3
- Paging HOT 1
- Drag and move to reorder features support
- Warning on macOS: Invalid frame dimension (negative or non-finite) HOT 2
- Use QGrid inside another scroll view HOT 1
- Darkmode override
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qgrid.