Skip to content

Commit

Permalink
Day 95 Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rajhraval committed Apr 4, 2020
1 parent 2fa36c9 commit 78d0e40
Show file tree
Hide file tree
Showing 22 changed files with 885 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
CF1B1549242143FF004350A5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CF1B1548242143FF004350A5 /* Assets.xcassets */; };
CF1B154C242143FF004350A5 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CF1B154B242143FF004350A5 /* Preview Assets.xcassets */; };
CF1B154F242143FF004350A5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CF1B154D242143FF004350A5 /* LaunchScreen.storyboard */; };
CF595EA72435D98E0073F1EC /* DetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF595EA62435D98E0073F1EC /* DetailView.swift */; };
CF595EA92435E6130073F1EC /* ContactMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF595EA82435E6130073F1EC /* ContactMapView.swift */; };
CFA2F7532434CB52002721DC /* Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA2F7522434CB52002721DC /* Contacts.swift */; };
CFA2F7552434D160002721DC /* AddContactView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA2F7542434D160002721DC /* AddContactView.swift */; };
CFA2F7572434E6A4002721DC /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA2F7562434E6A4002721DC /* ImagePicker.swift */; };
CFAB76912435B2A500BEBDCF /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFAB76902435B2A500BEBDCF /* MapView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -27,9 +30,12 @@
CF1B154B242143FF004350A5 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
CF1B154E242143FF004350A5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
CF1B1550242143FF004350A5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CF595EA62435D98E0073F1EC /* DetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailView.swift; sourceTree = "<group>"; };
CF595EA82435E6130073F1EC /* ContactMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactMapView.swift; sourceTree = "<group>"; };
CFA2F7522434CB52002721DC /* Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contacts.swift; sourceTree = "<group>"; };
CFA2F7542434D160002721DC /* AddContactView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddContactView.swift; sourceTree = "<group>"; };
CFA2F7562434E6A4002721DC /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
CFAB76902435B2A500BEBDCF /* MapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -66,7 +72,10 @@
CF1B1544242143FD004350A5 /* SceneDelegate.swift */,
CF1B1546242143FD004350A5 /* ContentView.swift */,
CFA2F7562434E6A4002721DC /* ImagePicker.swift */,
CFAB76902435B2A500BEBDCF /* MapView.swift */,
CF595EA62435D98E0073F1EC /* DetailView.swift */,
CFA2F7542434D160002721DC /* AddContactView.swift */,
CF595EA82435E6130073F1EC /* ContactMapView.swift */,
CFA2F7522434CB52002721DC /* Contacts.swift */,
CF1B1548242143FF004350A5 /* Assets.xcassets */,
CF1B154D242143FF004350A5 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -155,12 +164,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CFAB76912435B2A500BEBDCF /* MapView.swift in Sources */,
CF595EA72435D98E0073F1EC /* DetailView.swift in Sources */,
CFA2F7532434CB52002721DC /* Contacts.swift in Sources */,
CFA2F7552434D160002721DC /* AddContactView.swift in Sources */,
CF1B1543242143FD004350A5 /* AppDelegate.swift in Sources */,
CFA2F7572434E6A4002721DC /* ImagePicker.swift in Sources */,
CF1B1545242143FD004350A5 /* SceneDelegate.swift in Sources */,
CF1B1547242143FD004350A5 /* ContentView.swift in Sources */,
CF595EA92435E6130073F1EC /* ContactMapView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
40 changes: 38 additions & 2 deletions Milestone Project 5 - CatchUp/CatchUp/CatchUp/AddContactView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import MapKit

struct AddContactView: View {

Expand All @@ -18,6 +19,10 @@ struct AddContactView: View {
@State private var image: Image?
@State private var inputImage: UIImage?
@State private var showingImagePicker = false
@State private var centerCoordinate = CLLocationCoordinate2D()
@State private var location = MKPointAnnotation()
@State private var latitude: CLLocationDegrees = 0.0
@State private var longitude: CLLocationDegrees = 0.0

var body: some View {
NavigationView {
Expand All @@ -44,17 +49,48 @@ struct AddContactView: View {
.onTapGesture {
self.showingImagePicker = true
}
Text("Contact Name")
TextField("Enter contact name", text: $name)
.padding()
.textFieldStyle(RoundedBorderTextFieldStyle())
Spacer()
.frame(height: 18)
Text("You met at")
ZStack {
MapView(centerCoordinate: $centerCoordinate, annotation: location)
.frame(height: 300)
Circle()
.fill(Color.blue)
.opacity(0.3)
.frame(width: 18, height: 18)
VStack {
Spacer()
HStack {
Spacer()
Button(action: {
self.location.coordinate = self.centerCoordinate
self.latitude = self.location.coordinate.latitude
self.longitude = self.location.coordinate.longitude
}) {
Image(systemName: "plus")
.padding()
.background(Color.yellow.opacity(50))
.foregroundColor(.black)
.font(.title)
.clipShape(Circle())
.padding([.trailing])
}
}
}
}
Spacer()
}
.navigationBarTitle("Add Contact")
.navigationBarItems(trailing:
Button(action: {
guard let inputImage = self.inputImage else { return }
let contact = Contact(name: self.name, image: inputImage)
self.contactItems.contacts.append(contact)
let contact = Contact(name: self.name, image: inputImage, latitude: self.latitude, longitude: self.longitude)
self.contactItems.add(contact)
self.presentationMode.wrappedValue.dismiss()
}) {
Text("Save")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,39 @@
// Copyright © 2020 Buck. All rights reserved.
//

import Foundation
import SwiftUI
import MapKit

struct ContactMapView: UIViewRepresentable {

let latitude: CLLocationDegrees
let longitude: CLLocationDegrees

func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
mapView.delegate = context.coordinator
return mapView
}

class Coordinator: NSObject, MKMapViewDelegate {
var parent: ContactMapView

init(_ parent: ContactMapView) {
self.parent = parent
}

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
<#code#>
}

}

func makeCoordinator() -> Coordinator {
Coordinator(self)
}

func updateUIView(_ uiView: MKMapView, context: Context) {
// More to come
}

}
20 changes: 17 additions & 3 deletions Milestone Project 5 - CatchUp/CatchUp/CatchUp/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@
//

import SwiftUI
import MapKit

struct Contact: Identifiable {
class Contact: Identifiable {
let id = UUID()
let name: String
let image: UIImage?
var name: String = "Anon"
var image: UIImage? = nil
var latitude: CLLocationDegrees = 0.0
var longitude: CLLocationDegrees = 0.0

init(name: String, image: UIImage?, latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
self.name = name
self.image = image
self.latitude = latitude
self.longitude = longitude
}
}

class Contacts: ObservableObject {
Expand All @@ -20,4 +30,8 @@ class Contacts: ObservableObject {
init() {
self.contacts = []
}

func add(_ contact: Contact) {
contacts.append(contact)
}
}
16 changes: 14 additions & 2 deletions Milestone Project 5 - CatchUp/CatchUp/CatchUp/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@
//

import SwiftUI
import MapKit

struct DetailView: View {

@ObservedObject var contactItems = Contacts()

var index = 0
let defaultImage = UIImage(systemName: "person")!

var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
NavigationView {
VStack {
Image(uiImage: contactItems.contacts[index].image ?? defaultImage)
Text(contactItems.contacts[index].name)
}
}
}
}

struct DetailView_Previews: PreviewProvider {
static var previews: some View {
DetailView()
DetailView(contactItems: Contacts(), index: 0)
}
}
43 changes: 42 additions & 1 deletion Milestone Project 5 - CatchUp/CatchUp/CatchUp/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,45 @@
// Copyright © 2020 Buck. All rights reserved.
//

import Foundation
import SwiftUI
import MapKit

struct MapView: UIViewRepresentable {

@Binding var centerCoordinate: CLLocationCoordinate2D
var annotation: MKPointAnnotation

func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
mapView.delegate = context.coordinator
return mapView
}

class Coordinator: NSObject, MKMapViewDelegate {
var parent: MapView

init(_ parent: MapView) {
self.parent = parent
}

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: nil)
view.canShowCallout = true
return view
}

func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
parent.centerCoordinate = mapView.centerCoordinate
}

}

func makeCoordinator() -> Coordinator {
Coordinator(self)
}

func updateUIView(_ view: MKMapView, context: Context) {
view.addAnnotation(annotation)
}

}
Loading

0 comments on commit 78d0e40

Please sign in to comment.