Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPad sheet alignment and side padding options #158

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ 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 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.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// BottomSheet+SheetSidePadding.swift
//
// Created by Lucas Zischka.
// Copyright © 2022 Lucas Zischka. All rights reserved.
//

import Foundation

public extension BottomSheet {

/// Gives horizontal padding to the sheet
///
/// - Parameters:
/// - padding: The padding to use for the bottom sheet.
///
/// - Returns: A BottomSheet with the configured padding.
func sheetSidePadding(_ padding: CGFloat = 0.0) -> BottomSheet {
self.configuration.sheetSidePadding = padding
return self
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
.top,
self.topPadding
)
// Add side padding
.padding(
.horizontal,
self.configuration.sheetSidePadding
)
// Make the BottomSheet transition via move
.transition(.move(
edge: self.isIPadFloatingOrMac ? .top : .bottom
Expand Down Expand Up @@ -181,7 +186,7 @@
// Main content
self.mainContent
// Make the main content drag-able if content drag is enabled
// highPriorityGesture is required to make dragging the bottom sheet work even when user starts dragging on buttons or other pressable items

Check warning on line 189 in Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 156 characters (line_length)
.highPriorityGesture(
self.configuration.isContentDragEnabled && self.configuration.isResizable ?
self.dragGesture(with: geometry) : nil
Expand Down Expand Up @@ -402,4 +407,4 @@
return 0
}
}
}

Check warning on line 410 in Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

File Length Violation: File should contain 400 lines or less: currently contains 410 (file_length)
2 changes: 1 addition & 1 deletion Sources/BottomSheet/BottomSheetView/BottomSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal struct BottomSheetView<HContent: View, MContent: View>: 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 {
Expand Down
6 changes: 5 additions & 1 deletion Sources/BottomSheet/Models/BottomSheetConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ 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 &&
lhs.sheetSidePadding == rhs.sheetSidePadding
}

var animation: Animation? = .spring(
Expand Down Expand Up @@ -61,4 +63,6 @@ internal class BottomSheetConfiguration: Equatable {
var iPadFloatingSheet: Bool = true
var sheetWidth: BottomSheetWidth = .platformDefault
var accountForKeyboardHeight: Bool = false
var iPadSheetAlignment: Alignment = .bottomLeading
var sheetSidePadding: CGFloat = 0.0
}
Loading