@Environment(\.colorScheme) var colorScheme
- var content: String
- let evolution: Stage
+ @Binding var content: String
+ @Binding var evolution: Stage
+
+ @State var parsedMap: ParsedMap = ParsedMap.empty
let mapSize = CGSize(width: 1300.0, height: 1000.0)
let vertexSize = CGSize(width: 25.0, height: 25.0)
let padding = CGFloat(30.0)
- var parsedMap: ParsedMap {
- return Map.parse(content: content)
- }
-
var body: some View {
ZStack(alignment: .topLeading) {
}.frame(
width: mapSize.width,
height: mapSize.height + 2 * padding, alignment: .topLeading
- ).padding(padding)
+ ).onAppear {
+ self.parsedMap = Map.parse(content: content)
+ }.padding(padding).onChange(of: content) { newState in
+ self.parsedMap = Map.parse(content: newState)
+ }
}
}
struct MapRenderView_Previews: PreviewProvider {
static var previews: some View {
- MapRenderView(content: "", evolution: Stage.stages(.general)).environment(
+ MapRenderView(
+ content: Binding.constant(""), evolution: Binding.constant(Stage.stages(.general))
+ ).environment(
\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}