Skip to content

Instantly share code, notes, and snippets.

@elkraneo
Created August 25, 2022 18:21
Show Gist options
  • Save elkraneo/90c4908d367d04215aeda9c898790ebe to your computer and use it in GitHub Desktop.
Save elkraneo/90c4908d367d04215aeda9c898790ebe to your computer and use it in GitHub Desktop.
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