Skip to content

Commit

Permalink
Add new options
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaszischka committed Jun 17, 2022
1 parent fd87c1d commit 39f59cd
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
BottomSheet Changelog
==================

#### v2.8.0
- Add `disableBottomSafeAreaInsets` option #63
- Add `disableFlickThrough` option #61

#### v2.7.0
- Fix drag indicator not draggable #45
- Fix content not responding to tap gestures #51
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ struct ContentView: View {

`.cornerRadius(Double)` Changes the corener radius of the BottomSheet.

`.disableBottomSafeAreaInsets` Disables the bottom safeAreaInsets.

`.disableFlickThrough` Disables the flick through feature.

`.dragIndicatorColor(Color)` Changes the color of the drag indicator.

`.noBottomPosition` Prevents the lowest value (above 0) from being the bottom position and hiding the mainContent.
Expand Down
38 changes: 23 additions & 15 deletions Sources/BottomSheet/BottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,39 @@ public struct BottomSheet {
return lhs.rawValue == rhs.rawValue
}

///Allows absolute values in pixels to be used as BottomSheetPosition values.
/// Allows absolute values in pixels to be used as BottomSheetPosition values.
case absolutePositionValue
///Allows the BottomSheet to move when dragging the mainContent. Do not use if the mainContent is packed into a ScrollView.
/// Allows the BottomSheet to move when dragging the mainContent. Do not use if the mainContent is packed into a ScrollView.
case allowContentDrag
///Sets the animation for opening and closing the BottomSheet.
/// Sets the animation for opening and closing the BottomSheet.
case animation(Animation)
///The mainView is packed into a ScrollView, which can only scrolled at the .top position.
/// The mainView is packed into a ScrollView, which can only scrolled at the .top position.
case appleScrollBehavior
///Changes the background of the BottomSheet. Must be erased to AnyView.
/// Changes the background of the BottomSheet. Must be erased to AnyView.
case background(() -> AnyView)
///Enables and sets the blur effect of the background when pulling up the BottomSheet.
/// Enables and sets the blur effect of the background when pulling up the BottomSheet.
case backgroundBlur(effect: UIBlurEffect.Style = .systemThinMaterial)
///Changes the corner radius of the BottomSheet.
/// Changes the corner radius of the BottomSheet.
case cornerRadius(Double)
///Changes the color of the drag indicator.
/// Disables the bottom safe area insets.
case disableBottomSafeAreaInsets
/// Disables the flick through feature.
case disableFlickThrough
/// Changes the color of the drag indicator.
case dragIndicatorColor(Color)
///Prevents the lowest value (above 0) from being the bottom position and hiding the mainContent.
/// Prevents the lowest value (above 0) from being the bottom position and hiding the mainContent.
case noBottomPosition
///Hides the drag indicator.
/// Hides the drag indicator.
case noDragIndicator
///Hides the drag indicator and prevents the BottomSheet from being dragged.
/// Hides the drag indicator and prevents the BottomSheet from being dragged.
case notResizeable
///Adds a shadow to the background of the BottomSheet.
/// Adds a shadow to the background of the BottomSheet.
case shadow(color: Color = Color(.sRGBLinear, white: 0, opacity: 0.33), radius: CGFloat = 10, x: CGFloat = 0, y: CGFloat = 0)
///Shows a close button and declares an action to be performed when tapped.
/// Shows a close button and declares an action to be performed when tapped.
case showCloseButton(action: () -> Void = {})
///Dismisses the BottomSheet when swiped down.
/// Dismisses the BottomSheet when swiped down.
case swipeToDismiss
///Dismisses the BottomSheet when the background is tapped.
/// Dismisses the BottomSheet when the background is tapped.
case tapToDismiss

/**
Expand Down Expand Up @@ -78,6 +82,10 @@ public struct BottomSheet {
return "backgroundBlur"
case .cornerRadius:
return "cornerRadius"
case .disableBottomSafeAreaInsets:
return "disableBottomSafeAreaInsets"
case .disableFlickThrough:
return "disableFlickThrough"
case .dragIndicatorColor:
return "dragIndicatorColor"
case .noBottomPosition:
Expand Down
8 changes: 8 additions & 0 deletions Sources/BottomSheet/BottomSheetArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ internal extension Array where Element == BottomSheet.Options {
return cornerRadius
}

var disableBottomSafeAreaInsets: Bool {
return self.contains(BottomSheet.Options.disableBottomSafeAreaInsets)
}

var disableFlickThrough: Bool {
return self.contains(BottomSheet.Options.disableFlickThrough)
}

var dragIndicatorColor: Color {
var dragIndicatorColor: Color = Color(UIColor.tertiaryLabel)

Expand Down
42 changes: 27 additions & 15 deletions Sources/BottomSheet/BottomSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ internal struct BottomSheetView<hContent: View, mContent: View, bottomSheetPosit
}
}
.transition(.move(edge: .bottom))
.padding(.bottom, geometry.safeAreaInsets.bottom)
.padding(.bottom, self.options.disableBottomSafeAreaInsets ? nil : geometry.safeAreaInsets.bottom)
} else {
Color.clear
}
Expand Down Expand Up @@ -303,21 +303,33 @@ internal struct BottomSheetView<hContent: View, mContent: View, bottomSheetPosit
fileprivate func switchPosition(with height: CGFloat) -> Void {
if !self.isHiddenPosition {
if let currentIndex = self.allCases.firstIndex(where: { $0 == self.bottomSheetPosition }), self.allCases.count > 1 {
if height <= -0.1 && height > -0.3 {
if currentIndex < self.allCases.endIndex - 1 {
self.bottomSheetPosition = self.allCases[currentIndex + 1]
}
} else if height <= -0.3 {
self.bottomSheetPosition = self.allCases[self.allCases.endIndex - 1]
} else if height >= 0.1 && height < 0.3 {
if currentIndex > self.allCases.startIndex && (self.allCases[currentIndex - 1].rawValue != 0 || (self.allCases[currentIndex - 1].rawValue == 0 && self.options.swipeToDismiss)) {
self.bottomSheetPosition = self.allCases[currentIndex - 1]
if self.options.disableFlickThrough {
if height <= -0.1 {
if currentIndex < self.allCases.endIndex - 1 {
self.bottomSheetPosition = self.allCases[currentIndex + 1]
}
} else if height >= 0.1 {
if currentIndex > self.allCases.startIndex && (self.allCases[currentIndex - 1].rawValue != 0 || (self.allCases[currentIndex - 1].rawValue == 0 && self.options.swipeToDismiss)) {
self.bottomSheetPosition = self.allCases[currentIndex - 1]
}
}
} else if height >= 0.3 {
if (self.allCases[self.allCases.startIndex].rawValue == 0 && self.options.swipeToDismiss) || self.allCases[self.allCases.startIndex].rawValue != 0 {
self.bottomSheetPosition = self.allCases[self.allCases.startIndex]
} else {
self.bottomSheetPosition = self.allCases[self.allCases.startIndex + 1]
} else {
if height <= -0.1 && height > -0.3 {
if currentIndex < self.allCases.endIndex - 1 {
self.bottomSheetPosition = self.allCases[currentIndex + 1]
}
} else if height <= -0.3 {
self.bottomSheetPosition = self.allCases[self.allCases.endIndex - 1]
} else if height >= 0.1 && height < 0.3 {
if currentIndex > self.allCases.startIndex && (self.allCases[currentIndex - 1].rawValue != 0 || (self.allCases[currentIndex - 1].rawValue == 0 && self.options.swipeToDismiss)) {
self.bottomSheetPosition = self.allCases[currentIndex - 1]
}
} else if height >= 0.3 {
if (self.allCases[self.allCases.startIndex].rawValue == 0 && self.options.swipeToDismiss) || self.allCases[self.allCases.startIndex].rawValue != 0 {
self.bottomSheetPosition = self.allCases[self.allCases.startIndex]
} else {
self.bottomSheetPosition = self.allCases[self.allCases.startIndex + 1]
}
}
}
}
Expand Down

0 comments on commit 39f59cd

Please sign in to comment.