I'm trying to update TEXT info after a tap action from Reality Composer. func textTouch()
is working, I get a print on debug.
self.newText = "new info"
How can I update the view? Why the state variable leaves only inside the struct?
import SwiftUI
import RealityKit
struct ContentView : View {
@State var newText: String = "Touch add more info"
var body: some View {
return VStack {
ARViewContainer().edgesIgnoringSafeArea(.all)
Text(newText)
}
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
// Load the "Box" scene from the Reality File
let birdAnchor = try! Cube.loadCube()
let sunInfoAction = birdAnchor.actions.allActions.filter({$0.identifier == "cubeTap"}).first
sunInfoAction?.onAction = { entity in
self.textTouch()
}
arView.scene.anchors.append(birdAnchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
func textTouch() {
print("working")
self.newText = "new info"
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif