'How to use GeometryProxy outside of a ViewBuilder?
I implemented a BasicContainer upon GeometryReader with the functionality of a @ViewBuilder. How can I use this inside GeometryProxy, outside when declaring the content?
Here is my BasicContainer:
struct BasicContainer<Content : View> : View {
let content : Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
GeometryReader { proxy in
content
.frame(width: proxy.size.width * 0.3, height: 200)
// do some other fancy stuff ...
}
}
}
Everything works fine, when I use the BasicContainer as it's meant to be:
struct ContentView: View {
var body: some View {
BasicContainer {
Text("Roberts BasicContainer")
}
}
}
But what, if I would like to have the GeometryProxy also outside, (like Apple implemented their GeometryReader), like so:
BasicContainer { outsideGeo in
Text("Width: \(outsideGeo.size.width)")
}
I guess some kind of a @Binding could make the trick, but so far I couldn't make it work.
Is this even possible to realize?
Any help is very appreciated !!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
