Closed alelordelo closed 4 years ago
Thanks!
Sorry, I'm not sure I understood your question. Are you talking about the elements of the grid? Do you have an example of what you are trying to achieve?
Hi Paolo. Sorry, my question was not so clear! : )
I mean to use some Text or Rectangle to prototype a grid without data, when you are in early stage of designing the UI and don't have data yet.
Example bellow with a List
import SwiftUI
struct ListView: View {
var body: some View {
List {
Rectangle()
Text("Hello, World!")
}
}
}
struct ListView_Previews: PreviewProvider {
static var previews: some View {
ListView()
}
}
`
Oh, I see! Currently is not possible. But it's a feature that I would definitely like to include.
The Grid initializer needs to be updated in a way that can accept @ViewBuilder
as a parameter.
https://developer.apple.com/documentation/swiftui/viewbuilder
thanks Paolo! I managed to make it work, and now I am trying to make a button that Swtches between List and your Grid.
I posted a question on Stack Overflow. Do you know how to do it?
https://stackoverflow.com/questions/59145490/swiftui-switch-between-list-and-grid-collection-view
I believe they already pointed you in the right direction.
The problem with your code is the return type different from the expected some View
.
One solution is to move the if-else
statement inside a "container" like Group
, the opaque View generated won't change no matter the state of the boolean.
From there you can call .navigationBarTitle
, .navigationBarItems
etc. without compile errors.
NavigationView {
Group {
if showgrid == true {
WaterfallGrid(...)
} else {
List(...)
}
}
.navigationBarTitle(...)
.navigationBarItems(...)
}
Awesome stuff mate! : )
Is there a way to use a rectangle() or photo, instead of data?