Skip to content

Instantly share code, notes, and snippets.

@tarrouye
Created June 29, 2020 11:40
Show Gist options
  • Save tarrouye/c4a400514d2fb896a33bba3a2113f5ed to your computer and use it in GitHub Desktop.
Save tarrouye/c4a400514d2fb896a33bba3a2113f5ed to your computer and use it in GitHub Desktop.
import SwiftUI
import PlaygroundSupport
import MapKit
struct MapView: UIViewRepresentable {
var locationManager = CLLocationManager()
func setupManager() {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()
}
func makeUIView(context: Context) -> MKMapView {
setupManager()
let mapView = MKMapView(frame: UIScreen.main.bounds)
mapView.showsUserLocation = true
mapView.userTrackingMode = .follow
return mapView
}
func updateUIView(_ uiView: MKMapView, context: Context) {
}
}
class Note: ObservableObject {
@Published var title: String = "Title"
@Published var body: String = "This is the body of the note. This is where you wrote something important. Prob not much longer than this."
@Published var location: String = "Santa Clara, CA"
@Published var date: String = "June 28, 2020"
}
struct NoteEditView: View {
@Binding var note: Note
var body: some View {
ZStack {
MapView()
.blur(radius: 1.0 as CGFloat)
VStack {
TextField("Enter a title", text: $note.title)
.font(.largeTitle)
Spacer()
Text(note.body)
Spacer()
Spacer()
VStack {
(Text("This note was last edited ") + Text(note.date).bold())
.font(.caption)
(Text("This note is currently placed in ") + Text( note.location).bold())
.font(.caption)
.padding(.top)
}
.padding()
.background(Color(UIColor.secondarySystemBackground).opacity(0.5))
.cornerRadius(20)
/*
HStack {
VStack(alignment: .leading) {
Text("This note was last edited:").font(.caption)
Text("This note is currently placed in:").font(.caption)
}
VStack(alignment: .trailing) {
Text(note.date).bold().font(.caption)
Text(note.location).bold().font(.caption)
}
}
.padding()*/
}
}
}
}
struct NoteView: View {
@Binding var note: Note
var body: some View {
ZStack {
MapView()
.clipShape(RoundedRectangle(cornerRadius: 24))
//.blur(radius: 1.0)
VStack(alignment: .leading) {
Text(self.note.title)
.font(.largeTitle)
.fontWeight(.semibold)
Divider()
Spacer()
Text(self.note.body)
.font(.body)
Spacer()
Divider()
HStack {
Text(self.note.date)
.font(.caption).bold()
Spacer()
Text(self.note.location)
.font(.caption).bold()
}
}
.padding()
.frame(width: 250, height: 300)
.background(Color(UIColor.secondarySystemBackground).opacity(0.5))
.cornerRadius(24)
}
}
}
class Notes : ObservableObject {
var notes : [Note] = [ Note(), Note() ]
}
struct ContentView: View {
@EnvironmentObject var notesData: Notes
var body: some View {
NavigationView {
ScrollView {
HStack {
NavigationLink(destination: NoteEditView(note: $notesData.notes[0])) {
NoteView(note: $notesData.notes[0])
}
.buttonStyle(PlainButtonStyle())
NoteView(note: $notesData.notes[1])
}
Spacer()
HStack {
NoteView(note: $notesData.notes[0])
NoteView(note: $notesData.notes[0])
}
Spacer()
HStack {
NoteView(note: $notesData.notes[0])
NoteView(note: $notesData.notes[0])
}
}
.navigationBarTitle("Notes")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
PlaygroundPage.current.setLiveView(ContentView().environmentObject(Notes()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment