From a7688656c7dae86c75a039b7536276cdf3aaec8f Mon Sep 17 00:00:00 2001 From: Mark Storey Date: Sat, 6 Apr 2024 09:30:35 -0400 Subject: [PATCH 1/5] Allow for different sheet placements for "iPad not floating". --- Sources/BottomSheet/BottomSheetView/BottomSheetView.swift | 2 +- Sources/BottomSheet/Models/BottomSheetConfiguration.swift | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift b/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift index 036356c34..d589e4460 100644 --- a/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift +++ b/Sources/BottomSheet/BottomSheetView/BottomSheetView.swift @@ -51,7 +51,7 @@ internal struct BottomSheetView: View { // On iPad floating and Mac the BottomSheet is aligned to the top left // On iPhone and iPad not floating it is aligned to the bottom center, // in horizontal mode to the bottom left - alignment: self.isIPadFloatingOrMac ? .topLeading : .bottomLeading + alignment: self.isIPadFloatingOrMac ? .topLeading : self.configuration.iPadSheetAlignment ) { // Hide everything when the BottomSheet is hidden if !self.bottomSheetPosition.isHidden { diff --git a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift index 33a430930..0316a0ba1 100644 --- a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift +++ b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift @@ -28,7 +28,8 @@ internal class BottomSheetConfiguration: Equatable { lhs.isTapToDismissEnabled == rhs.isTapToDismissEnabled && lhs.iPadFloatingSheet == rhs.iPadFloatingSheet && lhs.sheetWidth == rhs.sheetWidth && - lhs.accountForKeyboardHeight == rhs.accountForKeyboardHeight + lhs.accountForKeyboardHeight == rhs.accountForKeyboardHeight && + lhs.iPadSheetAlignment == rhs.iPadSheetAlignment } var animation: Animation? = .spring( @@ -61,4 +62,5 @@ internal class BottomSheetConfiguration: Equatable { var iPadFloatingSheet: Bool = true var sheetWidth: BottomSheetWidth = .platformDefault var accountForKeyboardHeight: Bool = false + var iPadSheetAlignment: Alignment = .bottomLeading } From bc34c43656d324e1d08397ca71e8e196afcc95de Mon Sep 17 00:00:00 2001 From: Mark Storey Date: Sat, 6 Apr 2024 09:39:33 -0400 Subject: [PATCH 2/5] Added view modifer for sheet alignment --- README.md | 2 ++ .../BottomSheet+iPadSheetAlignment.swift | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+iPadSheetAlignment.swift diff --git a/README.md b/README.md index cfd378996..66f88f34c 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,8 @@ The ViewModifiers are used to customise the look and feel of the BottomSheet. `.enableFloatingIPadSheet(Bool)`: Makes it possible to make the sheet appear like on iPhone. +`.iPadSheetAlignment(Alignment)`: Allows for different alignments of the sheet when enableFloatingIPadSheet is disabled. + `.onDismiss(() -> Void)`: A action that will be performed when the BottomSheet is dismissed. - Please note that when you dismiss the BottomSheet yourself, by setting the bottomSheetPosition to .hidden, the action will not be called. diff --git a/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+iPadSheetAlignment.swift b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+iPadSheetAlignment.swift new file mode 100644 index 000000000..cbbbb8ee6 --- /dev/null +++ b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+iPadSheetAlignment.swift @@ -0,0 +1,23 @@ +// +// BottomSheet+iPadSheetAlignment.swift +// +// Created by Lucas Zischka. +// Copyright © 2022 Lucas Zischka. All rights reserved. +// + +import Foundation +import SwiftUI + +public extension BottomSheet { + + /// Makes it possible to align the sheet at different places on iPad if floating sheet is disabled + /// + /// - Parameters: + /// - alignment: An alignment for the bottom sheet + /// + /// - Returns: A BottomSheet that will align to what's specified + func iPadSheetAlignment(_ alignment: Alignment = .bottomLeading) -> BottomSheet { + self.configuration.iPadSheetAlignment = alignment + return self + } +} From 6da21a3f9bb057cc142ef630b3ef2b767350dd8e Mon Sep 17 00:00:00 2001 From: Mark Storey Date: Sat, 6 Apr 2024 10:03:02 -0400 Subject: [PATCH 3/5] Added sheet padding modifier to give padding to non floating iPad sheets. --- README.md | 4 +++- .../BottomSheet+SheetPadding.swift | 22 +++++++++++++++++++ .../BottomSheetView+HelperViews.swift | 2 +- .../Models/BottomSheetConfiguration.swift | 4 +++- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift diff --git a/README.md b/README.md index 66f88f34c..9293d196e 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,9 @@ The ViewModifiers are used to customise the look and feel of the BottomSheet. `.enableFloatingIPadSheet(Bool)`: Makes it possible to make the sheet appear like on iPhone. -`.iPadSheetAlignment(Alignment)`: Allows for different alignments of the sheet when enableFloatingIPadSheet is disabled. +`.iPadSheetAlignment(Alignment)`: Allows for different alignments of the sheet on iPad when enableFloatingIPadSheet is disabled. + +`.sheetPadding(CGFloat)`: Gives the bottom sheet padding on iPad when enableFloatingIPadSheet is disabled. `.onDismiss(() -> Void)`: A action that will be performed when the BottomSheet is dismissed. - Please note that when you dismiss the BottomSheet yourself, by setting the bottomSheetPosition to .hidden, the action will not be called. diff --git a/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift new file mode 100644 index 000000000..b8850f59f --- /dev/null +++ b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift @@ -0,0 +1,22 @@ +// +// BottomSheet+SheetPadding.swift +// +// Created by Lucas Zischka. +// Copyright © 2022 Lucas Zischka. All rights reserved. +// + +import Foundation + +public extension BottomSheet { + + /// Gives padding to the sheet + /// + /// - Parameters: + /// - padding: The padding to use for the bottom sheet. + /// + /// - Returns: A BottomSheet with the configured padding. + func sheetPadding(_ padding: CGFloat = 0.0) -> BottomSheet { + self.configuration.sheetPadding = padding + return self + } +} diff --git a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift index 8ccb6b062..25bb38418 100644 --- a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift +++ b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift @@ -67,7 +67,7 @@ internal extension BottomSheetView { ) // On iPad floating and Mac the BottomSheet has a padding .padding( - self.isIPadFloatingOrMac ? 10 : 0 + self.isIPadFloatingOrMac ? 10 : self.configuration.sheetPadding ) // Add safe area top padding on iPad and Mac .padding( diff --git a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift index 0316a0ba1..44ad36557 100644 --- a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift +++ b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift @@ -29,7 +29,8 @@ internal class BottomSheetConfiguration: Equatable { lhs.iPadFloatingSheet == rhs.iPadFloatingSheet && lhs.sheetWidth == rhs.sheetWidth && lhs.accountForKeyboardHeight == rhs.accountForKeyboardHeight && - lhs.iPadSheetAlignment == rhs.iPadSheetAlignment + lhs.iPadSheetAlignment == rhs.iPadSheetAlignment && + lhs.sheetPadding == rhs.sheetPadding } var animation: Animation? = .spring( @@ -63,4 +64,5 @@ internal class BottomSheetConfiguration: Equatable { var sheetWidth: BottomSheetWidth = .platformDefault var accountForKeyboardHeight: Bool = false var iPadSheetAlignment: Alignment = .bottomLeading + var sheetPadding: CGFloat = 0.0 } From e2cfceec0bafb0b11153f579c910692788b1c4a0 Mon Sep 17 00:00:00 2001 From: Mark Storey Date: Sat, 6 Apr 2024 10:18:11 -0400 Subject: [PATCH 4/5] Change padding option to be only side padding --- README.md | 2 +- ...adding.swift => BottomSheet+SheetSidePadding.swift} | 10 +++++----- .../BottomSheetView/BottomSheetView+HelperViews.swift | 7 ++++++- .../BottomSheet/Models/BottomSheetConfiguration.swift | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) rename Sources/BottomSheet/BottomSheet+ViewModifiers/{BottomSheet+SheetPadding.swift => BottomSheet+SheetSidePadding.swift} (61%) diff --git a/README.md b/README.md index 9293d196e..afcbc4637 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ The ViewModifiers are used to customise the look and feel of the BottomSheet. `.iPadSheetAlignment(Alignment)`: Allows for different alignments of the sheet on iPad when enableFloatingIPadSheet is disabled. -`.sheetPadding(CGFloat)`: Gives the bottom sheet padding on iPad when enableFloatingIPadSheet is disabled. +`.sheetSidePadding(CGFloat)`: Gives the bottom sheet horizontal padding on iPad when enableFloatingIPadSheet is disabled. `.onDismiss(() -> Void)`: A action that will be performed when the BottomSheet is dismissed. - Please note that when you dismiss the BottomSheet yourself, by setting the bottomSheetPosition to .hidden, the action will not be called. diff --git a/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetSidePadding.swift similarity index 61% rename from Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift rename to Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetSidePadding.swift index b8850f59f..832cdf1cc 100644 --- a/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetPadding.swift +++ b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+SheetSidePadding.swift @@ -1,6 +1,6 @@ // -// BottomSheet+SheetPadding.swift -// +// BottomSheet+SheetSidePadding.swift +// // Created by Lucas Zischka. // Copyright © 2022 Lucas Zischka. All rights reserved. // @@ -9,14 +9,14 @@ import Foundation public extension BottomSheet { - /// Gives padding to the sheet + /// Gives horizontal padding to the sheet /// /// - Parameters: /// - padding: The padding to use for the bottom sheet. /// /// - Returns: A BottomSheet with the configured padding. - func sheetPadding(_ padding: CGFloat = 0.0) -> BottomSheet { - self.configuration.sheetPadding = padding + func sheetSidePadding(_ padding: CGFloat = 0.0) -> BottomSheet { + self.configuration.sheetSidePadding = padding return self } } diff --git a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift index 25bb38418..1cbb4f600 100644 --- a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift +++ b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift @@ -67,13 +67,18 @@ internal extension BottomSheetView { ) // On iPad floating and Mac the BottomSheet has a padding .padding( - self.isIPadFloatingOrMac ? 10 : self.configuration.sheetPadding + self.isIPadFloatingOrMac ? 10 : 0 ) // Add safe area top padding on iPad and Mac .padding( .top, self.topPadding ) + // Add safe area top padding on iPad and Mac + .padding( + .horizontal, + self.configuration.sheetSidePadding + ) // Make the BottomSheet transition via move .transition(.move( edge: self.isIPadFloatingOrMac ? .top : .bottom diff --git a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift index 44ad36557..085029460 100644 --- a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift +++ b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift @@ -30,7 +30,7 @@ internal class BottomSheetConfiguration: Equatable { lhs.sheetWidth == rhs.sheetWidth && lhs.accountForKeyboardHeight == rhs.accountForKeyboardHeight && lhs.iPadSheetAlignment == rhs.iPadSheetAlignment && - lhs.sheetPadding == rhs.sheetPadding + lhs.sheetSidePadding == rhs.sheetSidePadding } var animation: Animation? = .spring( @@ -64,5 +64,5 @@ internal class BottomSheetConfiguration: Equatable { var sheetWidth: BottomSheetWidth = .platformDefault var accountForKeyboardHeight: Bool = false var iPadSheetAlignment: Alignment = .bottomLeading - var sheetPadding: CGFloat = 0.0 + var sheetSidePadding: CGFloat = 0.0 } From 3891705b975ac3fefe99689274ad4a2323ee4754 Mon Sep 17 00:00:00 2001 From: Mark Storey Date: Sat, 6 Apr 2024 10:57:14 -0400 Subject: [PATCH 5/5] typo --- .../BottomSheetView/BottomSheetView+HelperViews.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift index 1cbb4f600..85f0e8b01 100644 --- a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift +++ b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift @@ -74,7 +74,7 @@ internal extension BottomSheetView { .top, self.topPadding ) - // Add safe area top padding on iPad and Mac + // Add side padding .padding( .horizontal, self.configuration.sheetSidePadding