Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Apr 16, 2024
1 parent a5f6541 commit f6a1efe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
4 changes: 0 additions & 4 deletions Sources/StorybookKit/Primitives/BookProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public protocol BookProvider {
static var bookBody: BookPage { get }
}

public protocol BookType: View {

}

private enum BookContextKey: EnvironmentKey {
static var defaultValue: BookStore?
}
Expand Down
40 changes: 29 additions & 11 deletions Sources/StorybookKit/StorybookDisplayRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,38 @@ 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<Content: View>: 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()

}
}

struct BookContainer: BookType {
struct BookContainer: View {

@ObservedObject var store: BookStore
@State var isSearching: Bool = false
Expand Down Expand Up @@ -130,12 +144,12 @@ struct BookContainer: BookType {

}

final class _ViewController<Book: BookType>: UIViewController {
final class _ViewController<Content: View>: 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)
}

Expand All @@ -148,7 +162,7 @@ final class _ViewController<Book: BookType>: UIViewController {

let hosting = UIHostingController(
rootView:
book
content
.environment(\._targetViewController, self)
)

Expand All @@ -168,3 +182,7 @@ final class _ViewController<Book: BookType>: UIViewController {
}

}

#Preview {
BookActionHosting(BookAction(title: "Hello", action: { vc in }))
}

0 comments on commit f6a1efe

Please sign in to comment.