From f6a1efeaeef5e88e94b4c788c4986242b3a5ea81 Mon Sep 17 00:00:00 2001 From: Muukii Date: Tue, 16 Apr 2024 14:47:59 +0900 Subject: [PATCH] Update --- .../Primitives/BookProvider.swift | 4 -- .../StorybookDisplayRootView.swift | 40 ++++++++++++++----- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Sources/StorybookKit/Primitives/BookProvider.swift b/Sources/StorybookKit/Primitives/BookProvider.swift index db4760b..f16f8ae 100644 --- a/Sources/StorybookKit/Primitives/BookProvider.swift +++ b/Sources/StorybookKit/Primitives/BookProvider.swift @@ -27,10 +27,6 @@ public protocol BookProvider { static var bookBody: BookPage { get } } -public protocol BookType: View { - -} - private enum BookContextKey: EnvironmentKey { static var defaultValue: BookStore? } diff --git a/Sources/StorybookKit/StorybookDisplayRootView.swift b/Sources/StorybookKit/StorybookDisplayRootView.swift index 7424f94..88971d7 100644 --- a/Sources/StorybookKit/StorybookDisplayRootView.swift +++ b/Sources/StorybookKit/StorybookDisplayRootView.swift @@ -10,16 +10,30 @@ public struct StorybookDisplayRootView: View { public init(bookStore: BookStore) { self.book = .init(store: bookStore) } - - @MainActor - public init(book: any BookType) { - self.book = .init(store: .init(book: book)) + + public var body: some View { + + _ViewControllerHost { + let controller = _ViewController(content: book) + return controller + } + .ignoresSafeArea() + + } +} + +public struct BookActionHosting: View { + + private let content: Content + + public init(_ content: Content) { + self.content = content } public var body: some View { _ViewControllerHost { - let controller = _ViewController(book: book) + let controller = _ViewController(content: content) return controller } .ignoresSafeArea() @@ -27,7 +41,7 @@ public struct StorybookDisplayRootView: View { } } -struct BookContainer: BookType { +struct BookContainer: View { @ObservedObject var store: BookStore @State var isSearching: Bool = false @@ -130,12 +144,12 @@ struct BookContainer: BookType { } -final class _ViewController: UIViewController { +final class _ViewController: UIViewController { - private let book: Book + private let content: Content - init(book: Book) { - self.book = book + init(content: Content) { + self.content = content super.init(nibName: nil, bundle: nil) } @@ -148,7 +162,7 @@ final class _ViewController: UIViewController { let hosting = UIHostingController( rootView: - book + content .environment(\._targetViewController, self) ) @@ -168,3 +182,7 @@ final class _ViewController: UIViewController { } } + +#Preview { + BookActionHosting(BookAction(title: "Hello", action: { vc in })) +}