Skip to content

Commit

Permalink
support Tappable View spring loading
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Sep 28, 2024
1 parent 3d58069 commit 2d10fad
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Sources/UIComponent/Components/View/TappableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ open class TappableView: UIView {
gesture.numberOfTapsRequired = 2
return gesture
}()


/// A interaction for managing spring loading on the TappableView.
public private(set) lazy var springLoadedInteraction = UISpringLoadedInteraction { [weak self] interaction, context in
guard let self else { return }
self.onSpringLoaded?(self)
}

/// A gesture recognizer for detecting long presses on the TappableView.
public private(set) lazy var longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))

Expand Down Expand Up @@ -133,6 +139,17 @@ open class TappableView: UIView {
}
}

/// A closure that is called when the TappableView is spring loaded.
public var onSpringLoaded: ((TappableView) -> Void)? {
didSet {
if onSpringLoaded != nil {
addInteraction(springLoadedInteraction)
} else {
removeInteraction(springLoadedInteraction)
}
}
}

#if !os(tvOS)
/// The interaction responsible for handling drop operations on the TappableView.
private var dropInteraction: UIDropInteraction?
Expand Down

0 comments on commit 2d10fad

Please sign in to comment.