@@ -16,6 +16,7 @@ class BottomSheetDemoController: DemoController {
1616
1717 let optionTableView = UITableView ( frame: . zero, style: . insetGrouped)
1818 optionTableView. translatesAutoresizingMaskIntoConstraints = false
19+ optionTableView. register ( TableViewCell . self, forCellReuseIdentifier: TableViewCell . identifier)
1920 optionTableView. register ( BooleanCell . self, forCellReuseIdentifier: BooleanCell . identifier)
2021 optionTableView. register ( ActionsCell . self, forCellReuseIdentifier: ActionsCell . identifier)
2122 optionTableView. dataSource = self
@@ -42,6 +43,13 @@ class BottomSheetDemoController: DemoController {
4243 private func rebuildSheet( ) {
4344 // Tear down existing sheet
4445 if let existing = bottomSheetViewController {
46+ let contentViewController = swiftUIHostingController ?? contentNavigationController
47+ if contentViewController. parent === existing {
48+ contentViewController. willMove ( toParent: nil )
49+ contentViewController. view. removeFromSuperview ( )
50+ contentViewController. removeFromParent ( )
51+ }
52+
4553 existing. willMove ( toParent: nil )
4654 existing. view. removeFromSuperview ( )
4755 existing. removeFromParent ( )
@@ -58,17 +66,20 @@ class BottomSheetDemoController: DemoController {
5866 hostingVC. view. translatesAutoresizingMaskIntoConstraints = false
5967 swiftUIHostingController = hostingVC
6068
61- sheetController = BottomSheetController ( expandedContentView: hostingVC. view)
69+ sheetController = BottomSheetController ( expandedContentView: hostingVC. view, style : bottomSheetStyle )
6270 sheetController. isFlexibleHeight = true
6371 sheetController. shouldHideCollapsedContent = false
6472 sheetController. prioritizesSheetPanWhenCollapsed = true
6573 } else {
66- sheetController = BottomSheetController ( headerContentView: headerView, expandedContentView: contentNavigationController. view)
74+ sheetController = BottomSheetController ( headerContentView: headerView,
75+ expandedContentView: contentNavigationController. view,
76+ style: bottomSheetStyle)
6777 sheetController. hostedScrollView = personaListView
6878 sheetController. headerContentHeight = BottomSheetDemoController . headerHeight
6979 }
7080
7181 sheetController. delegate = self
82+ sheetController. usesAdaptiveBackground = useAdaptiveBackground
7283 sheetController. collapsedHeightResolver = { context in
7384 return context. containerTraitCollection. verticalSizeClass == . regular ? 100 : 70
7485 }
@@ -115,6 +126,19 @@ class BottomSheetDemoController: DemoController {
115126 bottomSheetViewController? . shouldAlwaysFillWidth = sender. isOn
116127 }
117128
129+ @objc private func toggleAdaptiveBackground( _ sender: BooleanCell ) {
130+ useAdaptiveBackground = sender. isOn
131+ bottomSheetViewController? . usesAdaptiveBackground = sender. isOn
132+ }
133+
134+ private func selectBottomSheetStyle( _ style: BottomSheetControllerStyle ) {
135+ guard bottomSheetStyle != style else {
136+ return
137+ }
138+
139+ bottomSheetStyle = style
140+ rebuildSheet ( )
141+ }
118142
119143 @objc private func toggleCollapsedContentHiding( _ sender: BooleanCell ) {
120144 bottomSheetViewController? . shouldHideCollapsedContent. toggle ( )
@@ -319,19 +343,42 @@ class BottomSheetDemoController: DemoController {
319343
320344 private var useSwiftUIContent : Bool = false
321345
346+ private var useAdaptiveBackground : Bool = false
347+
348+ private var bottomSheetStyle : BottomSheetControllerStyle = . primary
349+
350+ private func makeStyleButton( ) -> UIButton {
351+ let button = Button ( )
352+ button. showsMenuAsPrimaryAction = true
353+ let styleOptions : [ ( title: String , style: BottomSheetControllerStyle ) ] = [
354+ ( " Primary " , . primary) ,
355+ ( " Glass " , . glass)
356+ ]
357+ button. style = . subtle
358+
359+ button. setTitle ( styleOptions. first ( where: { $0. style == bottomSheetStyle } ) ? . title, for: . normal)
360+ button. menu = UIMenu ( title: " Style " , options: . singleSelection, children: styleOptions. map { option in
361+ UIAction ( title: option. title, state: option. style == bottomSheetStyle ? . on : . off) { [ weak self] _ in
362+ self ? . selectBottomSheetStyle ( option. style)
363+ }
364+ } )
365+ return button
366+ }
367+
322368 private let fpsOverlay : FPSOverlayView = {
323369 let overlay = FPSOverlayView ( )
324370 overlay. isHidden = true
325371 return overlay
326372 } ( )
327373
328-
329374 private var demoOptionItems : [ [ DemoItem ] ] {
330375 [
331376 [
377+ DemoItem ( title: " Style " , type: . menu, action: nil ) ,
332378 DemoItem ( title: " Expandable " , type: . boolean, action: #selector( toggleExpandable) , isOn: bottomSheetViewController? . isExpandable ?? true ) ,
333379 DemoItem ( title: " Hidden " , type: . boolean, action: #selector( toggleHidden) , isOn: bottomSheetViewController? . isHidden ?? false ) ,
334380 DemoItem ( title: " Should always fill width " , type: . boolean, action: #selector( toggleFillWidth) , isOn: bottomSheetViewController? . shouldAlwaysFillWidth ?? false ) ,
381+ DemoItem ( title: " Use adaptive background " , type: . boolean, action: #selector( toggleAdaptiveBackground) , isOn: bottomSheetViewController? . usesAdaptiveBackground ?? false ) ,
335382 DemoItem ( title: " Hide collapsed content " , type: . boolean, action: #selector( toggleCollapsedContentHiding) , isOn: collapsedContentHidingEnabled) ,
336383 DemoItem ( title: " Flexible sheet height " , type: . boolean, action: #selector( toggleFlexibleSheetHeight) , isOn: bottomSheetViewController? . isFlexibleHeight ?? false ) ,
337384 DemoItem ( title: " Use custom handle accessibility label " , type: . boolean, action: #selector( toggleHandleUsingCustomAccessibilityLabel) , isOn: isHandleUsingCustomAccessibilityLabel) ,
@@ -382,6 +429,7 @@ class BottomSheetDemoController: DemoController {
382429 private enum DemoItemType {
383430 case action
384431 case boolean
432+ case menu
385433 case stepper
386434 }
387435
@@ -456,6 +504,13 @@ extension BottomSheetDemoController: UITableViewDataSource {
456504 }
457505 cell. bottomSeparatorType = . full
458506 return cell
507+ } else if item. type == . menu {
508+ guard let cell = tableView. dequeueReusableCell ( withIdentifier: TableViewCell . identifier) as? TableViewCell else {
509+ return UITableViewCell ( )
510+ }
511+
512+ cell. setup ( title: item. title, customAccessoryView: makeStyleButton ( ) )
513+ return cell
459514 }
460515
461516 return UITableViewCell ( )
@@ -518,7 +573,7 @@ extension BottomSheetDemoController: DemoAppearanceDelegate {
518573
519574struct BottomSheetDemoListContentView : View {
520575 var body : some View {
521- List {
576+ FluentList {
522577 Text ( " Cell with Swipe Action " )
523578 . swipeActions {
524579 Button ( action: { } , label: {
@@ -527,7 +582,7 @@ struct BottomSheetDemoListContentView: View {
527582 }
528583 Text ( " Cell without Swipe Action " )
529584 }
530- . listStyle ( . plain )
585+ . fluentListStyle ( . glass )
531586 }
532587}
533588
0 commit comments