Remove UIview dependency

This commit is contained in:
Alexandr Goncharov 2020-10-19 20:09:13 +03:00
parent 4db7508f38
commit f608f74f74
2 changed files with 13 additions and 9 deletions

View File

@ -3,10 +3,8 @@ import SwiftUI
#endif
import UIKit
// TODO: remove UIView dependency
@available(iOS 14, *)
struct CatalogItem<Content: UIViewCatalogPresentable>: View {
struct CatalogItem<Content: UICatalogPresentable>: View {
let configuration: UICatalog.PreviewConfiguration
var body: some View {

View File

@ -11,18 +11,24 @@ public protocol UICatalogPresentable {
static var previewModels: [PreviewModel] { get }
static func makePreviewInstance() -> Self
@available(iOS 13, *)
func preview(with model: PreviewModel) -> AnyView
}
@available(iOS 13, *)
extension UICatalogPresentable {
public static func preview(with model: PreviewModel) -> some View {
makePreviewInstance().preview(with: model)
}
}
public typealias UIViewCatalogPresentable = UIView & UICatalogPresentable
@available(iOS 13, *)
extension UICatalogPresentable where Self: UIView {
public func preview(with model: PreviewModel) -> some View {
UIViewWrapper(self) { $0.apply(previewModel: model) }
}
public static func preview(with model: PreviewModel) -> some View {
makePreviewInstance().preview(with: model)
public func preview(with model: PreviewModel) -> AnyView {
AnyView(UIViewWrapper(self) { $0.apply(previewModel: model) })
}
}