From 6537b7fc577b8f0372ee7e94d7c2c9df7029871e Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 28 Dec 2024 21:03:51 +0100 Subject: [PATCH] Added scroll background config --- README.md | 4 +++- .../Models/AutoResizingSheetConfiguration.swift | 7 ++++++- .../ViewModifiers/AutoResizingSheetViewModifier.swift | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7e49f21..cca9d59 100644 --- a/README.md +++ b/README.md @@ -120,13 +120,15 @@ You can also configure `AutoResizingSheet` by passing a `AutoResizingSheetConfig | `scrollable` | `Bool`: Should the content be wrapped inside a scroll view. Defaults to `true`. | | `showGrabber` | `Bool`: If the grabber should be shown. Defaults to `true`. | | `extendableToFullSize` | `Bool`: If the sheet is extendable to full size using the grabber. Defaults to `true`, will be `false` if `showGrabber` is `false`. | +| `scrollBackground` | `UIColor`: If scrollable, defines the background color of the `ScrollView`. Defaults to `.clear`. | Create a configuration like this: ```swift let configuration = AutoResizingSheetConfiguration( scrollable: true, showGrabber: true, - extendableToFullSize: true + extendableToFullSize: true, + scrollBackground: .clear ) ``` diff --git a/Sources/AutoResizingSheet/Models/AutoResizingSheetConfiguration.swift b/Sources/AutoResizingSheet/Models/AutoResizingSheetConfiguration.swift index caaa79c..9fb0155 100644 --- a/Sources/AutoResizingSheet/Models/AutoResizingSheetConfiguration.swift +++ b/Sources/AutoResizingSheet/Models/AutoResizingSheetConfiguration.swift @@ -5,6 +5,7 @@ public struct AutoResizingSheetConfiguration { public var scrollable: Bool public var showGrabber: Bool public var extendableToFullSize: Bool + public var scrollBackground: UIColor /// Creates a new instance of `AutoResizingSheetConfiguration`. /// @@ -17,14 +18,18 @@ public struct AutoResizingSheetConfiguration { /// Defaults to `true`. /// - extendableToFullSize: If the sheet is extendable to full size using the grabber. /// Defaults to `true`, will be `false` if `showGrabber` is `false`. + /// - scrollBackground: If scrollable, defines the background color of the `ScrollView`. + /// Defaults to `.clear`. /// public init( scrollable: Bool = true, showGrabber: Bool = true, - extendableToFullSize: Bool = true + extendableToFullSize: Bool = true, + scrollBackground: UIColor = .clear ) { self.scrollable = scrollable self.showGrabber = showGrabber + self.scrollBackground = scrollBackground if !showGrabber { self.extendableToFullSize = false } else { diff --git a/Sources/AutoResizingSheet/ViewModifiers/AutoResizingSheetViewModifier.swift b/Sources/AutoResizingSheet/ViewModifiers/AutoResizingSheetViewModifier.swift index 6663a0a..a4c93f9 100644 --- a/Sources/AutoResizingSheet/ViewModifiers/AutoResizingSheetViewModifier.swift +++ b/Sources/AutoResizingSheet/ViewModifiers/AutoResizingSheetViewModifier.swift @@ -36,6 +36,7 @@ struct AutoResizingSheetViewModifier: ViewModifier { updateDetents(newHeigh: newSize.height) } } + .background(Color(configuration.scrollBackground)) } else { sheetContent() .presentationDetents(detents, selection: $selectedDetent)