@@ -36,6 +36,8 @@ extension UIKitBackend {
3636
3737 public func updateSheet(
3838 _ sheet: CustomSheet ,
39+ window: Window ,
40+ environment: EnvironmentValues ,
3941 size: SIMD2 < Int > ,
4042 onDismiss: @escaping ( ) -> Void ,
4143 cornerRadius: Double ? ,
@@ -44,17 +46,45 @@ extension UIKitBackend {
4446 backgroundColor: Color ? ,
4547 interactiveDismissDisabled: Bool
4648 ) {
47- // Center the sheet's content
48- let leadingPadding = ( sheet. preferredContentSize. width - CGFloat( size. x) ) / 2
49- sheet. leadingConstraint!. constant = leadingPadding
49+ // Center the sheet's content horizontally
50+ #if os(tvOS)
51+ let leadingPadding = ( window. frame. size. width - CGFloat( size. x) ) / 2
52+ sheet. leadingConstraint!. constant = - leadingPadding
53+ #else
54+ let leadingPadding = ( sheet. preferredContentSize. width - CGFloat( size. x) ) / 2
55+ sheet. leadingConstraint!. constant = leadingPadding
56+ #endif
5057
5158 sheet. onDismiss = onDismiss
5259 setPresentationDetents ( of: sheet, to: detents)
5360 setPresentationCornerRadius ( of: sheet, to: cornerRadius)
5461 setPresentationDragIndicatorVisibility ( of: sheet, to: dragIndicatorVisibility, detents: detents)
5562
56- // TODO: Get the default background color from the environment (via colorScheme?)
57- sheet. view. backgroundColor = backgroundColor? . uiColor ?? UIColor . systemBackground
63+ let defaultColor : UIColor ?
64+ #if targetEnvironment(macCatalyst)
65+ defaultColor = nil
66+ #else
67+ // These values were obtained by measuring the colors on my Mac, so they
68+ // are likely not completely accurate (these are just how they appeared
69+ // in my Mac's color space).
70+ switch environment. colorScheme {
71+ case . light:
72+ defaultColor = UIColor (
73+ red: 1 , green: 1 , blue: 1 , alpha: 1
74+ )
75+ case . dark:
76+ #if os(tvOS)
77+ defaultColor = UIColor (
78+ red: 15 / 255 , green: 15 / 255 , blue: 15 / 255 , alpha: 1
79+ )
80+ #else
81+ defaultColor = UIColor (
82+ red: 28 / 255 , green: 28 / 255 , blue: 30 / 255 , alpha: 1
83+ )
84+ #endif
85+ }
86+ #endif
87+ sheet. view. backgroundColor = backgroundColor? . uiColor ?? defaultColor
5888
5989 // From the UIKit docs for isModalInPresentation:
6090 // When you set it to true, UIKit ignores events outside the view controller’s
0 commit comments