Created
August 25, 2022 18:21
-
-
Save elkraneo/90c4908d367d04215aeda9c898790ebe to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Text("Hello, world!") | |
Reality { | |
Anchor { | |
Model() | |
} | |
} | |
} | |
.padding() | |
} | |
} | |
// MARK: - | |
protocol EntityRepresentable {} | |
struct Reality: UIViewRepresentable { | |
let tree: BinaryTree<EntityRepresentable> | |
func makeCoordinator() { | |
Coordinator() | |
} | |
init(@RealityBuilder _ builder: () -> BinaryTree<EntityRepresentable>) { | |
self.tree = builder() | |
} | |
func makeUIView(context: Context) -> UIView { | |
.init() | |
} | |
func updateUIView(_ uiView: UIViewType, context: Context) { | |
//TODO: compare `self.tree` with `context.coordinator.tree` | |
} | |
} | |
class Coordinator { | |
var tree: BinaryTree<EntityRepresentable> = .empty | |
init() {} | |
} | |
struct Anchor: EntityRepresentable { | |
let body: BinaryTree<EntityRepresentable> | |
init(@RealityBuilder _ builder: () -> BinaryTree<EntityRepresentable>) { | |
self.body = builder() | |
} | |
} | |
struct Model: EntityRepresentable { | |
let body: BinaryTree<EntityRepresentable> | |
init(@RealityBuilder _ builder: () -> BinaryTree<EntityRepresentable>) { | |
self.body = builder() | |
} | |
} | |
@resultBuilder | |
struct RealityBuilder { | |
static func buildBlock( | |
_ components: EntityRepresentable | |
) -> BinaryTree<EntityRepresentable> { | |
.node(components, .empty) | |
} | |
} | |
enum BinaryTree<T> { | |
case empty | |
indirect case node(BinaryTree, BinaryTree) | |
} | |
// enum Either<Left, Right> { | |
// case left(Left) | |
// case right(Right) | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment