Several Views were received as 'TurpleView<_VariadicView.Children>'.
struct View1: View {
var body: some View {
VStack {
Text("page!")
}
}
}
struct Routable<Content: View> : View where Content : View {
var activated:Bool = false
let _content: Content
init(@ViewBuilder content: @escaping() -> Content) {
self._content = content()
}
var body: some View {
_content
}
}
struct SplashViews: View {
var body: some View {
ZStack {
HStack {
RouterStack {
Routable {
View1()
}
Routable {
View1()
}
}
}
}
}
}
And the handle was converted to Array format, However, AnyView cannot be converted to the original class.
public typealias Views = _VariadicView.Children
extension TupleView {
var views: [AnyView] {
make_array(from: value)
}
private struct GenericView {
let body: Any
var any_view: AnyView? {
AnyView(_fromValue: body)
}
}
private func make_array<Tuple>(from tuple: Tuple) -> [AnyView] {
func convert(child: Mirror.Child) -> AnyView? {
withUnsafeBytes(of: child.value) { pointer -> AnyView? in
if case Optional<Any>.some(_) = child.value {
print("[TurpleView Children Value]: \(child)")
let binded = pointer.bindMemory(to: GenericView.self)
return binded.first?.any_view
}
return nil
}
}
let mirror = Mirror(reflecting: tuple)
return mirror.children.compactMap(convert)
}
}
struct RouterStack: View {
@ObservedObject var _router: Router
private let _content: [AnyView]
init<Views>(@ViewBuilder content: @escaping() -> TupleView<Views>) {
self._content = content().views
self._router = Router(self._content)
let x:AnyView = self._content[0] as Routable
// print("\(x.activated)")
// Cannot convert value of type 'AnyView' to type 'Routable<Content>' in coercion
// Cannot convert value of type 'Routable<Content>' to specified type 'AnyView'
// Generic parameter 'Content' could not be inferred in cast to 'Routable'
}
var body: some View {
NavigationView {
}
}
}
Is this possible?
I want to access the internal functions and variables of the view received through TurpleView. Or I don't have to use TurpleView, is there a better way?
Routable
out of a@ViewBuilder
? What are you going to do with it once you got it? This sounds very like an XY Problem.Routable
. I'd suggest that you take a step back, and edit your question to ask about your actual problem instead. Right now you seem to be going in a very wrong direction. Show, with code, an example of how someone might use yourRouterStack
(including how they would add an async skip condition). Describe how that code would behave.