-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
564510d
commit 2b80bda
Showing
14 changed files
with
301 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
SwiftUILearning/Assets.xcassets/Images/image1.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
21 changes: 21 additions & 0 deletions
21
SwiftUILearning/Assets.xcassets/Images/image2.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
SwiftUILearning/Components/ImageView/Enum/ImageListType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
SwiftUILearning/Components/ImageView/View/ImageListView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
SwiftUILearning/Components/ImageView/View/SubViews/ImageRowView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
SwiftUILearning/Components/ImageView/View/SubViews/TextAndImageView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
SwiftUILearning/Components/ImageView/ViewModel/ImageListViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} |