GithubHelp home page GithubHelp logo

Comments (9)

hmerzin avatar hmerzin commented on May 21, 2024 1

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,
Harry

from swiftui-grid.

ay42 avatar ay42 commented on May 21, 2024 1

#31 has improvements that address this issue as well.
I feel like we can close this.

from swiftui-grid.

ay42 avatar ay42 commented on May 21, 2024

This is related to #8
If anyone figured out how to do this please let me know.

from swiftui-grid.

TilBlechschmidt avatar TilBlechschmidt commented on May 21, 2024

Looks like this could be relevant:
https://developer.apple.com/documentation/swiftui/viewbuilder
Will investigate further.

from swiftui-grid.

ay42 avatar ay42 commented on May 21, 2024

@TilBlechschmidt we were able to init it with function builder in previous release
https://github.com/spacenation/grid/blob/eafea07725c1172fe630d6724bd6edac06bef728/Sources/Grid/Grid.swift#L10-L14
But the difficulty here is to process view builder directly like so:

public init(@ViewBuilder content: () -> Content) { ? }
Grid {
    Text("1")
}

from swiftui-grid.

hmerzin avatar hmerzin commented on May 21, 2024

Hi! I would love to take this issue. Any advice on a good place to start?

from swiftui-grid.

ay42 avatar ay42 commented on May 21, 2024

@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.
There it is possible to just do this and it works:

HStack {
    Text("1")
    Text("2")
}

It would be awesome if you can figure this out.

from swiftui-grid.

ay42 avatar ay42 commented on May 21, 2024

@hmerzin Looks there is a way to do this (#29). It's not perfect but it's an API we are looking for. Is this something similar to what you wanted to implement? Let me know

from swiftui-grid.

hmerzin avatar hmerzin commented on May 21, 2024

@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

from swiftui-grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.