Skip to content

Commit 5cc10b6

Browse files
committed
Split View.update into View.computeLayout and View.commit
1 parent 28c5082 commit 5cc10b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1875
-1419
lines changed

Examples/Sources/WindowingExample/WindowingApp.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ struct WindowingApp: App {
8484
}
8585

8686
Image(Bundle.module.bundleURL.appendingPathComponent("Banner.png"))
87+
.resizable()
88+
.aspectRatio(contentMode: .fit)
8789

8890
Divider()
8991

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ public final class AppKitBackend: AppBackend {
3030
// We assume that all scrollers have their controlSize set to `.regular` by default.
3131
// The internet seems to indicate that this is true regardless of any system wide
3232
// preferences etc.
33-
Int(
33+
let result = Int(
3434
NSScroller.scrollerWidth(
3535
for: .regular,
3636
scrollerStyle: NSScroller.preferredScrollerStyle
3737
).rounded(.awayFromZero)
3838
)
39+
print(result)
40+
return result
3941
}
4042

4143
private let appDelegate = NSCustomApplicationDelegate()

Sources/AppKitBackend/NSViewRepresentable.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,14 @@ extension View where Self: NSViewRepresentable {
139139
}
140140
}
141141

142-
public func update<Backend: AppBackend>(
142+
public func computeLayout<Backend: AppBackend>(
143143
_ widget: Backend.Widget,
144144
children: any ViewGraphNodeChildren,
145145
proposedSize: SIMD2<Int>,
146146
environment: EnvironmentValues,
147-
backend: Backend,
148-
dryRun: Bool
149-
) -> ViewUpdateResult {
150-
guard let backend = backend as? AppKitBackend else {
147+
backend: Backend
148+
) -> ViewLayoutResult {
149+
guard backend is AppKitBackend else {
151150
fatalError("NSViewRepresentable updated by \(Backend.self)")
152151
}
153152

@@ -160,11 +159,17 @@ extension View where Self: NSViewRepresentable {
160159
context: representingWidget.context!
161160
)
162161

163-
if !dryRun {
164-
backend.setSize(of: representingWidget, to: size.size)
165-
}
162+
return ViewLayoutResult.leafView(size: size)
163+
}
166164

167-
return ViewUpdateResult.leafView(size: size)
165+
public func commit<Backend: AppBackend>(
166+
_ widget: Backend.Widget,
167+
children: any ViewGraphNodeChildren,
168+
layout: ViewLayoutResult,
169+
environment: EnvironmentValues,
170+
backend: Backend
171+
) {
172+
backend.setSize(of: widget, to: layout.size.size)
168173
}
169174
}
170175

0 commit comments

Comments
 (0)