Skip to content

Commit

Permalink
add preview background color
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Aug 3, 2021
1 parent 82762be commit 2ac0122
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,30 @@ class AsyncImageViewController: ComponentViewController {
let detailVC = AsyncImageDetailViewController()
detailVC.image = image
$0.parentViewController?.navigationController?.pushViewController(detailVC, animated: true)
}.previewProvider {
}
.previewBackgroundColor(.systemBackground.withAlphaComponent(0.7))
.previewProvider {
let detailVC = AsyncImageDetailViewController()
detailVC.preferredContentSize = image.size
detailVC.image = image
detailVC.preferredContentSize = image.size
detailVC.view.backgroundColor = .clear
return detailVC
}.contextMenuProvider { [weak self] in
}
.contextMenuProvider { [weak self] in
UIMenu(children: [
UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: [.destructive], handler: { action in
self?.images.remove(at: index)
})
])
}
.id(image.url.absoluteString)
}
}
}

override func viewDidLoad() {
super.viewDidLoad()
componentView.animator = AnimatedReloadAnimator()
title = "Async Image"
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/UIComponent/Components/TappableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open class TappableView: ComponentView {
lazy var longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))
lazy var contextMenuInteraction = UIContextMenuInteraction(delegate: self)

public var previewBackgroundColor: UIColor?
public var onTap: ((TappableView) -> Void)? {
didSet {
if onTap != nil {
Expand Down Expand Up @@ -131,6 +132,15 @@ extension TappableView: UIContextMenuInteractionDelegate {
}
}

public func contextMenuInteraction(_ interaction: UIContextMenuInteraction, previewForHighlightingMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
if let previewBackgroundColor = previewBackgroundColor {
let param = UIPreviewParameters()
param.backgroundColor = previewBackgroundColor
return UITargetedPreview(view: self, parameters: param)
}
return nil
}

public func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
if let onCommitPreview = onCommitPreview {
onCommitPreview(animator)
Expand Down

0 comments on commit 2ac0122

Please sign in to comment.