-
-
Notifications
You must be signed in to change notification settings - Fork 60
Init with @functionBuilder #2
Comments
This is related to #8 |
Looks like this could be relevant: |
@TilBlechschmidt we were able to init it with function builder in previous release public init(@ViewBuilder content: () -> Content) { ? } Grid {
Text("1")
} |
Hi! I would love to take this issue. Any advice on a good place to start? |
@hmerzin Hi! This is as far as I have been able to take it extension Grid {
public init<Data: RandomAccessCollection, ID, Item: View>(@ViewBuilder content: () -> Content) where Content == ForEach<Data, ID, Item> {
let views = content()
self.items = views.data.map { AnyView(views.content($0)) }
}
} This allows to init grid like so: Grid {
ForEach(...)
} I honestly have no idea how to achieve the behaviour of native elements like List, Group, HStack. HStack {
Text("1")
Text("2")
} It would be awesome if you can figure this out. |
as luck would have it, I recall reading a blog post a few weeks agothat elaborates on function builders and how one might be able to harness that syntax, though I am not entirely sure if it is possible outside of a SwiftUI context, as I remember seeing a constraint on the syntax that I thought was a bit strange. Nevertheless, I will take a look and let you know what I find and if I can prototype a solution! thanks, |
@ay42 using @ViewBuilder was exactly the syntax that I was exploring for implementing this. I think I am pretty close, but basically I have just been fiddling with the initializer for HStack |
#31 has improvements that address this issue as well. |
Allow users to init Grid with function builder
The text was updated successfully, but these errors were encountered: