diff --git a/PanModal/Controller/PanModalPresentationController.swift b/PanModal/Controller/PanModalPresentationController.swift index 4617c981..7f2d23b5 100644 --- a/PanModal/Controller/PanModalPresentationController.swift +++ b/PanModal/Controller/PanModalPresentationController.swift @@ -111,7 +111,9 @@ public class PanModalPresentationController: UIPresentationController { view = DimmedView() } view.didTap = { [weak self] _ in - self?.dismissPresentedViewController() + if self?.presentable?.allowsTapToDismiss == true { + self?.dismissPresentedViewController() + } } return view }() diff --git a/PanModal/Presentable/PanModalPresentable+Defaults.swift b/PanModal/Presentable/PanModalPresentable+Defaults.swift index a69fc53c..9cb106ea 100644 --- a/PanModal/Presentable/PanModalPresentable+Defaults.swift +++ b/PanModal/Presentable/PanModalPresentable+Defaults.swift @@ -72,6 +72,10 @@ public extension PanModalPresentable where Self: UIViewController { return true } + var allowsTapToDismiss: Bool { + return true + } + var isUserInteractionEnabled: Bool { return true } diff --git a/PanModal/Presentable/PanModalPresentable.swift b/PanModal/Presentable/PanModalPresentable.swift index a5aab6b5..e5bd8b81 100644 --- a/PanModal/Presentable/PanModalPresentable.swift +++ b/PanModal/Presentable/PanModalPresentable.swift @@ -127,6 +127,13 @@ public protocol PanModalPresentable: AnyObject { */ var allowsDragToDismiss: Bool { get } + /** + A flag to determine if dismissal should be initiated when tapping on the dimmed background view. + + Default value is true. + */ + var allowsTapToDismiss: Bool { get } + /** A flag to toggle user interactions on the container view. diff --git a/Tests/PanModalTests.swift b/Tests/PanModalTests.swift index f5d499bd..358b8bbf 100644 --- a/Tests/PanModalTests.swift +++ b/Tests/PanModalTests.swift @@ -53,6 +53,7 @@ class PanModalTests: XCTestCase { XCTAssertEqual(vc.anchorModalToLongForm, true) XCTAssertEqual(vc.allowsExtendedPanScrolling, false) XCTAssertEqual(vc.allowsDragToDismiss, true) + XCTAssertEqual(vc.allowsTapToDismiss, true) XCTAssertEqual(vc.isUserInteractionEnabled, true) XCTAssertEqual(vc.isHapticFeedbackEnabled, true) XCTAssertEqual(vc.shouldRoundTopCorners, false)