Item styling
This commit is contained in:
parent
73a2f20d7d
commit
602688051f
|
@ -18,6 +18,14 @@ extension ColorScheme {
|
|||
var previewName: String {
|
||||
String(describing: self).capitalized
|
||||
}
|
||||
|
||||
var systemImageName: String {
|
||||
switch self {
|
||||
case .dark: return "sun.max.fill"
|
||||
case .light: return "sun.max"
|
||||
@unknown default: return "questionmark"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 13, *)
|
||||
|
|
|
@ -3,7 +3,9 @@ import SwiftUI
|
|||
#endif
|
||||
import UIKit
|
||||
|
||||
@available(iOS 13, *)
|
||||
// TODO: remove UIView dependency
|
||||
|
||||
@available(iOS 14, *)
|
||||
struct CatalogItem<Content: UIViewCatalogPresentable>: View {
|
||||
let configuration: UICatalog.PreviewConfiguration
|
||||
|
||||
|
@ -17,27 +19,28 @@ struct CatalogItem<Content: UIViewCatalogPresentable>: View {
|
|||
|
||||
func item(model: Content.PreviewModel,
|
||||
scheme: ColorScheme) -> some View {
|
||||
VStack(alignment: .center, spacing: 12.0) {
|
||||
Text("\(scheme.previewName): \(String(describing: model))")
|
||||
.font(.subheadline)
|
||||
.fontWeight(.bold)
|
||||
|
||||
|
||||
VStack(alignment: .center, spacing: 0) {
|
||||
Label(String(describing: model), systemImage: scheme.systemImageName)
|
||||
|
||||
Content.preview(with: model)
|
||||
.frame(maxWidth: .infinity)
|
||||
.background(Color(.systemBackground))
|
||||
.colorScheme(scheme)
|
||||
Divider()
|
||||
.background(Color.secondary)
|
||||
}
|
||||
.background(Color(.systemGroupedBackground))
|
||||
.cornerRadius(6)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
@available(iOS 13, *)
|
||||
@available(iOS 14, *)
|
||||
struct CatalogItem_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
ScrollView {
|
||||
ScrollView(.vertical) {
|
||||
CatalogItem<TestView>(configuration: .init())
|
||||
}.navigationBarTitle("TestView")
|
||||
}
|
||||
|
@ -47,11 +50,22 @@ struct CatalogItem_Previews: PreviewProvider {
|
|||
private final class TestView: UILabel, UICatalogPresentable {
|
||||
static var previewModels = [
|
||||
"Hello world",
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"
|
||||
// "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
|
||||
"Hello2 world",
|
||||
"Hello3 world",
|
||||
"Hello4 world",
|
||||
"Hello world",
|
||||
"Hello world",
|
||||
"Hello world",
|
||||
"Hello world",
|
||||
"Hello world",
|
||||
"Hello world",
|
||||
]
|
||||
|
||||
func apply(previewModel: String) {
|
||||
text = previewModel
|
||||
textColor = .systemRed
|
||||
numberOfLines = 0
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ extension UICatalog {
|
|||
|
||||
}
|
||||
|
||||
@available(iOS 13, *)
|
||||
@available(iOS 14, *)
|
||||
public extension UICatalog.PreviewDescriptor {
|
||||
init<Content>(_ content: Content.Type,
|
||||
configuration: UICatalog.PreviewConfiguration = .init(),
|
||||
|
|
Loading…
Reference in New Issue