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()
}
}
}
}
}
}
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.