Skip to content

Commit c64e066

Browse files
Liquid Glass interactive sheets
1 parent 7970156 commit c64e066

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

Signal/Registration/UserInterface/RegistrationSplashViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public class RegistrationSplashViewController: OWSViewController, OWSNavigationC
208208

209209
private class RestoreOrTransferPickerController: StackSheetViewController {
210210

211+
override var placeOnGlassIfAvailable: Bool { false }
212+
211213
private let setHasOldDeviceBlock: ((Bool) -> Void)
212214
init(setHasOldDeviceBlock: @escaping (Bool) -> Void) {
213215
self.setHasOldDeviceBlock = setHasOldDeviceBlock

Signal/src/ViewControllers/AppSettings/Linked Devices/LinkOrSyncPickerSheet.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class LinkOrSyncPickerSheet: StackSheetViewController {
1414
UIColor.Signal.groupedBackground
1515
}
1616

17+
private let hMargin: CGFloat = 20
1718
override var stackViewInsets: UIEdgeInsets {
18-
UIEdgeInsets(top: 0, leading: 20, bottom: 24, trailing: 20)
19+
UIEdgeInsets(top: 0, leading: hMargin, bottom: 24, trailing: hMargin)
1920
}
2021

2122
private let didDismiss: () -> Void
@@ -73,8 +74,8 @@ class LinkOrSyncPickerSheet: StackSheetViewController {
7374
}
7475
)
7576

76-
view.addSubview(closeButton)
77-
closeButton.autoPinEdge(toSuperviewMargin: .trailing)
77+
contentView.addSubview(closeButton)
78+
closeButton.autoPinEdge(toSuperviewEdge: .trailing, withInset: hMargin)
7879
closeButton.autoAlignAxis(.horizontal, toSameAxisOf: titleLabel)
7980
closeButton.autoSetDimensions(to: .square(28))
8081

SignalUI/ViewControllers/InteractiveSheetViewController.swift

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ open class InteractiveSheetViewController: OWSViewController {
6363
open var sheetBackgroundColor: UIColor { Theme.actionSheetBackgroundColor }
6464
open var handleBackgroundColor: UIColor { Theme.tableView2PresentedSeparatorColor }
6565

66+
/// Override to `true` to make the content appear on a glass background on
67+
/// iOS 26 and later. `sheetBackgroundColor` will be ignored when on glass,
68+
/// but still be sure to set it for devices running iOS 18 and older.
69+
open var placeOnGlassIfAvailable: Bool { false }
70+
private var isOnGlass: Bool {
71+
if #available(iOS 26, *), FeatureFlags.iOS26SDKIsAvailable {
72+
placeOnGlassIfAvailable
73+
} else {
74+
false
75+
}
76+
}
77+
6678
public weak var externalBackdropView: UIView?
6779
private lazy var _internalBackdropView = UIView()
6880
public var backdropView: UIView? { externalBackdropView ?? _internalBackdropView }
@@ -154,7 +166,8 @@ open class InteractiveSheetViewController: OWSViewController {
154166
view.addSubview(sheetContainerView)
155167
sheetCurrentOffsetConstraint = sheetContainerView.autoPinEdge(toSuperviewEdge: .bottom)
156168
sheetContainerView.autoHCenterInSuperview()
157-
sheetContainerView.backgroundColor = sheetBackgroundColor
169+
170+
let margin: CGFloat = isOnGlass ? 8 : 0
158171

159172
// Prefer to be full width, but don't exceed the maximum width
160173
sheetContainerView.autoSetDimension(.width, toSize: maxWidth, relation: .lessThanOrEqual)
@@ -165,7 +178,12 @@ open class InteractiveSheetViewController: OWSViewController {
165178
}
166179

167180
sheetContainerContentView.addSubview(sheetStackView)
168-
sheetStackView.autoPinEdgesToSuperviewEdges()
181+
sheetStackView.autoPinEdgesToSuperviewEdges(with: .init(
182+
top: 0,
183+
left: margin,
184+
bottom: margin,
185+
right: margin
186+
))
169187

170188
contentView.preservesSuperviewLayoutMargins = true
171189
sheetStackView.addArrangedSubview(contentView)
@@ -187,6 +205,18 @@ open class InteractiveSheetViewController: OWSViewController {
187205

188206
// Setup handle for interactive dismissal / resizing
189207
setupInteractiveSizing()
208+
209+
if #available(iOS 26.0, *), isOnGlass {
210+
#if compiler(>=6.2)
211+
sheetContainerView.backgroundColor = .clear
212+
let glassBackground = UIVisualEffectView(effect: UIGlassEffect(style: .regular))
213+
sheetContainerView.insertSubview(glassBackground, at: 0)
214+
glassBackground.autoPinEdges(toEdgesOf: sheetStackView)
215+
glassBackground.cornerConfiguration = .uniformCorners(radius: .containerConcentric(minimum: 20))
216+
#endif
217+
} else {
218+
sheetContainerView.backgroundColor = sheetBackgroundColor
219+
}
190220
}
191221

192222
open override func viewDidDisappear(_ animated: Bool) {
@@ -198,7 +228,11 @@ open class InteractiveSheetViewController: OWSViewController {
198228
super.themeDidChange()
199229

200230
handle.backgroundColor = handleBackgroundColor
201-
sheetContainerView.backgroundColor = sheetBackgroundColor
231+
sheetContainerView.backgroundColor = if isOnGlass {
232+
.clear
233+
} else {
234+
sheetBackgroundColor
235+
}
202236
}
203237

204238
@objc
@@ -482,7 +516,17 @@ open class InteractiveSheetViewController: OWSViewController {
482516

483517
// Add resistance above the max preferred height
484518
if newHeight > maxHeight {
485-
newHeight = maxHeight + (newHeight - maxHeight) / resistanceDivisor
519+
if isOnGlass {
520+
// Doing a transform keeps the glass background the same
521+
// height and prevents its concentric corners from shirking
522+
// as they get farther from the edges of the screen.
523+
sheetContainerView.transform = .translate(.init(x: 0, y: (maxHeight - newHeight) / resistanceDivisor))
524+
newHeight = maxHeight
525+
} else {
526+
// When not on glass, we want the bottom of the sheet to
527+
// extend to the bottom of the screen, so don't transform.
528+
newHeight = maxHeight + (newHeight - maxHeight) / resistanceDivisor
529+
}
486530
}
487531

488532
// Don't go past the max allowed height
@@ -576,6 +620,7 @@ open class InteractiveSheetViewController: OWSViewController {
576620

577621
sheetPanDelegate?.sheetPanDecelerationDidBegin()
578622
self.animate {
623+
self.sheetContainerView.transform = .identity
579624
self.sheetCurrentOffsetConstraint?.constant = finalOffset
580625
self.sheetCurrentHeightConstraint.constant = finalHeight
581626
self.view.layoutIfNeeded()

SignalUI/ViewControllers/StackSheetViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ open class StackSheetViewController: InteractiveSheetViewController {
1919
UIColor.Signal.groupedBackground
2020
}
2121

22+
open override var placeOnGlassIfAvailable: Bool { true }
23+
2224
private lazy var preferredHeight: CGFloat = self.maximumAllowedHeight()
2325
open override func maximumPreferredHeight() -> CGFloat {
2426
min(self.preferredHeight, self.maximumAllowedHeight())

0 commit comments

Comments
 (0)