Skip to content

Commit

Permalink
BottomSheet v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaszischka committed Aug 12, 2022
1 parent dd0100d commit 6f928f6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
BottomSheet Changelog
==================

#### v3.0.2
- Added `.customThreshold(Double)` modifier #8, #88

#### v3.0.1
- Fix CocoaPods build #85
- Fix close button not shown in dark mode #86
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ The ViewModifiers are used to customise the look and feel of the BottomSheet.

`.customBackground(...)`: Changes the background of the BottomSheet.
- This works exactly like the native SwiftUI `.background(...)` modifier.
- Using offset or shadow may break the hiding transition.

`.onDragChanged((DragGesture.Value) -> Void)`: Adds an action to perform when the gesture’s value changes.

Expand Down Expand Up @@ -211,6 +212,11 @@ The ViewModifiers are used to customise the look and feel of the BottomSheet.

`.enableTapToDismiss(Bool)`: Makes it possible to dismiss the BottomSheet by tapping somewhere else.

`.customThreshold(Double)`: Sets a custom threshold which determines, when to trigger swipe to dismiss or flick through.
- The threshold must be positive and higher than 10% (0.1).
- Changing the threshold does not affect whether either option is enabled.
- The default threshold is 30% (0.3).


## BottomSheetPosition

Expand Down Expand Up @@ -492,9 +498,11 @@ struct ArtistSongsView: View {
.customBackground(
Color.black
.cornerRadius(30)
.shadow(color: .white, radius: 10, x: 0, y: 0)
)
.foregroundColor(.white)
.shadow(color: .white, radius: 10, x: 0, y: 0)
// Adding the shadow here does not break the hiding transition, but the shadow may gets added to your other views too
// .shadow(color: .white, radius: 10, x: 0, y: 0)
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// BottomSheet+Threshold.swift
//
// Created by Lucas Zischka.
// Copyright © 2022 Lucas Zischka. All rights reserved.
//

import Foundation

public extension BottomSheet {

/// Sets a custom threshold which determines, when to trigger swipe to dismiss or flick through.
///
/// The threshold must be positive and higher than 10% (0.1).
/// Changing the threshold does not affect whether either option is enabled.
/// The default threshold is 30% (0.3)
///
/// - Parameters:
/// - threshold: The threshold as percentage of the screen height.
///
/// - Returns: A BottomSheet with a custom threshold.
func customThreshold(_ threshold: Double) -> BottomSheet {
self.configuration.threshold = threshold
return self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ internal extension BottomSheetView {

// The height of the safe area when position is bottom
var bottomPositionSafeAreaHeight: CGFloat {
// Only limit height when dynamic
// Only add safe area when `dynamicBottom` and not on iPad or Mac
if self.bottomSheetPosition == .dynamicBottom && !self.isIPadOrMac {
#if !os(macOS)
// When dynamic return safe area as height (iPhone)
// Safe area as height (iPhone)
return UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 20
#else
// Should never be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ internal extension BottomSheetView {
height: self.bottomSheetPosition.isDynamic && self.translation == 0 ? nil : self.height(with: geometry),
alignment: self.isIPadOrMac ? .bottom : .top
)
// Clip BottomSheet for transition to work correctly for iPad and Mac
.clipped()
// BottomSheet background
.background(
self.bottomSheetBackground(with: geometry)
)
// Clip BottomSheet for transition to work correctly for iPad and Mac
.clipped()
// On iPad and Mac the BottomSheet has a padding
.padding(
self.isIPadOrMac ? 10 : 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ internal extension BottomSheetView {
)],
currentHeight: CGFloat
) {
if height <= -0.1 && height > -0.3 {
if height <= -0.1 && height > -self.configuration.threshold {
// Go up one position
self.onePositionSwitchUp(
switchablePositions: switchablePositions,
currentHeight: currentHeight
)
} else if height <= -0.3 {
} else if height <= -self.configuration.threshold {
// Go up to highest position
self.switchToHighestPosition(
switchablePositions: switchablePositions,
currentHeight: currentHeight
)
} else if height >= 0.1 && height < 0.3 {
} else if height >= 0.1 && height < self.configuration.threshold {
// Go down one position
self.onePositionSwitchDown(
switchablePositions: switchablePositions,
currentHeight: currentHeight
)
} else if height >= 0.3 && self.configuration.isSwipeToDismissEnabled {
} else if height >= self.configuration.threshold && self.configuration.isSwipeToDismissEnabled {
self.closeSheet()
} else if height >= 0.3 {
} else if height >= self.configuration.threshold {
// Go down to lowest position
self.switchToLowestPosition(
switchablePositions: switchablePositions,
Expand Down Expand Up @@ -191,7 +191,7 @@ internal extension BottomSheetView {
switchablePositions: switchablePositions,
currentHeight: currentHeight
)
} else if height >= 0.3 && self.configuration.isSwipeToDismissEnabled {
} else if height >= self.configuration.threshold && self.configuration.isSwipeToDismissEnabled {
self.closeSheet()
} else if height >= 0.1 {
// Go down one position
Expand Down
1 change: 1 addition & 0 deletions Sources/BottomSheet/Models/BottomSheetConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ internal class BottomSheetConfiguration: Equatable {
var onDismiss: () -> Void = {}
var onDragEnded: (DragGesture.Value) -> Void = { _ in }
var onDragChanged: (DragGesture.Value) -> Void = { _ in }
var threshold: Double = 0.3
}

0 comments on commit 6f928f6

Please sign in to comment.