import AppKit import SwiftUI /// Keeps card rendering inside a fixed-size child host. struct NativeContentHost: NSViewRepresentable { let content: Content func makeNSView(context: Context) -> NSHostingView { let host = NSHostingView(rootView: root(context)) // The parent owns the card frame, including its responsive column width. host.sizingOptions = [] return host } func updateNSView(_ host: NSHostingView, context: Context) { host.rootView = root(context) } func sizeThatFits(_ proposal: ProposedViewSize, nsView: NSHostingView, context: Context) -> CGSize? { CGSize(width: proposal.width.flatMap { $0.isFinite ? max(0, $0) : nil } ?? 10, height: proposal.height.flatMap { $0.isFinite ? max(0, $0) : nil } ?? 10) } static func dismantleNSView(_ host: NSHostingView, coordinator: ()) { // AppKit may cache a detached view. Release its mounted content immediately. host.rootView = AnyView(EmptyView()) } private func root(_ context: Context) -> AnyView { AnyView(content.environment(\.self, context.environment)) } }