Skip to content

Commit 0f53ec8

Browse files
committed
Adding sheet content in createSheet() instead of update (UIKit, AppKit)
1 parent bb8b228 commit 0f53ec8

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,32 +1687,28 @@ public final class AppKitBackend: AppBackend {
16871687
webView.load(request)
16881688
}
16891689

1690-
public func createSheet() -> NSCustomSheet {
1690+
public func createSheet(content: NSView) -> NSCustomSheet {
16911691
// Initialize with a default contentRect, similar to window creation (lines 58-68)
16921692
let sheet = NSCustomSheet(
16931693
contentRect: NSRect(
16941694
x: 0,
16951695
y: 0,
16961696
width: 400, // Default width
1697-
height: 300 // Default height
1697+
height: 400 // Default height
16981698
),
16991699
styleMask: [.titled, .closable],
17001700
backing: .buffered,
17011701
defer: true
17021702
)
1703+
sheet.contentView = content
1704+
17031705
return sheet
17041706
}
17051707

17061708
public func updateSheet(
1707-
_ sheet: NSCustomSheet, content: NSView, onDismiss: @escaping () -> Void
1709+
_ sheet: NSCustomSheet,
1710+
onDismiss: @escaping () -> Void
17081711
) {
1709-
let contentSize = naturalSize(of: content)
1710-
1711-
let width = max(contentSize.x, 10)
1712-
let height = max(contentSize.y, 10)
1713-
sheet.setContentSize(NSSize(width: width, height: height))
1714-
1715-
sheet.contentView = content
17161712
sheet.onDismiss = onDismiss
17171713
}
17181714

Sources/SwiftCrossUI/Backend/AppBackend.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,11 @@ public protocol AppBackend: Sendable {
607607
/// Creates a sheet object (without showing it yet). Sheets contain view content.
608608
/// They optionally execute provided code on dismiss and
609609
/// prevent users from interacting with the parent window until dimissed.
610-
func createSheet() -> Sheet
610+
func createSheet(content: Widget) -> Sheet
611611

612612
/// Updates the content and appearance of a sheet.
613613
func updateSheet(
614614
_ sheet: Sheet,
615-
content: Widget,
616615
onDismiss: @escaping () -> Void
617616
)
618617

@@ -1260,13 +1259,12 @@ extension AppBackend {
12601259
todo()
12611260
}
12621261

1263-
public func createSheet() -> Sheet {
1262+
public func createSheet(content: Widget) -> Sheet {
12641263
todo()
12651264
}
12661265

12671266
public func updateSheet(
12681267
_ sheet: Sheet,
1269-
content: Widget,
12701268
onDismiss: @escaping () -> Void
12711269
) {
12721270
todo()

Sources/SwiftCrossUI/Views/Modifiers/SheetModifier.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ struct SheetModifier<Content: View, SheetContent: View>: TypeSafeView {
7171
)
7272

7373
if isPresented.wrappedValue && children.sheet == nil {
74-
let sheet = backend.createSheet()
74+
let sheet = backend.createSheet(
75+
content: children.sheetContentNode.widget.into()
76+
)
7577

7678
let dismissAction = DismissAction(action: { [isPresented] in
7779
isPresented.wrappedValue = false
@@ -96,7 +98,6 @@ struct SheetModifier<Content: View, SheetContent: View>: TypeSafeView {
9698

9799
backend.updateSheet(
98100
sheet,
99-
content: children.sheetContentNode.widget.into(),
100101
onDismiss: handleDismiss
101102
)
102103

Sources/UIKitBackend/UIKitBackend+Sheet.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import UIKit
44
extension UIKitBackend {
55
public typealias Sheet = CustomSheet
66

7-
public func createSheet() -> CustomSheet {
7+
public func createSheet(content: Widget) -> CustomSheet {
88
let sheet = CustomSheet()
99
sheet.modalPresentationStyle = .formSheet
10-
10+
sheet.view = content.view
1111
return sheet
1212
}
1313

14-
public func updateSheet(_ sheet: CustomSheet, content: Widget, onDismiss: @escaping () -> Void)
15-
{
16-
sheet.view = content.view
14+
public func updateSheet(_ sheet: CustomSheet, onDismiss: @escaping () -> Void) {
1715
sheet.onDismiss = onDismiss
1816
}
1917

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class WinUIBackend: AppBackend {
3434
public typealias Menu = Void
3535
public typealias Alert = WinUI.ContentDialog
3636
public typealias Path = GeometryGroupHolder
37-
public typealias Sheet = CustomWindow //only for be protocol conform. doesn't currently support it
37+
public typealias Sheet = CustomWindow // Only for protocol conformance. WinUI doesn't currently support it.
3838

3939
public let defaultTableRowContentHeight = 20
4040
public let defaultTableCellVerticalPadding = 4

0 commit comments

Comments
 (0)