Skip to content

Commit

Permalink
Component 2 - Image
Browse files Browse the repository at this point in the history
  • Loading branch information
sshikalgar committed Jul 6, 2020
1 parent 564510d commit 2b80bda
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SwiftUILearning

## Requirements
* Xcode 12 and above which support SwiftUI

Repo for learning SwiftUI
60 changes: 60 additions & 0 deletions SwiftUILearning.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
384ECA6924B3060F00D2CDC0 /* ImageListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384ECA6824B3060F00D2CDC0 /* ImageListView.swift */; };
384ECA6C24B30F6A00D2CDC0 /* ImageRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384ECA6B24B30F6A00D2CDC0 /* ImageRowView.swift */; };
384ECA6F24B30F7E00D2CDC0 /* TextAndImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384ECA6E24B30F7E00D2CDC0 /* TextAndImageView.swift */; };
384ECA7224B3611D00D2CDC0 /* ImageListType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384ECA7124B3611D00D2CDC0 /* ImageListType.swift */; };
384ECA7524B3614E00D2CDC0 /* ImageListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384ECA7424B3614E00D2CDC0 /* ImageListViewModel.swift */; };
38D25C5024A9D26B00AD202F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D25C4F24A9D26B00AD202F /* AppDelegate.swift */; };
38D25C5224A9D26B00AD202F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D25C5124A9D26B00AD202F /* SceneDelegate.swift */; };
38D25C5524A9D26B00AD202F /* SwiftUILearning.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 38D25C5324A9D26B00AD202F /* SwiftUILearning.xcdatamodeld */; };
Expand Down Expand Up @@ -40,6 +45,11 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
384ECA6824B3060F00D2CDC0 /* ImageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageListView.swift; sourceTree = "<group>"; };
384ECA6B24B30F6A00D2CDC0 /* ImageRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageRowView.swift; sourceTree = "<group>"; };
384ECA6E24B30F7E00D2CDC0 /* TextAndImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextAndImageView.swift; sourceTree = "<group>"; };
384ECA7124B3611D00D2CDC0 /* ImageListType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageListType.swift; sourceTree = "<group>"; };
384ECA7424B3614E00D2CDC0 /* ImageListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageListViewModel.swift; sourceTree = "<group>"; };
38D25C4C24A9D26B00AD202F /* SwiftUILearning.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUILearning.app; sourceTree = BUILT_PRODUCTS_DIR; };
38D25C4F24A9D26B00AD202F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
38D25C5124A9D26B00AD202F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +96,50 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
384ECA6624B3057300D2CDC0 /* ImageView */ = {
isa = PBXGroup;
children = (
384ECA7024B3610100D2CDC0 /* Enum */,
384ECA6724B3058600D2CDC0 /* View */,
384ECA7324B3613600D2CDC0 /* ViewModel */,
);
path = ImageView;
sourceTree = "<group>";
};
384ECA6724B3058600D2CDC0 /* View */ = {
isa = PBXGroup;
children = (
384ECA6A24B30F4000D2CDC0 /* SubViews */,
384ECA6824B3060F00D2CDC0 /* ImageListView.swift */,
);
path = View;
sourceTree = "<group>";
};
384ECA6A24B30F4000D2CDC0 /* SubViews */ = {
isa = PBXGroup;
children = (
384ECA6B24B30F6A00D2CDC0 /* ImageRowView.swift */,
384ECA6E24B30F7E00D2CDC0 /* TextAndImageView.swift */,
);
path = SubViews;
sourceTree = "<group>";
};
384ECA7024B3610100D2CDC0 /* Enum */ = {
isa = PBXGroup;
children = (
384ECA7124B3611D00D2CDC0 /* ImageListType.swift */,
);
path = Enum;
sourceTree = "<group>";
};
384ECA7324B3613600D2CDC0 /* ViewModel */ = {
isa = PBXGroup;
children = (
384ECA7424B3614E00D2CDC0 /* ImageListViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
38D25C4324A9D26B00AD202F = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -160,6 +214,7 @@
children = (
38D25C8724A9D62900AD202F /* ContentView */,
38D25C8424A9D29B00AD202F /* Text */,
384ECA6624B3057300D2CDC0 /* ImageView */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -347,13 +402,18 @@
buildActionMask = 2147483647;
files = (
38D25C5524A9D26B00AD202F /* SwiftUILearning.xcdatamodeld in Sources */,
384ECA7524B3614E00D2CDC0 /* ImageListViewModel.swift in Sources */,
38D25C8624A9D2E600AD202F /* TextSwiftUIView.swift in Sources */,
384ECA6924B3060F00D2CDC0 /* ImageListView.swift in Sources */,
38D25C8B24A9D65400AD202F /* ContentViewModel.swift in Sources */,
384ECA6C24B30F6A00D2CDC0 /* ImageRowView.swift in Sources */,
38D25C5024A9D26B00AD202F /* AppDelegate.swift in Sources */,
38D25C9124A9D81700AD202F /* ContentEnum.swift in Sources */,
38D25C5724A9D26B00AD202F /* ContentView.swift in Sources */,
38D25C8E24A9D75E00AD202F /* ContentModel.swift in Sources */,
38D25C5224A9D26B00AD202F /* SceneDelegate.swift in Sources */,
384ECA6F24B30F7E00D2CDC0 /* TextAndImageView.swift in Sources */,
384ECA7224B3611D00D2CDC0 /* ImageListType.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 6 additions & 0 deletions SwiftUILearning/Assets.xcassets/Images/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "image1.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "image2.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions SwiftUILearning/Components/ContentView/Enum/ContentEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import Foundation

// MARK: - Enum for ComponentType
enum ComponentType: String {
case text = "Text"
case image = "Image"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import SwiftUI
class ContentViewModel {
// MARK: - Variables
/// Model object array
let contentViewItems = [ContentModel(id: 1, contentType: ComponentType.text.rawValue)]
let contentViewItems = [ContentModel(id: 1, contentType: ComponentType.text.rawValue),
ContentModel(id: 2, contentType: ComponentType.image.rawValue)]

/// Method to get destination view
/// - Parameter type: Type of view component
Expand All @@ -23,6 +24,8 @@ class ContentViewModel {
switch rowType {
case .text:
return AnyView(TextSwiftUIView())
case .image:
return AnyView(ImageListView())
}
}
}
15 changes: 15 additions & 0 deletions SwiftUILearning/Components/ImageView/Enum/ImageListType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ImageListType.swift
// SwiftUILearning
//
// Created by Shikalgar, Shahrukh on 06/07/20.
// Copyright © 2020 Shahrukh Shikalgar. All rights reserved.
//

import Foundation

// MARK: - Enum for ImageListType
enum ImageListType: String {
case imageView = "ImageView"
case imageAndTextView = "ImageAndTextView"
}
37 changes: 37 additions & 0 deletions SwiftUILearning/Components/ImageView/View/ImageListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ImageListView.swift
// SwiftUILearning
//
// Created by Shikalgar, Shahrukh on 06/07/20.
// Copyright © 2020 Shahrukh Shikalgar. All rights reserved.
//

import SwiftUI

// MARK: - Struct for ImageListView
/// View for ImageListView
struct ImageListView: View {
// MARK: - Variables
private let viewModel = ImageListViewModel()

// MARK: - View
/// Body for Content View
var body: some View {
List {
ForEach(self.viewModel.contentViewItems, id: \.self) { item in
NavigationLink(destination: self.viewModel.getDestinationView(type: item.contentType ?? "")) {
Text("\(item.contentType ?? "")")
}
}
}
.navigationBarTitle("SwiftUI Images")
}
}

// MARK: - ImageListView_Previews
/// Preview provider for ImageListView
struct ImageListView_Previews: PreviewProvider {
static var previews: some View {
ImageListView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ImageRowView.swift
// SwiftUILearning
//
// Created by Shikalgar, Shahrukh on 06/07/20.
// Copyright © 2020 Shahrukh Shikalgar. All rights reserved.
//

import SwiftUI

// MARK: - Struct for ImageRowView
/// View for ImageRowView
struct ImageRowView: View {
// MARK: - View
/// Body for TextSwiftUIView
var body: some View {
VStack {
Spacer()
Image("image2")
.resizable()
.frame(width: 200, height: 200, alignment: .center)
.clipShape(Circle())
Spacer()
Image("image1")
.resizable()
.aspectRatio(contentMode: .fit)
Spacer()
}
}
}

// MARK: - ImageRowView_Previews
/// Preview provider for ImageRowView
struct ImageRowView_Previews: PreviewProvider {
static var previews: some View {
ImageRowView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// TextAndImageView.swift
// SwiftUILearning
//
// Created by Shikalgar, Shahrukh on 06/07/20.
// Copyright © 2020 Shahrukh Shikalgar. All rights reserved.
//

import SwiftUI

// MARK: - Struct for TextAndImageView
/// View for TextAndImageView
struct TextAndImageView: View {
// MARK: - View
/// Body for TextSwiftUIView
var body: some View {
ImageWithTextView(title: "Image with Text and Icon", imageName: "image2")
}
}

// MARK: - Struct for ImageWithTextView
/// View for ImageWithTextView
struct ImageWithTextView: View {
// MARK: - Variables
let title: String
let imageName: String

// MARK: - View
/// Body for TextSwiftUIView
var body: some View {
VStack {
HStack {
Image(systemName: "sun.max.fill")
.resizable()
.frame(width: 30, height: 30, alignment: .center)
.font(.body)
.foregroundColor(Color.orange)
Text(title)
.font(.body)
.foregroundColor(Color.orange)
}
.shadow(radius: 10)
Image(imageName)
.resizable()
.scaledToFill()
.frame(width: 200, height: 200, alignment: .center)
.cornerRadius(10)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color.orange, lineWidth: 4))
.shadow(radius: 10)

}
}
}

// MARK: - TextAndImageView_Previews
/// Preview provider for TextAndImageView
struct TextAndImageView_Previews: PreviewProvider {
static var previews: some View {
TextAndImageView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ImageListViewModel.swift
// SwiftUILearning
//
// Created by Shikalgar, Shahrukh on 06/07/20.
// Copyright © 2020 Shahrukh Shikalgar. All rights reserved.
//

import Foundation
import SwiftUI

// MARK: - Class for ImageListViewModel
/// ImageListViewModel class object
class ImageListViewModel {
// MARK: - Variables
/// Model object array
let contentViewItems = [ContentModel(id: 1, contentType: ImageListType.imageView.rawValue),
ContentModel(id: 2, contentType: ImageListType.imageAndTextView.rawValue)]


/// Method to get destination view
/// - Parameter type: Type of view component
func getDestinationView(type: String) -> AnyView {
guard let rowType = ImageListType(rawValue: type) else { return AnyView(EmptyView()) }
switch rowType {
case .imageView:
return AnyView(ImageRowView())
case .imageAndTextView:
return AnyView(TextAndImageView())
}
}
}

0 comments on commit 2b80bda

Please sign in to comment.