5 struct MapDetailScreen: View {
6 @Environment(\.managedObjectContext) private var viewContext
8 @EnvironmentObject var store: AppStore
10 @ObservedObject var map: Map
12 @State var title: String
13 @State var content: String
21 "Title", text: $title, onCommit: saveModel
22 ).font(.title2).textFieldStyle(PlainTextFieldStyle()).padding(.vertical, 4.0).padding(
24 Button(action: saveText) {
25 Image(systemName: "doc.text")
26 }.padding(.vertical, 4.0).padding(.leading, 4.0)
27 Button(action: saveImage) {
28 Image(systemName: "photo")
29 }.padding(.vertical, 4.0).padding(.leading, 4.0).padding(.trailing, 8.0)
33 ZStack(alignment: .topLeading) {
34 MapTextEditor(text: $content, onChange: saveModel)
35 .background(Color.ui.background)
36 .foregroundColor(Color.ui.foreground)
37 .frame(minHeight: 96.0)
38 }.padding(.top, 8.0).padding(.leading, 8.0).background(Color.ui.background).cornerRadius(
40 }.padding(.horizontal, 8.0)
41 ScrollView([.horizontal, .vertical]) {
42 MapRenderView(content: $content, evolution: .constant(store.state.selectedEvolution))
48 EmptyMapDetailScreen()
52 private func saveModel() {
55 try? viewContext.save()
58 private func saveText() {
59 store.send(.exportMapAsText(map: map))
62 private func saveImage() {
63 store.send(.exportMapAsImage(map: map))
67 struct MapDetailView_Previews: PreviewProvider {
68 static var previews: some View {
69 MapDetailScreen(map: Map(), title: "", content: "").environment(
70 \.managedObjectContext, PersistenceController.preview.container.viewContext)