From 007da014f807d59522fe7ca94de7d574a936b4fa Mon Sep 17 00:00:00 2001 From: John Estropia Date: Sun, 30 Aug 2020 10:24:10 +0900 Subject: [PATCH] cleanup --- Demo/Demo.xcodeproj/project.pbxproj | 8 --- .../Modern.ColorsDemo.UIKit.ItemCell.swift | 7 +-- ...⭐️Modern.ColorsDemo.SwiftUI.ItemView.swift | 10 ++-- ...⭐️Modern.ColorsDemo.SwiftUI.ListView.swift | 1 + ...odern.PokedexDemo.ListViewController.swift | 5 +- Demo/Sources/Helpers/NetworkImageView.swift | 51 ------------------- Demo/Sources/Helpers/UIImage+Extensions.swift | 43 ---------------- 7 files changed, 12 insertions(+), 113 deletions(-) delete mode 100644 Demo/Sources/Helpers/NetworkImageView.swift delete mode 100644 Demo/Sources/Helpers/UIImage+Extensions.swift diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index fef68e1..9bca030 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ B531EFE924EB5A53005F247D /* ⭐️Modern.PokedexDemo.PokedexEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = B531EFE824EB5A52005F247D /* ⭐️Modern.PokedexDemo.PokedexEntry.swift */; }; B531EFEB24EB5ECD005F247D /* ⭐️Modern.PokedexDemo.Service.swift in Sources */ = {isa = PBXBuildFile; fileRef = B531EFEA24EB5ECD005F247D /* ⭐️Modern.PokedexDemo.Service.swift */; }; B531EFED24EB7453005F247D /* Modern.PokedexDemo.MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B531EFEC24EB7453005F247D /* Modern.PokedexDemo.MainView.swift */; }; - B566C8E624ED6B98001134A1 /* NetworkImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B566C8E524ED6B98001134A1 /* NetworkImageView.swift */; }; B566C8E824F9D406001134A1 /* Modern.PokedexDemo.ListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B566C8E724F9D406001134A1 /* Modern.PokedexDemo.ListView.swift */; }; B566C8EA24F9D412001134A1 /* Modern.PokedexDemo.ListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B566C8E924F9D412001134A1 /* Modern.PokedexDemo.ListViewController.swift */; }; B566C8EC24F9D694001134A1 /* Modern.PokedexDemo.ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B566C8EB24F9D694001134A1 /* Modern.PokedexDemo.ItemCell.swift */; }; @@ -60,7 +59,6 @@ B5A391A224E8F01F00E7E8BD /* ⭐️Modern.ColorsDemo.UIKit.ListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391A124E8F01F00E7E8BD /* ⭐️Modern.ColorsDemo.UIKit.ListViewController.swift */; }; B5A391A424E8F04300E7E8BD /* Modern.ColorsDemo.UIKit.ListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391A324E8F04300E7E8BD /* Modern.ColorsDemo.UIKit.ListView.swift */; }; B5A391A624E8F4EA00E7E8BD /* ⭐️Modern.ColorsDemo.MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391A524E8F4EA00E7E8BD /* ⭐️Modern.ColorsDemo.MainView.swift */; }; - B5A391A824E90F1000E7E8BD /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391A724E90F1000E7E8BD /* UIImage+Extensions.swift */; }; B5A391AA24E9104300E7E8BD /* Modern.ColorsDemo.UIKit.ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391A924E9104300E7E8BD /* Modern.ColorsDemo.UIKit.ItemCell.swift */; }; B5A391AC24E9143B00E7E8BD /* Modern.ColorsDemo.UIKit.DetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391AB24E9143B00E7E8BD /* Modern.ColorsDemo.UIKit.DetailView.swift */; }; B5A391AE24E9150F00E7E8BD /* ⭐️Modern.ColorsDemo.UIKit.DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A391AD24E9150F00E7E8BD /* ⭐️Modern.ColorsDemo.UIKit.DetailViewController.swift */; }; @@ -93,7 +91,6 @@ B531EFE824EB5A52005F247D /* ⭐️Modern.PokedexDemo.PokedexEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "⭐️Modern.PokedexDemo.PokedexEntry.swift"; sourceTree = ""; }; B531EFEA24EB5ECD005F247D /* ⭐️Modern.PokedexDemo.Service.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "⭐️Modern.PokedexDemo.Service.swift"; sourceTree = ""; }; B531EFEC24EB7453005F247D /* Modern.PokedexDemo.MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.PokedexDemo.MainView.swift; sourceTree = ""; }; - B566C8E524ED6B98001134A1 /* NetworkImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkImageView.swift; sourceTree = ""; }; B566C8E724F9D406001134A1 /* Modern.PokedexDemo.ListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.PokedexDemo.ListView.swift; sourceTree = ""; }; B566C8E924F9D412001134A1 /* Modern.PokedexDemo.ListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.PokedexDemo.ListViewController.swift; sourceTree = ""; }; B566C8EB24F9D694001134A1 /* Modern.PokedexDemo.ItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.PokedexDemo.ItemCell.swift; sourceTree = ""; }; @@ -141,7 +138,6 @@ B5A391A124E8F01F00E7E8BD /* ⭐️Modern.ColorsDemo.UIKit.ListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "⭐️Modern.ColorsDemo.UIKit.ListViewController.swift"; sourceTree = ""; }; B5A391A324E8F04300E7E8BD /* Modern.ColorsDemo.UIKit.ListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.ColorsDemo.UIKit.ListView.swift; sourceTree = ""; }; B5A391A524E8F4EA00E7E8BD /* ⭐️Modern.ColorsDemo.MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "⭐️Modern.ColorsDemo.MainView.swift"; sourceTree = ""; }; - B5A391A724E90F1000E7E8BD /* UIImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = ""; }; B5A391A924E9104300E7E8BD /* Modern.ColorsDemo.UIKit.ItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.ColorsDemo.UIKit.ItemCell.swift; sourceTree = ""; }; B5A391AB24E9143B00E7E8BD /* Modern.ColorsDemo.UIKit.DetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modern.ColorsDemo.UIKit.DetailView.swift; sourceTree = ""; }; B5A391AD24E9150F00E7E8BD /* ⭐️Modern.ColorsDemo.UIKit.DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "⭐️Modern.ColorsDemo.UIKit.DetailViewController.swift"; sourceTree = ""; }; @@ -306,9 +302,7 @@ children = ( B5A3917B24E6A76C00E7E8BD /* LazyView.swift */, B5A3917F24E787D900E7E8BD /* InstructionsView.swift */, - B566C8E524ED6B98001134A1 /* NetworkImageView.swift */, B5E32C8F24FA41F9003F46AD /* ImageDownloader.swift */, - B5A391A724E90F1000E7E8BD /* UIImage+Extensions.swift */, B5A3915424E6857F00E7E8BD /* Menu */, ); path = Helpers; @@ -484,7 +478,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - B5A391A824E90F1000E7E8BD /* UIImage+Extensions.swift in Sources */, B5A3911D24E5429200E7E8BD /* AppDelegate.swift in Sources */, B5A3915924E685EC00E7E8BD /* Classic.swift in Sources */, B5E32C9024FA41F9003F46AD /* ImageDownloader.swift in Sources */, @@ -492,7 +485,6 @@ B5A3917C24E6A76C00E7E8BD /* LazyView.swift in Sources */, B5A3913424E6170500E7E8BD /* Menu.swift in Sources */, B5A3915B24E685FE00E7E8BD /* Modern.swift in Sources */, - B566C8E624ED6B98001134A1 /* NetworkImageView.swift in Sources */, B5A3911F24E5429200E7E8BD /* SceneDelegate.swift in Sources */, B5A3915324E6537F00E7E8BD /* Menu.ItemView.swift in Sources */, B5A3912124E5429200E7E8BD /* Menu.MainView.swift in Sources */, diff --git a/Demo/Sources/Demos/Modern/ColorsDemo/Modern.ColorsDemo.UIKit.ItemCell.swift b/Demo/Sources/Demos/Modern/ColorsDemo/Modern.ColorsDemo.UIKit.ItemCell.swift index 2d83029..69f979f 100644 --- a/Demo/Sources/Demos/Modern/ColorsDemo/Modern.ColorsDemo.UIKit.ItemCell.swift +++ b/Demo/Sources/Demos/Modern/ColorsDemo/Modern.ColorsDemo.UIKit.ItemCell.swift @@ -20,12 +20,9 @@ extension Modern.ColorsDemo.UIKit { func setPalette(_ palette: Modern.ColorsDemo.Palette) { - self.imageView?.image = UIImage( - color: palette.color, - size: .init(width: 30, height: 30), - cornerRadius: 5 - ) + self.contentView.backgroundColor = palette.color self.textLabel?.text = palette.colorText + self.textLabel?.textColor = palette.brightness > 0.6 ? .black : .white } } } diff --git a/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ItemView.swift b/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ItemView.swift index 97dbee9..1ea723d 100644 --- a/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ItemView.swift +++ b/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ItemView.swift @@ -37,12 +37,12 @@ extension Modern.ColorsDemo.SwiftUI { return AnyView(EmptyView()) } return AnyView( - HStack { - Color(palette.$color) - .cornerRadius(5) - .frame(width: 30, height: 30, alignment: .leading) + Color(palette.$color).overlay( Text(palette.$colorText) - } + .foregroundColor(palette.$brightness > 0.6 ? .black : .white) + .padding(), + alignment: .leading + ) ) } } diff --git a/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift b/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift index fee31e2..55d145c 100644 --- a/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift +++ b/Demo/Sources/Demos/Modern/ColorsDemo/⭐️Modern.ColorsDemo.SwiftUI.ListView.swift @@ -36,6 +36,7 @@ extension Modern.ColorsDemo.SwiftUI { Modern.ColorsDemo.SwiftUI.ItemView(palette) } ) + .listRowInsets(.init()) } .onDelete { itemIndices in diff --git a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.ListViewController.swift b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.ListViewController.swift index 772f6f7..f9b9c4f 100644 --- a/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.ListViewController.swift +++ b/Demo/Sources/Demos/Modern/PokedexDemo/Modern.PokedexDemo.ListViewController.swift @@ -33,7 +33,10 @@ extension Modern.PokedexDemo { let screenWidth = UIScreen.main.bounds.inset(by: layout.sectionInset).width let cellsPerRow: CGFloat = 3 - let cellWidth = floor((screenWidth - ((cellsPerRow - 1) * layout.minimumInteritemSpacing)) / cellsPerRow) + let cellWidth = min( + 230, + floor((screenWidth - ((cellsPerRow - 1) * layout.minimumInteritemSpacing)) / cellsPerRow) + ) layout.itemSize = .init( width: cellWidth, height: ceil(cellWidth * (4 / 3)) diff --git a/Demo/Sources/Helpers/NetworkImageView.swift b/Demo/Sources/Helpers/NetworkImageView.swift deleted file mode 100644 index 5094493..0000000 --- a/Demo/Sources/Helpers/NetworkImageView.swift +++ /dev/null @@ -1,51 +0,0 @@ -// -// Demo -// Copyright © 2020 John Rommel Estropia, Inc. All rights reserved. - -import Combine -import SwiftUI - -// MARK: - NetworkImageView - -struct NetworkImageView: View { - - // MARK: Internal - - init(url: URL?) { - - self.imageDownloader = .init(url: url) - } - - - // MARK: View - - var body: some View { - - if let image = self.imageDownloader.image { - - return AnyView( - Image(uiImage: image) - .resizable() - .aspectRatio(contentMode: .fit) - ) - } - else { - - return AnyView( - Circle() - .colorMultiply(Color(UIColor.placeholderText)) - .onAppear { - - self.imageDownloader.fetchImage() - } - ) - } - } - - - // MARK: Private - - @ObservedObject - private var imageDownloader: ImageDownloader -} - diff --git a/Demo/Sources/Helpers/UIImage+Extensions.swift b/Demo/Sources/Helpers/UIImage+Extensions.swift deleted file mode 100644 index 8dde2fe..0000000 --- a/Demo/Sources/Helpers/UIImage+Extensions.swift +++ /dev/null @@ -1,43 +0,0 @@ -// -// Demo -// Copyright © 2020 John Rommel Estropia, Inc. All rights reserved. - -import UIKit - - -// MARK: - UIImage - -extension UIImage { - - // MARK: Internal - - convenience init( - color: UIColor, - size: CGSize = CGSize(width: 1, height: 1), - cornerRadius: CGFloat = 0 - ) { - let rect = CGRect(origin: .zero, size: size) - let scale = UIScreen.main.scale - UIGraphicsBeginImageContextWithOptions(rect.size, false, scale) - defer { - UIGraphicsEndImageContext() - } - let context = UIGraphicsGetCurrentContext()! - - if cornerRadius > 0 { - UIBezierPath( - roundedRect: rect, - cornerRadius: cornerRadius - ) - .addClip() - } - color.setFill() - context.fill(rect) - - self.init( - cgImage: UIGraphicsGetImageFromCurrentImageContext()!.cgImage!, - scale: scale, - orientation: .up - ) - } -}