Skip to content

Commit bb8b228

Browse files
committed
removed SheetImplementation Protocol, replaced with backend.sizeOf(_:)
changed comment in appbackend
1 parent af6da88 commit bb8b228

File tree

6 files changed

+34
-36
lines changed

6 files changed

+34
-36
lines changed

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,13 @@ public final class AppKitBackend: AppBackend {
17161716
sheet.onDismiss = onDismiss
17171717
}
17181718

1719+
public func sizeOf(_ sheet: NSCustomSheet) -> SIMD2<Int> {
1720+
guard let size = sheet.contentView?.frame.size else {
1721+
return SIMD2(x: 0, y: 0)
1722+
}
1723+
return SIMD2(x: Int(size.width), y: Int(size.height))
1724+
}
1725+
17191726
public func showSheet(_ sheet: NSCustomSheet, window: NSCustomWindow?) {
17201727
guard let window else {
17211728
print("warning: Cannot show sheet without a parent window")
@@ -1772,13 +1779,7 @@ public final class AppKitBackend: AppBackend {
17721779
}
17731780
}
17741781

1775-
public final class NSCustomSheet: NSCustomWindow, NSWindowDelegate, SheetImplementation {
1776-
public var sheetSize: SIMD2<Int> {
1777-
guard let size = self.contentView?.frame.size else {
1778-
return SIMD2(x: 0, y: 0)
1779-
}
1780-
return SIMD2(x: Int(size.width), y: Int(size.height))
1781-
}
1782+
public final class NSCustomSheet: NSCustomWindow, NSWindowDelegate {
17821783
public var onDismiss: (() -> Void)?
17831784

17841785
public var interactiveDismissDisabled: Bool = false

Sources/GtkBackend/GtkBackend.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,10 @@ public final class GtkBackend: AppBackend {
16941694
connectedCloseHandlers.remove(key)
16951695
}
16961696

1697+
public func sizeOf(_ sheet: Gtk.Window) -> SIMD2<Int> {
1698+
return SIMD2(x: sheet.size.width, y: sheet.size.height)
1699+
}
1700+
16971701
public func setPresentationBackground(of sheet: Gtk.Window, to color: SwiftCrossUI.Color) {
16981702
sheet.css.set(properties: [.backgroundColor(color.gtkColor)])
16991703
}
@@ -1732,12 +1736,6 @@ class CustomListBox: ListBox {
17321736
var cachedSelection: Int? = nil
17331737
}
17341738

1735-
extension Gtk.Window: SheetImplementation {
1736-
public var sheetSize: SIMD2<Int> {
1737-
return SIMD2(x: self.size.width, y: self.size.height)
1738-
}
1739-
}
1740-
17411739
final class ValueBox<T> {
17421740
let value: T
17431741
init(value: T) {

Sources/SwiftCrossUI/Backend/AppBackend.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public protocol AppBackend: Sendable {
4747
associatedtype Menu
4848
associatedtype Alert
4949
associatedtype Path
50-
associatedtype Sheet: SheetImplementation
50+
associatedtype Sheet
5151

5252
/// Creates an instance of the backend.
5353
init()
@@ -604,12 +604,12 @@ public protocol AppBackend: Sendable {
604604
/// ``showAlert(_:window:responseHandler:)``.
605605
func dismissAlert(_ alert: Alert, window: Window?)
606606

607-
/// Creates a sheet object (without showing it yet). Sheets contain View Content.
608-
/// They optionally execute provied code on dismiss and
607+
/// Creates a sheet object (without showing it yet). Sheets contain view content.
608+
/// They optionally execute provided code on dismiss and
609609
/// prevent users from interacting with the parent window until dimissed.
610610
func createSheet() -> Sheet
611611

612-
/// Updates the content and appearance of a sheet
612+
/// Updates the content and appearance of a sheet.
613613
func updateSheet(
614614
_ sheet: Sheet,
615615
content: Widget,
@@ -633,6 +633,9 @@ public protocol AppBackend: Sendable {
633633
/// Gets used by the SCUI sheet implementation to close a sheet.
634634
func dismissSheet(_ sheet: Sheet, window: Window?)
635635

636+
/// Get the dimensions of a sheet
637+
func sizeOf(_ sheet: Sheet) -> SIMD2<Int>
638+
636639
/// Sets the corner radius for a sheet presentation.
637640
///
638641
/// This method is called when the sheet content has a `presentationCornerRadius` modifier
@@ -806,10 +809,6 @@ extension AppBackend {
806809
}
807810
}
808811

809-
public protocol SheetImplementation {
810-
var sheetSize: SIMD2<Int> { get }
811-
}
812-
813812
extension AppBackend {
814813
/// Used by placeholder implementations of backend methods.
815814
private func todo(_ function: String = #function) -> Never {
@@ -1273,6 +1272,12 @@ extension AppBackend {
12731272
todo()
12741273
}
12751274

1275+
public func sizeOf(
1276+
sheet: Sheet
1277+
) -> SIMD2<Int> {
1278+
todo()
1279+
}
1280+
12761281
public func showSheet(
12771282
_ sheet: Sheet,
12781283
window: Window?

Sources/SwiftCrossUI/Views/Modifiers/SheetModifier.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct SheetModifier<Content: View, SheetContent: View>: TypeSafeView {
8080

8181
let dryRunResult = children.sheetContentNode.update(
8282
with: sheetContent(),
83-
proposedSize: sheet.sheetSize,
83+
proposedSize: backend.sizeOf(sheet),
8484
environment: sheetEnvironment,
8585
dryRun: true
8686
)
@@ -89,7 +89,7 @@ struct SheetModifier<Content: View, SheetContent: View>: TypeSafeView {
8989

9090
let _ = children.sheetContentNode.update(
9191
with: sheetContent(),
92-
proposedSize: sheet.sheetSize,
92+
proposedSize: backend.sizeOf(sheet),
9393
environment: sheetEnvironment,
9494
dryRun: false
9595
)

Sources/UIKitBackend/UIKitBackend+Sheet.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ extension UIKitBackend {
3737
}
3838
}
3939

40+
public func sizeOf(_ sheet: CustomSheet) -> SIMD2<Int> {
41+
let size = sheet.view.frame.size
42+
return SIMD2(x: Int(size.width), y: Int(size.height))
43+
}
44+
4045
public func setPresentationDetents(of sheet: CustomSheet, to detents: [PresentationDetent]) {
4146
if #available(iOS 15.0, *) {
4247
#if !os(visionOS)
@@ -121,12 +126,7 @@ extension UIKitBackend {
121126
}
122127
}
123128

124-
public final class CustomSheet: UIViewController, SheetImplementation {
125-
public var sheetSize: SIMD2<Int> {
126-
let size = view.frame.size
127-
return SIMD2(x: Int(size.width), y: Int(size.height))
128-
}
129-
129+
public final class CustomSheet: UIViewController {
130130
var onDismiss: (() -> Void)?
131131
private var isDismissedProgrammatically = false
132132

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ class SwiftIInitializeWithWindow: WindowsFoundation.IUnknown {
18701870
}
18711871
}
18721872

1873-
public class CustomWindow: WinUI.Window, SheetImplementation {
1873+
public class CustomWindow: WinUI.Window {
18741874
/// Hardcoded menu bar height from MenuBar_themeresources.xaml in the
18751875
/// microsoft-ui-xaml repository.
18761876
static let menuBarHeight = 0
@@ -1880,12 +1880,6 @@ public class CustomWindow: WinUI.Window, SheetImplementation {
18801880
var grid: WinUI.Grid
18811881
var cachedAppWindow: WinAppSDK.AppWindow!
18821882

1883-
//only for AppBackend conformance, no support yet
1884-
public var sheetSize: SIMD2<Int> {
1885-
let size = self.cachedAppWindow.size
1886-
return SIMD2<Int>(x: Int(size.width), y: Int(size.height))
1887-
}
1888-
18891883
var scaleFactor: Double {
18901884
// I'm leaving this code here for future travellers. Be warned that this always
18911885
// seems to return 100% even if the scale factor is set to 125% in settings.

0 commit comments

Comments
 (0)