Last active
October 14, 2025 01:49
-
-
Save Kyle-Ye/7a61ac0d15b196c49b79b0a614670ca0 to your computer and use it in GitHub Desktop.
SwiftUI implicitRootType Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extra content to append for your SwiftUICore SDK to use internal package API | |
extension SwiftUICore.View { | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
nonisolated public static func makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
nonisolated public static func makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs | |
} | |
extension SwiftUICore._ViewInputs { | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public var implicitRootType: any SwiftUICore._VariadicView.AnyImplicitRoot.Type { | |
get | |
set | |
} | |
} | |
extension SwiftUICore._ViewListInputs { | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public var implicitRootType: any SwiftUICore._VariadicView.AnyImplicitRoot.Type { | |
get | |
set | |
} | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
extension SwiftUICore._VariadicView { | |
public typealias AnyImplicitRoot = SwiftUICore._VariadicView_AnyImplicitRoot | |
public typealias ImplicitRoot = SwiftUICore._VariadicView_ImplicitRoot | |
public typealias ImplicitRootVisitor = SwiftUICore._VariadicView_ImplicitRootVisitor | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public protocol _VariadicView_AnyImplicitRoot { | |
static func visitType<V>(visitor: inout V) where V : SwiftUICore._VariadicView_ImplicitRootVisitor | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public protocol _VariadicView_ImplicitRoot : SwiftUICore._VariadicView_AnyImplicitRoot, SwiftUICore._VariadicView_ViewRoot { | |
static var implicitRoot: Self { get } | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public protocol _VariadicView_ImplicitRootVisitor { | |
mutating func visit<R>(type: R.Type) where R : SwiftUICore._VariadicView_ImplicitRoot | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
extension _HStackLayout: _VariadicView.ImplicitRoot { | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public static var implicitRoot: _HStackLayout { .init() } | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
extension _ZStackLayout: _VariadicView.ImplicitRoot { | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public static var implicitRoot: _HStackLayout { .init() } | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public final class ViewGraph { | |
public static var current: ViewGraph { get } | |
public func append<T>(feature: T) where T: ViewGraphFeature | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
public protocol ViewGraphFeature { | |
mutating func modifyViewInputs(inputs: inout _ViewInputs, graph: ViewGraph) | |
mutating func modifyViewOutputs(outputs: inout _ViewOutputs, inputs: _ViewInputs, graph: ViewGraph) | |
mutating func uninstantiate(graph: ViewGraph) | |
mutating func isHiddenForReuseDidChange(graph: ViewGraph) | |
mutating func allowsAsyncUpdate(graph: ViewGraph) -> Bool? | |
mutating func needsUpdate(graph: ViewGraph) -> Bool | |
mutating func update(graph: ViewGraph) | |
} | |
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) | |
extension SwiftUICore.ViewGraphFeature { | |
public mutating func modifyViewInputs(inputs: inout SwiftUICore._ViewInputs, graph: SwiftUICore.ViewGraph) | |
public mutating func modifyViewOutputs(outputs: inout SwiftUICore._ViewOutputs, inputs: SwiftUICore._ViewInputs, graph: SwiftUICore.ViewGraph) | |
public mutating func uninstantiate(graph: SwiftUICore.ViewGraph) | |
public mutating func isHiddenForReuseDidChange(graph: SwiftUICore.ViewGraph) | |
#if compiler(>=5.3) && $NoncopyableGenerics | |
public mutating func allowsAsyncUpdate(graph: SwiftUICore.ViewGraph) -> Swift.Bool? | |
#else | |
public mutating func allowsAsyncUpdate(graph: SwiftUICore.ViewGraph) -> Swift.Bool? | |
#endif | |
public mutating func needsUpdate(graph: SwiftUICore.ViewGraph) -> Swift.Bool | |
public mutating func update(graph: SwiftUICore.ViewGraph) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: ViewGraph.current.append(feature: HStackImplicitFeature()) | |
struct HStackImplicitFeature: ViewGraphFeature { | |
func modifyViewInputs(inputs: inout _ViewInputs, graph: ViewGraph) { | |
inputs.implicitRootType = _HStackLayout.self | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
ChildView1() | |
// ChildView2() | |
} | |
} | |
struct ChildView1: View { | |
@State private var show = false | |
var body: some View { | |
Color.red | |
Color.blue | |
} | |
static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs { | |
var inputs = inputs | |
inputs.implicitRootType = _HStackLayout.self | |
return makeView(view: view, inputs: inputs) | |
} | |
static func _makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs { | |
var inputs = inputs | |
inputs.implicitRootType = _HStackLayout.self | |
return makeViewList(view: view, inputs: inputs) | |
} | |
} | |
struct ChildView2: View { | |
@State private var show = false | |
var body: some View { | |
Color.red.opacity(0.5) | |
Color.blue.opacity(0.5) | |
} | |
static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs { | |
var inputs = inputs | |
inputs.implicitRootType = _ZStackLayout.self | |
return makeView(view: view, inputs: inputs) | |
} | |
static func _makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs { | |
var inputs = inputs | |
inputs.implicitRootType = _ZStackLayout.self | |
return makeViewList(view: view, inputs: inputs) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally posted in https://x.com/KyleSwifter/status/1977747002604630157
Preview:
