Add allowTapToDismiss to PanModalPresentable (#58)

This commit is contained in:
Scott Campbell 2019-10-09 16:06:51 -04:00 committed by Tosin Afolabi
parent af264ebb0d
commit 5c1d8c49a7
4 changed files with 15 additions and 1 deletions

View File

@ -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
}()

View File

@ -72,6 +72,10 @@ public extension PanModalPresentable where Self: UIViewController {
return true
}
var allowsTapToDismiss: Bool {
return true
}
var isUserInteractionEnabled: Bool {
return true
}

View File

@ -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.

View File

@ -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)