Skip to content

Commit

Permalink
SwiftUI HStack, VStack, List, Button & ScrollView
Browse files Browse the repository at this point in the history
Worked on SwiftUI components like HStack, VStack, List, Button & ScrollView
  • Loading branch information
TejasKokate-Deloitte committed Jul 19, 2020
1 parent 40c715f commit 9e0dcaa
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 0 deletions.
32 changes: 32 additions & 0 deletions SwiftUI_Starter/SwiftUI_Starter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
48965A7B24AA4D1700261C13 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 48965A7A24AA4D1700261C13 /* Assets.xcassets */; };
48965A7E24AA4D1700261C13 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 48965A7D24AA4D1700261C13 /* Preview Assets.xcassets */; };
48965A8124AA4D1700261C13 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 48965A7F24AA4D1700261C13 /* LaunchScreen.storyboard */; };
48B07A6524C430710051259D /* CellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B07A6424C430710051259D /* CellRow.swift */; };
48B07A6724C4351A0051259D /* ListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B07A6624C4351A0051259D /* ListModel.swift */; };
48B07A6924C4360B0051259D /* MyFirstListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B07A6824C4360B0051259D /* MyFirstListView.swift */; };
48B07A6D24C43D5E0051259D /* ScrollViewChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B07A6C24C43D5E0051259D /* ScrollViewChallenge.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,6 +30,10 @@
48965A7D24AA4D1700261C13 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
48965A8024AA4D1700261C13 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
48965A8224AA4D1700261C13 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
48B07A6424C430710051259D /* CellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellRow.swift; sourceTree = "<group>"; };
48B07A6624C4351A0051259D /* ListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModel.swift; sourceTree = "<group>"; };
48B07A6824C4360B0051259D /* MyFirstListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyFirstListView.swift; sourceTree = "<group>"; };
48B07A6C24C43D5E0051259D /* ScrollViewChallenge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewChallenge.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -74,8 +82,10 @@
48965A7324AA4D1400261C13 /* SwiftUI_Starter */ = {
isa = PBXGroup;
children = (
48B07A6B24C43D4D0051259D /* ScrollView */,
484521ED24B9C85400107D2B /* Text */,
484521EE24B9C85D00107D2B /* Image */,
48B07A6A24C43D0A0051259D /* List */,
48965A7424AA4D1400261C13 /* AppDelegate.swift */,
48965A7624AA4D1400261C13 /* SceneDelegate.swift */,
48965A7A24AA4D1700261C13 /* Assets.xcassets */,
Expand All @@ -94,6 +104,24 @@
path = "Preview Content";
sourceTree = "<group>";
};
48B07A6A24C43D0A0051259D /* List */ = {
isa = PBXGroup;
children = (
48B07A6424C430710051259D /* CellRow.swift */,
48B07A6624C4351A0051259D /* ListModel.swift */,
48B07A6824C4360B0051259D /* MyFirstListView.swift */,
);
path = List;
sourceTree = "<group>";
};
48B07A6B24C43D4D0051259D /* ScrollView */ = {
isa = PBXGroup;
children = (
48B07A6C24C43D5E0051259D /* ScrollViewChallenge.swift */,
);
path = ScrollView;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -164,9 +192,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
48B07A6924C4360B0051259D /* MyFirstListView.swift in Sources */,
48B07A6D24C43D5E0051259D /* ScrollViewChallenge.swift in Sources */,
48965A7524AA4D1400261C13 /* AppDelegate.swift in Sources */,
48965A7724AA4D1400261C13 /* SceneDelegate.swift in Sources */,
484521F024B9C92100107D2B /* SwiftUIView.swift in Sources */,
48B07A6724C4351A0051259D /* ListModel.swift in Sources */,
48B07A6524C430710051259D /* CellRow.swift in Sources */,
48965A7924AA4D1400261C13 /* ContentView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
49 changes: 49 additions & 0 deletions SwiftUI_Starter/SwiftUI_Starter/List/CellRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// CellRow.swift
// SwiftUI_Starter
//
// Created by Kokate, Tejas on 19/07/20.
//

import SwiftUI

struct CellRow: View {

let cellData: ListModel

var body: some View {
HStack(spacing: 10) {
Image(cellData.imageName)
.resizable()
.scaledToFill()
.frame(width: 50, height: 50, alignment: .center)
.cornerRadius(5)

VStack(alignment: .leading, spacing: 3) {
Text(cellData.title)
.font(.headline)
Text(cellData.subTitle)
.font(.subheadline)
}

Spacer()

Button(action: buttonAction) {
Image(systemName: "chevron.right")
.frame(width: 20, height: 20)
.foregroundColor(Color.black)
}
}
.padding(10)
}

private func buttonAction() {
//TODO: week 4
}
}

struct CellRow_Previews: PreviewProvider {
static var previews: some View {
CellRow(cellData: ListModel(id: 1, title: "Title", subTitle: "SubTitle", imageName: "image1"))
}
}
31 changes: 31 additions & 0 deletions SwiftUI_Starter/SwiftUI_Starter/List/ListModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// ListModel.swift
// SwiftUI_Starter
//
// Created by Kokate, Tejas on 19/07/20.
//

import SwiftUI

struct ListModel: Identifiable, Hashable {

let id: Int
let title: String
let subTitle: String
let imageName: String

static func dummyData() -> [ListModel] {
return [ListModel(id: 1, title: "Title 1", subTitle: "SubTitle 1", imageName: "image1"),
ListModel(id: 2, title: "Title 2", subTitle: "SubTitle 2", imageName: "image2"),
ListModel(id: 3, title: "Title 3", subTitle: "SubTitle 3", imageName: "image3"),
ListModel(id: 4, title: "Title 4", subTitle: "SubTitle 4", imageName: "image1"),
ListModel(id: 5, title: "Title 5", subTitle: "SubTitle 5", imageName: "image2"),
ListModel(id: 6, title: "Title 6", subTitle: "SubTitle 6", imageName: "image3"),
ListModel(id: 7, title: "Title 7", subTitle: "SubTitle 7", imageName: "image1"),
ListModel(id: 8, title: "Title 8", subTitle: "SubTitle 8", imageName: "image2"),
ListModel(id: 9, title: "Title 9", subTitle: "SubTitle 9", imageName: "image3"),
ListModel(id: 10, title: "Title 10", subTitle: "SubTitle 10", imageName: "image1"),
ListModel(id: 11, title: "Title 11", subTitle: "SubTitle 11", imageName: "image2"),
ListModel(id: 12, title: "Title 12", subTitle: "SubTitle 12", imageName: "image3")]
}
}
27 changes: 27 additions & 0 deletions SwiftUI_Starter/SwiftUI_Starter/List/MyFirstListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// MyFirstListView.swift
// SwiftUI_Starter
//
// Created by Kokate, Tejas on 19/07/20.
//

import SwiftUI

struct MyFirstListView: View {
var body: some View {
NavigationView {
List {
ForEach(ListModel.dummyData(), id: \.self) { listObject in
CellRow(cellData: listObject)
}
}
.navigationBarTitle(Text("List View"))
}
}
}

struct MyFirstListView_Previews: PreviewProvider {
static var previews: some View {
MyFirstListView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ScrollViewChallenge.swift
// SwiftUI_Starter
//
// Created by Kokate, Tejas on 19/07/20.
//

import SwiftUI

struct ScrollViewChallenge: View {
var body: some View {
NavigationView {
ScrollView(.vertical, showsIndicators: true) {
ForEach(ListModel.dummyData(), id: \.self) { listObject in
CellRow(cellData: listObject)
}
}
.navigationBarTitle(Text("List with Scroll View"))
}
}
}

struct ScrollViewChallenge_Previews: PreviewProvider {
static var previews: some View {
ScrollViewChallenge()
}
}

0 comments on commit 9e0dcaa

Please sign in to comment.