Skip to content

Commit

Permalink
add context menu provider to TappableView
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Aug 3, 2021
1 parent 36974bd commit 4a8e297
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/UIComponent/Components/TappableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ open class TappableView: ComponentView {

lazy var tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTap))
lazy var longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))
lazy var contextMenuInteraction = UIContextMenuInteraction(delegate: self)

public var onTap: ((TappableView) -> Void)? {
didSet {
Expand All @@ -47,6 +48,16 @@ open class TappableView: ComponentView {
}
}
}

public var contextMenuProvider: UIContextMenuActionProvider? {
didSet {
if contextMenuProvider != nil {
addInteraction(contextMenuInteraction)
} else {
removeInteraction(contextMenuInteraction)
}
}
}

open var isHighlighted: Bool = false {
didSet {
Expand Down Expand Up @@ -93,6 +104,12 @@ open class TappableView: ComponentView {
}
}

extension TappableView: UIContextMenuInteractionDelegate {
public func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: contextMenuProvider)
}
}

extension Component {
public func tappableView(configuration: TappableViewConfiguration? = nil,
_ onTap: @escaping (TappableView) -> Void) -> ViewUpdateComponent<ComponentDisplayableViewComponent<TappableView>> {
Expand Down

0 comments on commit 4a8e297

Please sign in to comment.