From 2c3a7f7e55c7e359b76d9456ccb747ddad7e8755 Mon Sep 17 00:00:00 2001 From: "alekseev.pg" <> Date: Mon, 18 Aug 2025 17:10:34 +0400 Subject: [PATCH] add new property --- .../BottomSheet+HitTestAllowed.swift | 25 +++++++++++++++++++ .../BottomSheetView+HelperViews.swift | 2 +- .../Models/BottomSheetConfiguration.swift | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+HitTestAllowed.swift diff --git a/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+HitTestAllowed.swift b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+HitTestAllowed.swift new file mode 100644 index 000000000..694f8b19f --- /dev/null +++ b/Sources/BottomSheet/BottomSheet+ViewModifiers/BottomSheet+HitTestAllowed.swift @@ -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 + } +} \ No newline at end of file diff --git a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift index 8ccb6b062..22f100a47 100644 --- a/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift +++ b/Sources/BottomSheet/BottomSheetView/BottomSheetView+HelperViews.swift @@ -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) diff --git a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift index 33a430930..d4e16ebc8 100644 --- a/Sources/BottomSheet/Models/BottomSheetConfiguration.swift +++ b/Sources/BottomSheet/Models/BottomSheetConfiguration.swift @@ -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 @@ -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 }