shaps80 / SwiftUIBackports

A collection of SwiftUI backports for iOS, macOS, tvOS and watchOS
MIT License
931 stars 59 forks source link

UIHostingConfiguration #4

Closed K1NXZ closed 2 years ago

K1NXZ commented 2 years ago

Any plans to backport UIHostingConfiguration added in iOS 16 would be great for the beginning to configure cells with SwiftUI.

shaps80 commented 2 years ago

I haven’t looked deeply into the UIHostingConfiguration yet but I imagine that might be difficult to backport actually. It requires a lot more understanding and access (I think) to the underlying SwiftUI components. But I’ll definitely explore it.

I have been working on a CollectionList custom layout view that could solve these types of issues, but its still a WIP.

shaps80 commented 2 years ago

I'll strikeout the above as I completely mis-remembered what UIHostingConfiguration was.

I did actually see this mentioned at WWDC I recall now, and its pretty nice to make it easier for UIKit users to bring SwiftUI into their code. However, that's not exactly the purpose of this library. This feels more like I'd be back porting UIKit in order to support this.

That being said, I am (as mentioned above) working on something related to UICollectionView that does require me to wrap SwiftUI view's in cells. So if there is even a lightweight version of this that could be useful in this library, I'll include it and let you know 👍

shaps80 commented 2 years ago

Good news @K1NXZ, I managed to get most of this working already. I have intentionally left out much of the UIContentConfiguration APIs since they're only useful if we also backport the whole iOS 14+ API they introduced for configuring cells, which would be a lot of effort.

But I think this still provides a useful and familiar API that should make it just as easy to integrate SwiftUI into cells.

Screenshot 2022-07-01 at 01 37 59
shaps80 commented 2 years ago

I will test this more thoroughly for a while, but it's looking quite promising. If you have time, I'd love if you could test it out on the branch hosting

shaps80 commented 2 years ago
Screenshot 2022-07-01 at 02 18 39

Its looking good so far 👍

shaps80 commented 2 years ago

Merged and released #6 – v1.1.0

K1NXZ commented 2 years ago

Looking great! Unfortunately I didn't have time to test it out yet. I will look into it ASAP.

K1NXZ commented 2 years ago

Looking great! Unfortunately I didn't have time to test it out yet. I will look into it ASAP.

Just tested it, its working pretty well! Good job.

shaps80 commented 2 years ago

Good to hear! Any issues please raise so I can take a look. Thanks!

lukeredpath commented 1 year ago

@shaps80 do you know how easy it would be to get this working with UITableViewCell too?

shaps80 commented 1 year ago

@shaps80 do you know how easy it would be to get this working with UITableViewCell too?

@lukeredpath I don't imagine it's very different at all. If you 'copy' the existing implementation I've provided for collection view you are welcome to contribute to the library.

I will eventually get around to it myself, but I don't have time atm.

shaps80 commented 1 year ago

@lukeredpath good news, 1.6.0 is out now and includes this for you 👍

lukeredpath commented 1 year ago

That’s awesome. Thank you.