Remove UIview dependency
This commit is contained in:
parent
4db7508f38
commit
f608f74f74
|
@ -3,10 +3,8 @@ import SwiftUI
|
||||||
#endif
|
#endif
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
// TODO: remove UIView dependency
|
|
||||||
|
|
||||||
@available(iOS 14, *)
|
@available(iOS 14, *)
|
||||||
struct CatalogItem<Content: UIViewCatalogPresentable>: View {
|
struct CatalogItem<Content: UICatalogPresentable>: View {
|
||||||
let configuration: UICatalog.PreviewConfiguration
|
let configuration: UICatalog.PreviewConfiguration
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
|
@ -11,18 +11,24 @@ public protocol UICatalogPresentable {
|
||||||
static var previewModels: [PreviewModel] { get }
|
static var previewModels: [PreviewModel] { get }
|
||||||
|
|
||||||
static func makePreviewInstance() -> Self
|
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
|
public typealias UIViewCatalogPresentable = UIView & UICatalogPresentable
|
||||||
|
|
||||||
@available(iOS 13, *)
|
@available(iOS 13, *)
|
||||||
extension UICatalogPresentable where Self: UIView {
|
extension UICatalogPresentable where Self: UIView {
|
||||||
public func preview(with model: PreviewModel) -> some View {
|
public func preview(with model: PreviewModel) -> AnyView {
|
||||||
UIViewWrapper(self) { $0.apply(previewModel: model) }
|
AnyView(UIViewWrapper(self) { $0.apply(previewModel: model) })
|
||||||
}
|
|
||||||
|
|
||||||
public static func preview(with model: PreviewModel) -> some View {
|
|
||||||
makePreviewInstance().preview(with: model)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue