From 3aa94b17d732d11cea2d200ea565cda7e12900a1 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 2 Dec 2024 09:38:07 +0900 Subject: [PATCH] WIP --- .../StorybookKit/Internals/machOLoader.swift | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Sources/StorybookKit/Internals/machOLoader.swift b/Sources/StorybookKit/Internals/machOLoader.swift index 2b5fdf6..daeb00c 100644 --- a/Sources/StorybookKit/Internals/machOLoader.swift +++ b/Sources/StorybookKit/Internals/machOLoader.swift @@ -113,6 +113,38 @@ extension Book { metadataAccessFunction, to: Any.Type.self ) + if #available(iOS 17.0, *) { + if let previewType = anyType as? any DeveloperToolsSupport.PreviewRegistry.Type { + print("========") + print("fileID: \(previewType.fileID)") + print("line: \(previewType.line)") + print("column: \(previewType.column)") + + let preview = try! previewType.makePreview() + dump(preview) + + let mirror: Mirror = .init(reflecting: preview) + for child in mirror.children { + switch child.label { + case "displayName": + print("displayName: \(child.value)") + + case "source": + let mirror: Mirror = .init(reflecting: child.value) + let factory = mirror.children.first!.value as! @MainActor () -> any SwiftUI.View +// let view = AnyView(factory()) + print("view:") + let anyView: AnyView = MainActor.assumeIsolated(factory) as! AnyView + dump(anyView) + print("========") + + default: + break + } + } + print("========") + } + } guard let bookProviderType = anyType as? any BookProvider.Type else { continue }