Skip to content

Commit 0d34485

Browse files
committed
Remove BaseWidget for AppKit backend.
Signed-off-by: furby™ <devs@wabi.foundation>
1 parent 457c421 commit 0d34485

File tree

4 files changed

+16
-209
lines changed

4 files changed

+16
-209
lines changed

Examples/Package.resolved

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
"version" : "1.6.45"
2828
}
2929
},
30+
{
31+
"identity" : "libwebp",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/the-swift-collective/libwebp",
34+
"state" : {
35+
"revision" : "5f745a17b9a5c2a4283f17c2cde4517610ab5f99",
36+
"version" : "1.4.1"
37+
}
38+
},
3039
{
3140
"identity" : "pathkit",
3241
"kind" : "remoteSourceControl",
@@ -130,8 +139,8 @@
130139
"kind" : "remoteSourceControl",
131140
"location" : "https://github.com/stackotter/swift-image-formats",
132141
"state" : {
133-
"revision" : "05a0169a2a5e9365a058e9aa13da5937be6e2586",
134-
"version" : "0.3.1"
142+
"revision" : "697bd8aa62bef7d74a1383454e3534a527769e41",
143+
"version" : "0.3.2"
135144
}
136145
},
137146
{
@@ -143,15 +152,6 @@
143152
"version" : "0.4.0"
144153
}
145154
},
146-
{
147-
"identity" : "swift-libwebp",
148-
"kind" : "remoteSourceControl",
149-
"location" : "https://github.com/stackotter/swift-libwebp",
150-
"state" : {
151-
"revision" : "61dc3787c764022ad2f5ab4f9994a569afe86f9f",
152-
"version" : "0.2.0"
153-
}
154-
},
155155
{
156156
"identity" : "swift-log",
157157
"kind" : "remoteSourceControl",

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ switch ProcessInfo.processInfo.environment["SCUI_LIBRARY_TYPE"] {
6161

6262
let package = Package(
6363
name: "swift-cross-ui",
64-
platforms: [.macOS(.v11), .iOS(.v13), .tvOS(.v13), .macCatalyst(.v13)],
64+
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .macCatalyst(.v13)],
6565
products: [
6666
.library(name: "SwiftCrossUI", type: libraryType, targets: ["SwiftCrossUI"]),
6767
.library(name: "AppKitBackend", type: libraryType, targets: ["AppKitBackend"]),

Sources/AppKitBackend/BaseWidget.swift

Lines changed: 0 additions & 113 deletions
This file was deleted.

Sources/AppKitBackend/NSViewRepresentable.swift

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ public struct NSViewRepresentableContext<Coordinator> {
66
public internal(set) var environment: EnvironmentValues
77
}
88

9-
public protocol NSViewRepresentable: View
10-
where Content == Never {
9+
public protocol NSViewRepresentable: View where Content == Never {
1110
associatedtype NSViewType: NSView
1211
associatedtype Coordinator = Void
1312

@@ -46,6 +45,7 @@ where Content == Never {
4645
///
4746
/// The default implementation uses `nsView.intrinsicContentSize` and `nsView.sizeThatFits(_:)`
4847
/// to determine the return value.
48+
@MainActor
4949
func determineViewSize(
5050
for proposal: SIMD2<Int>, nsView: NSViewType,
5151
context: NSViewRepresentableContext<Coordinator>
@@ -101,8 +101,7 @@ extension NSViewRepresentable {
101101
}
102102
}
103103

104-
extension View
105-
where Self: NSViewRepresentable {
104+
extension View where Self: NSViewRepresentable {
106105
public var body: Never {
107106
preconditionFailure("This should never be called")
108107
}
@@ -121,89 +120,10 @@ where Self: NSViewRepresentable {
121120
) -> [LayoutSystem.LayoutableChild] {
122121
[]
123122
}
124-
125-
public func asWidget<Backend: AppBackend>(
126-
_: any ViewGraphNodeChildren,
127-
backend _: Backend
128-
) -> Backend.Widget {
129-
if let widget = RepresentingWidget(representable: self) as? Backend.Widget {
130-
return widget
131-
} else {
132-
fatalError("NSViewRepresentable requested by \(Backend.self)")
133-
}
134-
}
135-
136-
public func update<Backend: AppBackend>(
137-
_ widget: Backend.Widget,
138-
children _: any ViewGraphNodeChildren,
139-
proposedSize: SIMD2<Int>,
140-
environment: EnvironmentValues,
141-
backend _: Backend,
142-
dryRun: Bool
143-
) -> ViewUpdateResult {
144-
let representingWidget = widget as! RepresentingWidget<Self>
145-
representingWidget.update(with: environment)
146-
147-
let size =
148-
representingWidget.representable.determineViewSize(
149-
for: proposedSize,
150-
nsView: representingWidget.subview,
151-
context: representingWidget.context!
152-
)
153-
154-
if !dryRun {
155-
representingWidget.width = size.size.x
156-
representingWidget.height = size.size.y
157-
}
158-
159-
return ViewUpdateResult.leafView(size: size)
160-
}
161123
}
162124

163-
extension NSViewRepresentable
164-
where Coordinator == Void {
125+
extension NSViewRepresentable where Coordinator == Void {
165126
public func makeCoordinator() {
166127
return ()
167128
}
168129
}
169-
170-
final class RepresentingWidget<Representable: NSViewRepresentable>: BaseWidget {
171-
var representable: Representable
172-
var context: NSViewRepresentableContext<Representable.Coordinator>?
173-
174-
lazy var subview: Representable.NSViewType = {
175-
let view = representable.makeNSView(context: context!)
176-
177-
self.addSubview(view)
178-
179-
view.translatesAutoresizingMaskIntoConstraints = false
180-
NSLayoutConstraint.activate([
181-
view.topAnchor.constraint(equalTo: self.topAnchor),
182-
view.leadingAnchor.constraint(equalTo: self.leadingAnchor),
183-
view.trailingAnchor.constraint(equalTo: self.trailingAnchor),
184-
view.bottomAnchor.constraint(equalTo: self.bottomAnchor),
185-
])
186-
187-
return view
188-
}()
189-
190-
func update(with environment: EnvironmentValues) {
191-
if context == nil {
192-
context = .init(coordinator: representable.makeCoordinator(), environment: environment)
193-
} else {
194-
context!.environment = environment
195-
representable.updateNSView(subview, context: context!)
196-
}
197-
}
198-
199-
init(representable: Representable) {
200-
self.representable = representable
201-
super.init()
202-
}
203-
204-
deinit {
205-
if let context {
206-
Representable.dismantleNSView(subview, coordinator: context.coordinator)
207-
}
208-
}
209-
}

0 commit comments

Comments
 (0)