Code cleanup
This commit is contained in:
parent
2308051854
commit
7daeeaed05
|
@ -1,11 +0,0 @@
|
|||
#if canImport(SwiftUI)
|
||||
import SwiftUI
|
||||
#endif
|
||||
|
||||
@available(iOS 13, *)
|
||||
extension Binding {
|
||||
public static func mock(_ value: Value) -> Self {
|
||||
var value = value
|
||||
return Binding(get: { value }, set: { value = $0 })
|
||||
}
|
||||
}
|
|
@ -4,10 +4,12 @@ import SwiftUI
|
|||
|
||||
@available(iOS 13, *)
|
||||
extension View {
|
||||
/// Generate preview in the `.light` theme
|
||||
public func previewLightTheme() -> some View {
|
||||
ColorSchemePreview(scheme: .light) { self }
|
||||
}
|
||||
|
||||
/// Generate preview in the `.dark` theme
|
||||
public func previewDarkTheme() -> some View {
|
||||
ColorSchemePreview(scheme: .dark) { self }
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import SwiftUI
|
|||
|
||||
@available(iOS 13, *)
|
||||
extension View {
|
||||
/// Generate preview in the multiple themes and size categories
|
||||
public func previewAsComponent() -> some View {
|
||||
ComponentPreview(component: self)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public let defaultDeviceNames: [String] =
|
|||
|
||||
@available(iOS 13, *)
|
||||
extension View {
|
||||
/// Generate preview in the multiple themes and devices
|
||||
public func previewAsScreen(deviceNames: [String] = defaultDeviceNames) -> some View {
|
||||
ScreenPreview(screen: self, deviceNames: deviceNames)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import SwiftUI
|
|||
import UIKit
|
||||
|
||||
@available(iOS 14, *)
|
||||
struct CatalogItem<Content: UICatalogPresentable>: View {
|
||||
struct CatalogItemView<Content: UICatalogPresentable>: View {
|
||||
let configuration: UICatalog.PreviewConfiguration
|
||||
|
||||
var body: some View {
|
||||
|
@ -30,7 +30,7 @@ struct CatalogItem_Previews: PreviewProvider {
|
|||
NavigationView {
|
||||
ScrollView(.vertical) {
|
||||
PreviewLegend()
|
||||
CatalogItem<TestView>(configuration: .init())
|
||||
CatalogItemView<TestView>(configuration: .init())
|
||||
}.navigationBarTitle("TestView")
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ import SwiftUI
|
|||
#endif
|
||||
|
||||
@available(iOS 14, *)
|
||||
struct GroupItem<Content>: View where Content: View {
|
||||
struct GroupItemView<Content>: View where Content: View {
|
||||
struct Model {
|
||||
let title: String
|
||||
let content: () -> Content
|
||||
|
@ -26,7 +26,7 @@ struct GroupItem_Previews: PreviewProvider {
|
|||
static var previews: some View {
|
||||
ScrollView {
|
||||
PreviewLegend()
|
||||
GroupItem(items: [
|
||||
GroupItemView(items: [
|
||||
.init(title: "Group 1",
|
||||
content: { AnyView(Text("Preview")) }),
|
||||
.init(title: "Group 2",
|
|
@ -36,10 +36,10 @@ public extension UICatalog.PreviewDescriptor {
|
|||
/// - title: preview title
|
||||
init<Content>(_ content: Content.Type,
|
||||
configuration: UICatalog.PreviewConfiguration = .init(),
|
||||
title: String? = nil) where Content: UIViewCatalogPresentable {
|
||||
title: String? = nil) where Content: UICatalogPresentable {
|
||||
id = "\(content)"
|
||||
self.title = title ?? "\(content)"
|
||||
builder = { CatalogItem<Content>(configuration: configuration).eraseToAny() }
|
||||
builder = { CatalogItemView<Content>(configuration: configuration).eraseToAny() }
|
||||
}
|
||||
|
||||
/// Group multiple previews together
|
||||
|
@ -59,7 +59,7 @@ public extension UICatalog.PreviewDescriptor {
|
|||
title: String? = nil) {
|
||||
id = content.map(\.id).joined()
|
||||
self.title = title ?? content.map(\.title).joined(separator: " ")
|
||||
let items = content.map { GroupItem.Model(title: $0.title, content: $0.builder) }
|
||||
builder = { GroupItem(items: items).eraseToAny() }
|
||||
let items = content.map { GroupItemView.Model(title: $0.title, content: $0.builder) }
|
||||
builder = { GroupItemView(items: items).eraseToAny() }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ extension UICatalogPresentable {
|
|||
}
|
||||
}
|
||||
|
||||
public typealias UIViewCatalogPresentable = UIView & UICatalogPresentable
|
||||
|
||||
@available(iOS 13, *)
|
||||
extension UICatalogPresentable where Self: UIView {
|
||||
public func preview(with model: PreviewModel) -> AnyView {
|
||||
|
|
Loading…
Reference in New Issue