This commit is contained in:
John Estropia
2020-08-30 10:24:10 +09:00
parent b26e50f777
commit 007da014f8
7 changed files with 12 additions and 113 deletions

View File

@@ -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
}
}
}

View File

@@ -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
)
)
}
}

View File

@@ -36,6 +36,7 @@ extension Modern.ColorsDemo.SwiftUI {
Modern.ColorsDemo.SwiftUI.ItemView(palette)
}
)
.listRowInsets(.init())
}
.onDelete { itemIndices in

View File

@@ -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))

View File

@@ -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
}

View File

@@ -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
)
}
}