Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// BottomSheet+HitTestAllowed.swift
//
// Created by Pavel Alekseev.
// Copyright © 2025 Pavel Alekseev. All rights reserved.
//

import Foundation

public extension BottomSheet {

/// Override whether the background allows hit testing, independent of tap-to-dismiss setting.
///
/// When enabled, users can tap through the BottomSheet background even if tap-to-dismiss is disabled.
/// When disabled, the background blocks tap events even if tap-to-dismiss is enabled.
///
/// - Parameters:
/// - bool: A boolean whether hit testing is allowed on the background.
///
/// - Returns: A BottomSheet with custom hit testing behavior.
func hitTestAllowed(_ bool: Bool) -> BottomSheet {
self.configuration.isHitTestAllowed = bool
return self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal extension BottomSheetView {
.edgesIgnoringSafeArea(.all)
// Make the background tap-able for `tapToDismiss`
.contentShape(Rectangle())
.allowsHitTesting(self.configuration.isTapToDismissEnabled)
.allowsHitTesting(self.configuration.isHitTestAllowed ?? self.configuration.isTapToDismissEnabled)
.onTapGesture(perform: self.tapToDismissAction)
// Make the background transition via opacity
.transition(.opacity)
Expand Down
2 changes: 2 additions & 0 deletions Sources/BottomSheet/Models/BottomSheetConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class BottomSheetConfiguration: Equatable {
lhs.isResizable == rhs.isResizable &&
lhs.isSwipeToDismissEnabled == rhs.isSwipeToDismissEnabled &&
lhs.isTapToDismissEnabled == rhs.isTapToDismissEnabled &&
lhs.isHitTestAllowed == rhs.isHitTestAllowed &&
lhs.iPadFloatingSheet == rhs.iPadFloatingSheet &&
lhs.sheetWidth == rhs.sheetWidth &&
lhs.accountForKeyboardHeight == rhs.accountForKeyboardHeight
Expand Down Expand Up @@ -54,6 +55,7 @@ internal class BottomSheetConfiguration: Equatable {
var isResizable: Bool = true
var isSwipeToDismissEnabled: Bool = false
var isTapToDismissEnabled: Bool = false
var isHitTestAllowed: Bool? = nil
var onDismiss: () -> Void = {}
var onDragEnded: (DragGesture.Value) -> Void = { _ in }
var onDragChanged: (DragGesture.Value) -> Void = { _ in }
Expand Down