@@ -11,20 +11,25 @@ import ReactiveDataDisplayManager
1111/// Base view to implement label within cell
1212public class MessageView : UIView {
1313
14+ // MARK: - Aliases
15+
16+ typealias TapGesture = UILongPressGestureRecognizer
17+
1418 // MARK: - Constants
1519
1620 private enum Constants {
17- static let tapGestureName = " TapGesture "
21+ static let minimumPressDuration : TimeInterval = 0.001
1822 }
1923
2024 // MARK: - Public initialization
2125
2226 public override init ( frame: CGRect ) {
2327 super. init ( frame: frame)
2428
25- let tapGesture = UITapGestureRecognizer ( target: self , action: #selector( handleTapGesture ( _: ) ) )
29+ let tapGesture = TapGesture ( target: self , action: #selector( handleTapGesture ( _: ) ) )
2630 tapGesture. cancelsTouchesInView = false
27- textView. addGestureRecognizer ( tapGesture)
31+ tapGesture. minimumPressDuration = Constants . minimumPressDuration
32+ addGestureRecognizer ( tapGesture)
2833 }
2934
3035 required init ? ( coder: NSCoder ) {
@@ -36,7 +41,7 @@ public class MessageView: UIView {
3641 private var textView = UITextView ( frame: . zero)
3742 private var dataDetection : DataDetection ?
3843 private var tapHandler : TapHandler ?
39- private var pressStateAction : ( ( UITapGestureRecognizer . State ) -> Void ) ?
44+ private var pressStateAction : ( ( TapGesture . State ) -> Void ) ?
4045
4146}
4247
@@ -294,12 +299,11 @@ private extension MessageView {
294299 dataDetectionHandler ( data)
295300 }
296301
297- @objc func handleTapGesture( _ gesture: UITapGestureRecognizer ) {
298- guard let tapAction = tapHandler? . tapAction else {
302+ @objc func handleTapGesture( _ gesture: TapGesture ) {
303+ guard tapHandler? . tapAction != nil else {
299304 return
300305 }
301306 pressStateAction ? ( gesture. state)
302- tapAction ( )
303307 }
304308
305309 func setIsSelectablePropertyIfNeeded( for model: Model ) {
@@ -310,12 +314,15 @@ private extension MessageView {
310314 }
311315 }
312316
313- func handleTapGesture( _ state: UITapGestureRecognizer . State , with model: Model ) {
317+ func handleTapGesture( _ state: TapGesture . State , with model: Model ) {
314318 switch state {
315319 case . began:
316320 setPressState ( for: model)
317- case . ended, . cancelled:
321+ case . cancelled, . failed:
322+ setInitialState ( for: model)
323+ case . ended:
318324 setInitialState ( for: model)
325+ tapHandler? . tapAction ? ( )
319326 default :
320327 break
321328 }
0 commit comments