Skip to content

Commit

Permalink
Add allowTapToDismiss to PanModalPresentable (slackhq#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Campbell authored and TosinAF committed Oct 9, 2019
1 parent af264eb commit 5c1d8c4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion PanModal/Controller/PanModalPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand Down
4 changes: 4 additions & 0 deletions PanModal/Presentable/PanModalPresentable+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public extension PanModalPresentable where Self: UIViewController {
return true
}

var allowsTapToDismiss: Bool {
return true
}

var isUserInteractionEnabled: Bool {
return true
}
Expand Down
7 changes: 7 additions & 0 deletions PanModal/Presentable/PanModalPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Tests/PanModalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5c1d8c4

Please sign in to comment.