Skip to content

Commit 2520e0e

Browse files
authored
[ViewCode-RP] Criação de extensão para usar o Canvas do SwiftUI (#27)
1 parent 0bf8b58 commit 2520e0e

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

solutions/devsprint-rafael-de-paula-1/DeliveryApp.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
69D31C9E28076A73009B02CA /* CategoryItemCollectionViewCellSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D31C9D28076A73009B02CA /* CategoryItemCollectionViewCellSnapshotTests.swift */; };
2525
69D31CA028076C3E009B02CA /* CategoryCarouselTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D31C9F28076C3E009B02CA /* CategoryCarouselTableViewCell.swift */; };
2626
69D31CA228088C49009B02CA /* SeparatorLineTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D31CA128088C49009B02CA /* SeparatorLineTableViewCell.swift */; };
27+
69D31CA4280895BA009B02CA /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D31CA3280895BA009B02CA /* UIView+Extensions.swift */; };
28+
69D31CA628089665009B02CA /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D31CA528089665009B02CA /* UIViewController+Extensions.swift */; };
2729
7141E7C89DBE44E0A62CC1D0 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A063A87CD0AD580FAD73C96 /* String+Extensions.swift */; };
2830
742337EDE77E85114BAC9E85 /* MenuItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99D53954CAAA6939A5F6FD9D /* MenuItemView.swift */; };
2931
876C205298F3FD40E6745563 /* HomeViewSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF5E7FAB0DA77EA09943A31E /* HomeViewSnapshotTests.swift */; };
@@ -65,6 +67,8 @@
6567
69D31C9D28076A73009B02CA /* CategoryItemCollectionViewCellSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryItemCollectionViewCellSnapshotTests.swift; sourceTree = "<group>"; };
6668
69D31C9F28076C3E009B02CA /* CategoryCarouselTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCarouselTableViewCell.swift; sourceTree = "<group>"; };
6769
69D31CA128088C49009B02CA /* SeparatorLineTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorLineTableViewCell.swift; sourceTree = "<group>"; };
70+
69D31CA3280895BA009B02CA /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = "<group>"; };
71+
69D31CA528089665009B02CA /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = "<group>"; };
6872
6CF1C64AFEDEABB1B74D449B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
6973
74EE0AE75090A482AF87444A /* DeliveryAppTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeliveryAppTests.swift; sourceTree = "<group>"; };
7074
7971E7020BBD5644842191DD /* Pods-DeliveryApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DeliveryApp.release.xcconfig"; path = "Target Support Files/Pods-DeliveryApp/Pods-DeliveryApp.release.xcconfig"; sourceTree = "<group>"; };
@@ -276,6 +280,8 @@
276280
isa = PBXGroup;
277281
children = (
278282
5A063A87CD0AD580FAD73C96 /* String+Extensions.swift */,
283+
69D31CA3280895BA009B02CA /* UIView+Extensions.swift */,
284+
69D31CA528089665009B02CA /* UIViewController+Extensions.swift */,
279285
);
280286
path = Extensions;
281287
sourceTree = "<group>";
@@ -502,6 +508,7 @@
502508
EE89F87B9B10B1971D03DC4E /* MenuItemViewController.swift in Sources */,
503509
031E56C3C98F1ABEF07BC135 /* Restaurant.swift in Sources */,
504510
359FA3D03548CEE255D6C425 /* RestaurantDetails.swift in Sources */,
511+
69D31CA4280895BA009B02CA /* UIView+Extensions.swift in Sources */,
505512
D48DEA1EDC4CC8A5CC46541F /* RestaurantDetailsView.swift in Sources */,
506513
CD02B16590C6FAA9467F6C46 /* RestaurantDetailsViewController.swift in Sources */,
507514
41621C7BE3A3D88908857236 /* RestaurantListItemTableViewCell.swift in Sources */,
@@ -515,6 +522,7 @@
515522
7141E7C89DBE44E0A62CC1D0 /* String+Extensions.swift in Sources */,
516523
BEC96BC61BF1F740550B943D /* ViewCode.swift in Sources */,
517524
69D31CA028076C3E009B02CA /* CategoryCarouselTableViewCell.swift in Sources */,
525+
69D31CA628089665009B02CA /* UIViewController+Extensions.swift in Sources */,
518526
);
519527
runOnlyForDeploymentPostprocessing = 0;
520528
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// UIView+Extensions.swift
3+
// DeliveryApp
4+
//
5+
// Created by Rafael de Paula on 14/04/22.
6+
//
7+
8+
import SwiftUI
9+
import UIKit
10+
11+
extension UIView {
12+
13+
@available(iOS 13, *)
14+
private struct Preview: UIViewRepresentable {
15+
typealias UIViewType = UIView
16+
let view: UIView
17+
18+
func makeUIView(context: Context) -> UIView {
19+
return view
20+
}
21+
22+
func updateUIView(_ uiView: UIView, context: Context) { }
23+
}
24+
25+
@available(iOS 13, *)
26+
func showPreview() -> some View {
27+
Preview(view: self)
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// UIViewController+Extensions.swift
3+
// DeliveryApp
4+
//
5+
// Created by Rafael de Paula on 14/04/22.
6+
//
7+
8+
import SwiftUI
9+
import UIKit
10+
11+
extension UIViewController {
12+
13+
@available(iOS 13, *)
14+
private struct Preview: UIViewControllerRepresentable {
15+
let viewController: UIViewController
16+
17+
func makeUIViewController(context: Context) -> UIViewController {
18+
return viewController
19+
}
20+
21+
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { }
22+
}
23+
24+
@available(iOS 13, *)
25+
func showPreview() -> some View {
26+
Preview(viewController: self)
27+
}
28+
}

solutions/devsprint-rafael-de-paula-1/DeliveryApp/Screens/Components/EmptyView.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import UIKit
99

10-
class EmptyView: UIView {
10+
final class EmptyView: UIView {
1111

1212
private enum DefaultTexts {
1313
static let titleLabel = "Endereço não encontrado"
@@ -77,3 +77,13 @@ extension EmptyView: ViewCode {
7777
])
7878
}
7979
}
80+
81+
#if DEBUG
82+
import SwiftUI
83+
84+
struct EmptyView_Preview: PreviewProvider {
85+
static var previews: some View {
86+
EmptyView().showPreview()
87+
}
88+
}
89+
#endif

0 commit comments

Comments
 (0)