Skip to content

Commit

Permalink
Filling out more of NSUIViewRepresentable
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Mar 30, 2024
1 parent 1390ba9 commit 16d736b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/NSUI/ViewControllerRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol NSUIViewControllerRepresentable: NSViewControllerRepresentable w

@available(macOS 13.0, *)
@MainActor
func sizeThatFits(_ proposal: ProposedViewSize, nsUIViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize?
func sizeThatFits(_ proposal: ProposedViewSize, nsuiViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize?
}

public extension NSUIViewControllerRepresentable {
Expand All @@ -37,7 +37,7 @@ public extension NSUIViewControllerRepresentable {
@available(macOS 13.0, *)
@MainActor
func sizeThatFits(_ proposal: ProposedViewSize, nsViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize? {
sizeThatFits(proposal, nsUIViewController: nsViewController, context: context)
sizeThatFits(proposal, nsuiViewController: nsViewController, context: context)
}
}

Expand All @@ -56,7 +56,7 @@ public protocol NSUIViewControllerRepresentable: UIViewControllerRepresentable w

@available(iOS 16.0, tvOS 16.0, *)
@MainActor
func sizeThatFits(_ proposal: ProposedViewSize, nsUIViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize?
func sizeThatFits(_ proposal: ProposedViewSize, nsuiViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize?
}

public extension NSUIViewControllerRepresentable {
Expand All @@ -82,7 +82,7 @@ public extension NSUIViewControllerRepresentable {
uiViewController: Self.NSUIViewControllerType,
context: Self.Context
) -> CGSize? {
sizeThatFits(proposal, nsUIViewController: uiViewController, context: context)
sizeThatFits(proposal, nsuiViewController: uiViewController, context: context)
}
}
#endif
Expand All @@ -94,7 +94,7 @@ extension NSUIViewControllerRepresentable {

@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
@MainActor
public func sizeThatFits(_ proposal: ProposedViewSize, nsUIViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize? {
public func sizeThatFits(_ proposal: ProposedViewSize, nsuiViewController: Self.NSUIViewControllerType, context: Self.Context) -> CGSize? {
nil
}
}
40 changes: 40 additions & 0 deletions Sources/NSUI/ViewRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public protocol NSUIViewRepresentable: NSViewRepresentable {
func makeNSUIView(context: Context) -> NSUIViewType
@MainActor
func updateNSUIView(_ view: NSUIViewType, context: Context)
@MainActor
static func dismantleNSUIView(_ view: Self.NSUIViewType, coordinator: Self.Coordinator)
@available(macOS 13.0, *)
@MainActor func sizeThatFits(_ proposal: ProposedViewSize, nsuiView: Self.NSUIViewType, context: Self.Context) -> CGSize?
}

public extension NSUIViewRepresentable {
Expand All @@ -22,6 +26,16 @@ public extension NSUIViewRepresentable {
func updateNSView(_ view: NSUIViewType, context: Context) {
updateNSUIView(view, context: context)
}

@MainActor
static func dismantleNSView(_ nsView: Self.NSUIViewType, coordinator: Self.Coordinator) {
Self.dismantleNSUIView(nsView, coordinator: coordinator)
}

@available(macOS 13.0, *)
@MainActor func sizeThatFits(_ proposal: ProposedViewSize, nsView: Self.NSUIViewType, context: Self.Context) -> CGSize? {
sizeThatFits(proposal, nsuiView: nsView, context: context)
}
}

#elseif canImport(UIKit)
Expand All @@ -34,6 +48,10 @@ public protocol NSUIViewRepresentable: UIViewRepresentable {
func makeNSUIView(context: Context) -> NSUIViewType
@MainActor
func updateNSUIView(_ view: NSUIViewType, context: Context)
@MainActor
static func dismantleNSUIView(_ view: Self.NSUIViewType, coordinator: Self.Coordinator)
@available(iOS 16.0, tvOS 16.0, *)
@MainActor func sizeThatFits(_ proposal: ProposedViewSize, nsuiView: Self.NSUIViewType, context: Self.Context) -> CGSize?
}

public extension NSUIViewRepresentable {
Expand All @@ -46,6 +64,28 @@ public extension NSUIViewRepresentable {
func updateUIView(_ view: NSUIViewType, context: Context) {
updateNSUIView(view, context: context)
}

@MainActor
static func dismantleUIView(_ uiView: Self.NSUIViewType, coordinator: Self.Coordinator) {
Self.dismantleNSUIView(uiView, coordinator: coordinator)
}

@available(iOS 16.0, tvOS 16.0, *)
@MainActor func sizeThatFits(_ proposal: ProposedViewSize, uiView: Self.NSUIViewType, context: Self.Context) -> CGSize? {
sizeThatFits(proposal, nsuiView: uiView, context: context)
}
}

#endif

extension NSUIViewRepresentable {
@MainActor
public static func dismantleNSUIView(_ view: Self.NSUIViewType, coordinator: Self.Coordinator) {
}

@available(macOS 13.0, iOS 16.0, tvOS 16.0, *)
@MainActor
public func sizeThatFits(_ proposal: ProposedViewSize, nsuiView: Self.NSUIViewType, context: Self.Context) -> CGSize? {
nil
}
}
6 changes: 6 additions & 0 deletions Tests/NSUITests/ViewRepresentableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ struct RepresentedView: NSUIViewRepresentable {

func updateNSUIView(_ uiView: NSUIView, context: Context) {
}

final class Coordinator {}

func makeCoordinator() -> Coordinator {
Coordinator()
}
}

final class ViewRepresentableTests: XCTestCase {
Expand Down

0 comments on commit 16d736b

Please sign in to comment.