Skip to content

Commit

Permalink
Week 4 - My Contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Bhasin committed Jul 26, 2020
1 parent 6af0db6 commit 58fdfe6
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
8 changes: 8 additions & 0 deletions SwiftUI_Starter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
7729D99A24B9C0A500FB8EFF /* LearnImagesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7729D99924B9C0A500FB8EFF /* LearnImagesView.swift */; };
7729D99C24C0B69300FB8EFF /* CellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7729D99B24C0B69300FB8EFF /* CellRow.swift */; };
7729D99E24C0B9AA00FB8EFF /* ListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7729D99D24C0B9AA00FB8EFF /* ListView.swift */; };
776E672524CDC1680085CED6 /* MyContacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776E672424CDC1680085CED6 /* MyContacts.swift */; };
776E672724CDC7A80085CED6 /* ContactRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776E672624CDC7A80085CED6 /* ContactRow.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -30,6 +32,8 @@
7729D99924B9C0A500FB8EFF /* LearnImagesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LearnImagesView.swift; sourceTree = "<group>"; };
7729D99B24C0B69300FB8EFF /* CellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellRow.swift; sourceTree = "<group>"; };
7729D99D24C0B9AA00FB8EFF /* ListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListView.swift; sourceTree = "<group>"; };
776E672424CDC1680085CED6 /* MyContacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyContacts.swift; sourceTree = "<group>"; };
776E672624CDC7A80085CED6 /* ContactRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactRow.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -68,6 +72,8 @@
7729D99924B9C0A500FB8EFF /* LearnImagesView.swift */,
7729D99B24C0B69300FB8EFF /* CellRow.swift */,
7729D99D24C0B9AA00FB8EFF /* ListView.swift */,
776E672424CDC1680085CED6 /* MyContacts.swift */,
776E672624CDC7A80085CED6 /* ContactRow.swift */,
77029AF324AA7282007896AD /* Assets.xcassets */,
77029AF824AA7282007896AD /* LaunchScreen.storyboard */,
77029AFB24AA7282007896AD /* Info.plist */,
Expand Down Expand Up @@ -155,12 +161,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
776E672524CDC1680085CED6 /* MyContacts.swift in Sources */,
77029AEE24AA727F007896AD /* AppDelegate.swift in Sources */,
77029AF024AA727F007896AD /* SceneDelegate.swift in Sources */,
7729D99E24C0B9AA00FB8EFF /* ListView.swift in Sources */,
77029AF224AA727F007896AD /* ContentView.swift in Sources */,
7729D99C24C0B69300FB8EFF /* CellRow.swift in Sources */,
7729D99A24B9C0A500FB8EFF /* LearnImagesView.swift in Sources */,
776E672724CDC7A80085CED6 /* ContactRow.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
77 changes: 77 additions & 0 deletions SwiftUI_Starter/ContactRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// ContactRow.swift
// SwiftUI_Starter
//
// Created by Karan Bhasin on 26/07/20.
// Copyright © 2020 Karan Bhaisn. All rights reserved.
//

import SwiftUI


struct Contact: Identifiable, Hashable {

let id: Int
let name: String
let email: String
let number: String

static func data() -> [Contact] {
return [
Contact(id: 0, name: "Nila", email: "alash@gmail.com", number: "8884489221"),
Contact(id: 1, name: "Nitin", email: "pant@gmail.com", number: "8884489222"),
Contact(id: 2, name: "Deepak", email: "kumar@gmail.com", number: "8884489223"),
Contact(id: 3,name: "Dileep", email: "dm@gmail.com", number: "8884489224")]
}
}

struct ContactRow: View {
var cellData: Contact
@State private var showingAlert = false
var body: some View {
HStack(spacing: 10) {
VStack(spacing: 10) {
Text(cellData.name)
Text(cellData.email)
}
Spacer()
Button(action: sendMessage) {
Image(systemName: "message.fill")
.frame(width: 20, height: 20, alignment: .leading)
.foregroundColor(Color.green)
}.alert(isPresented: $showingAlert) {
Alert(title: Text("Coming Soon"), message: Text("We will be live soon with this feature"), dismissButton: .default(Text("Got It!")))
}
Button(action: makeVideoCall) {
Image(systemName: "video.fill")
.frame(width: 20, height: 20, alignment: .leading)
.foregroundColor(Color.red)
}.alert(isPresented: $showingAlert) {
Alert(title: Text("Coming Soon"), message: Text("We will be live soon with this feature"), dismissButton: .default(Text("Got It!")))
}
Button(action: buttonAction) {
Image(systemName: "chevron.right")
.frame(width: 20, height: 20)
.foregroundColor(Color.yellow)
}
}
}

func sendMessage() {
self.showingAlert = true
}

func makeVideoCall() {
self.showingAlert = true
}

private func buttonAction() {

}
}

struct ContactRow_Previews: PreviewProvider {
static var previews: some View {
ContactRow(cellData: Contact(id: 1, name: "dss", email: "Ds@sdcom", number: "32332"))
}
}
46 changes: 46 additions & 0 deletions SwiftUI_Starter/MyContacts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// MyContacts.swift
// SwiftUI_Starter
//
// Created by Karan Bhasin on 26/07/20.
// Copyright © 2020 Karan Bhaisn. All rights reserved.
//

import SwiftUI


struct MyContacts: View {
@State private var sortingIndex = 0

var body: some View {
NavigationView {
VStack(spacing: 5) {
Text("Scroll List")
Picker("Sort Contacts by", selection: $sortingIndex) {
Text("Name").tag(0)
Text("Email").tag(1)
}.pickerStyle(SegmentedPickerStyle())
ScrollView {
VStack(spacing: 15) {
ForEach(Contact.data(), id: \.self) { object in
ContactRow(cellData: object)
}
}
}
Text("Table List")
List {
ForEach(Contact.data(), id: \.self) { object in
ContactRow(cellData: object)
}
}
}
.navigationBarTitle("My List")
}
}
}

struct MyContacts_Previews: PreviewProvider {
static var previews: some View {
MyContacts()
}
}
2 changes: 1 addition & 1 deletion SwiftUI_Starter/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

// Create the SwiftUI view that provides the window contents.
// let contentView = ContentView()
let contentView = LearnImagesView()
let contentView = MyContacts()

// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
Expand Down

0 comments on commit 58fdfe6

Please sign in to comment.