Skip to content

Commit d34c16b

Browse files
committed
Refactor BackdropView.dismissalTapGestureRecognizer
* Added the interface and implementation comment * Changed the property as non-optional
1 parent 0581325 commit d34c16b

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Sources/BackdropView.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,19 @@ import UIKit
77
public class BackdropView: UIView {
88

99
/// The gesture recognizer for tap gestures to dismiss a panel.
10-
@objc public var dismissalTapGestureRecognizer: UITapGestureRecognizer!
10+
///
11+
/// By default, this gesture recognizer is disabled as following the default behavior of iOS modalities.
12+
/// To dismiss a panel by tap gestures on the backrdop, `dismissalTapGestureRecognizer.isEanbled` is set to true.
13+
@objc public var dismissalTapGestureRecognizer: UITapGestureRecognizer
14+
15+
init() {
16+
dismissalTapGestureRecognizer = UITapGestureRecognizer()
17+
dismissalTapGestureRecognizer.isEnabled = false
18+
super.init(frame: .zero)
19+
addGestureRecognizer(dismissalTapGestureRecognizer)
20+
}
21+
22+
required init?(coder: NSCoder) {
23+
fatalError("init(coder:) has not been implemented")
24+
}
1125
}

Sources/Core.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ class Core: NSObject, UIGestureRecognizerDelegate {
9696
panGestureRecognizer.addTarget(self, action: #selector(handle(panGesture:)))
9797
panGestureRecognizer.delegate = self
9898

99-
// Set tap-to-dismiss in the backdrop view
100-
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleBackdrop(tapGesture:)))
101-
tapGesture.isEnabled = false
102-
backdropView.dismissalTapGestureRecognizer = tapGesture
103-
backdropView.addGestureRecognizer(tapGesture)
99+
// Set the tap-to-dismiss action of the backdrop view.
100+
// It's disabled by default. See also BackdropView.dismissalTapGestureRecognizer.
101+
backdropView.dismissalTapGestureRecognizer.addTarget(self, action: #selector(handleBackdrop(tapGesture:)))
104102
}
105103

106104
deinit {

0 commit comments

Comments
 (0)