Skip to content

Commit

Permalink
Week 3 - ScrollView, ListView and Stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Bhasin committed Jul 16, 2020
1 parent 09d2792 commit 6af0db6
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SwiftUI_Starter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
77029AF724AA7282007896AD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 77029AF624AA7282007896AD /* Preview Assets.xcassets */; };
77029AFA24AA7282007896AD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77029AF824AA7282007896AD /* LaunchScreen.storyboard */; };
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 */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,6 +28,8 @@
77029AF924AA7282007896AD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
77029AFB24AA7282007896AD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -62,6 +66,8 @@
77029AEF24AA727F007896AD /* SceneDelegate.swift */,
77029AF124AA727F007896AD /* ContentView.swift */,
7729D99924B9C0A500FB8EFF /* LearnImagesView.swift */,
7729D99B24C0B69300FB8EFF /* CellRow.swift */,
7729D99D24C0B9AA00FB8EFF /* ListView.swift */,
77029AF324AA7282007896AD /* Assets.xcassets */,
77029AF824AA7282007896AD /* LaunchScreen.storyboard */,
77029AFB24AA7282007896AD /* Info.plist */,
Expand Down Expand Up @@ -151,7 +157,9 @@
files = (
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 */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
61 changes: 61 additions & 0 deletions SwiftUI_Starter/CellRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// CellRow.swift
// SwiftUI_Starter
//
// Created by Karan Bhasin on 16/07/20.
// Copyright © 2020 Karan Bhaisn. All rights reserved.
//

import SwiftUI
struct ListModel: Identifiable, Hashable {
let id: Int
let name: String
let imageName: String

static func data() -> [ListModel] {
return [ListModel(id: 0, name: "Karan", imageName: "Bhasin"),
ListModel(id: 0, name: "Nila", imageName: "Akash"),
ListModel(id: 0, name: "Nitin", imageName: "Pant"),
ListModel(id: 0, name: "Deepak", imageName: "Carpenter"),
ListModel(id: 0, name: "Dileep", imageName: "M")]
}
}


struct CellRow: View {
let cellData: ListModel

var body: some View {
HStack(spacing: 10) {
Text("Hello")
Text(cellData.name)
Button(action: buttonAction) {
Image(systemName: "chevron.right")
.frame(width: 20, height: 20)
.foregroundColor(Color.yellow)
}
VStack {
Text(cellData.imageName)
Image("med")
.resizable()
.scaledToFill()
.frame(width: 100, height: 100, alignment: .center)
.clipShape(Rectangle())
.aspectRatio(contentMode: .fit)
.clipped()
}
Spacer()
}
.background(Color.green)
}

private func buttonAction() {

}
}

struct CellRow_Previews: PreviewProvider {
static var previews: some View {
CellRow(cellData: ListModel(id: 0, name: "lkjh", imageName: "jkhgj"))
}
}
37 changes: 37 additions & 0 deletions SwiftUI_Starter/ListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ListView.swift
// SwiftUI_Starter
//
// Created by Karan Bhasin on 16/07/20.
// Copyright © 2020 Karan Bhaisn. All rights reserved.
//

import SwiftUI

struct ListView: View {
var body: some View {
NavigationView {
HStack(spacing: 5) {
ScrollView {
VStack(spacing: 15) {
ForEach(ListModel.data(), id: \.self) { object in
CellRow(cellData: object)
}
}
}
List {
ForEach(ListModel.data(), id: \.self) { object in
CellRow(cellData: object)
}
}
}
.navigationBarTitle("My List")
}
}
}

struct ListView_Previews: PreviewProvider {
static var previews: some View {
ListView()
}
}

0 comments on commit 6af0db6

Please sign in to comment.