Skip to content

Commit

Permalink
Use highPriorityGesture for drag (lucaszischka#153)
Browse files Browse the repository at this point in the history
highPriorityGesture is required to make dragging the bottom sheet work even when user starts dragging on buttons or other pressable items
  • Loading branch information
danilhodlevskiy committed Jun 5, 2024
1 parent 7af4bb2 commit 3ea9dd2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,6 @@ internal extension BottomSheetView {
#endif
}

// For `backgroundBlur`
func opacity(with geometry: GeometryProxy) -> Double {
if self.configuration.isBackgroundBlurEnabled {
// Calculate background blur relative to BottomSheet height
return min(
max(
Double(
self.height(with: geometry) / self.maxBottomSheetHeight(with: geometry)
),
0
),
1
)
} else {
return 0
}
}

// For `tapToDismiss`
func tapToDismissAction() {
// Only dismiss sheet when `tapToDismiss` is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import SwiftUI
import Combine

internal extension BottomSheetView {
func fullScreenBackground(with geometry: GeometryProxy) -> some View {
func fullScreenBackground() -> some View {
VisualEffectView(visualEffect: self.configuration.backgroundBlurMaterial)
.opacity(
// When `backgroundBlur` is enabled the opacity is calculated
// based on the current height of the BottomSheet relative to its maximum height
// Otherwise it is 0
self.opacity(with: geometry)
)
.opacity(self.configuration.backgroundBlurOpacity)
// Make the background fill the whole screen including safe area
.frame(
maxWidth: .infinity,
Expand Down Expand Up @@ -181,7 +176,8 @@ internal extension BottomSheetView {
// Main content
self.mainContent
// Make the main content drag-able if content drag is enabled
.gesture(
// highPriorityGesture is required to make dragging the bottom sheet work even when user starts dragging on buttons or other pressable items
.highPriorityGesture(
self.configuration.isContentDragEnabled && self.configuration.isResizable ?
self.dragGesture(with: geometry) : nil
)
Expand Down
2 changes: 1 addition & 1 deletion Sources/BottomSheet/BottomSheetView/BottomSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal struct BottomSheetView<HContent: View, MContent: View>: View {
// Hide everything when the BottomSheet is hidden
if !self.bottomSheetPosition.isHidden {
// Full screen background for aligning and used by `backgroundBlur` and `tapToDismiss`
self.fullScreenBackground(with: geometry)
self.fullScreenBackground()

// The BottomSheet itself
self.bottomSheet(with: geometry)
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 @@ -37,6 +37,7 @@ internal class BottomSheetConfiguration: Equatable {
blendDuration: 1
)
var backgroundBlurMaterial: VisualEffect = .system
var backgroundBlurOpacity: CGFloat = 0.2
var backgroundViewID: UUID?
var backgroundView: AnyView?
var dragIndicatorAction: ((GeometryProxy) -> Void)?
Expand Down

0 comments on commit 3ea9dd2

Please sign in to comment.