Compare commits

...

5 Commits

5 changed files with 53 additions and 10 deletions

View File

@ -91,23 +91,33 @@ class GalleryItemViewController: UIViewController {
view.addSubview(topControlsView) view.addSubview(topControlsView)
var shareConfig = UIButton.Configuration.gray() var shareConfig = UIButton.Configuration.gray()
shareConfig.cornerStyle = .capsule shareConfig.cornerStyle = .dynamic
shareConfig.background.backgroundColor = .black.withAlphaComponent(0.25) shareConfig.background.backgroundColor = .black.withAlphaComponent(0.25)
shareConfig.baseForegroundColor = .white shareConfig.baseForegroundColor = .white
shareConfig.image = UIImage(systemName: "square.and.arrow.up") shareConfig.image = UIImage(systemName: "square.and.arrow.up")
shareConfig.contentInsets = NSDirectionalEdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 4)
shareButton = UIButton(configuration: shareConfig) shareButton = UIButton(configuration: shareConfig)
shareButton.addTarget(self, action: #selector(shareButtonPressed), for: .touchUpInside) shareButton.addTarget(self, action: #selector(shareButtonPressed), for: .touchUpInside)
shareButton.isPointerInteractionEnabled = true
shareButton.pointerStyleProvider = { button, effect, shape in
return UIPointerStyle(effect: .highlight(effect.preview), shape: .roundedRect(button.frame))
}
shareButton.translatesAutoresizingMaskIntoConstraints = false shareButton.translatesAutoresizingMaskIntoConstraints = false
updateShareButton() updateShareButton()
topControlsView.addSubview(shareButton) topControlsView.addSubview(shareButton)
var closeConfig = UIButton.Configuration.gray() var closeConfig = UIButton.Configuration.gray()
closeConfig.cornerStyle = .capsule closeConfig.cornerStyle = .dynamic
closeConfig.background.backgroundColor = .black.withAlphaComponent(0.25) closeConfig.background.backgroundColor = .black.withAlphaComponent(0.25)
closeConfig.baseForegroundColor = .white closeConfig.baseForegroundColor = .white
closeConfig.image = UIImage(systemName: "xmark") closeConfig.image = UIImage(systemName: "xmark")
closeConfig.contentInsets = NSDirectionalEdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 4)
let closeButton = UIButton(configuration: closeConfig) let closeButton = UIButton(configuration: closeConfig)
closeButton.addTarget(self, action: #selector(closeButtonPressed), for: .touchUpInside) closeButton.addTarget(self, action: #selector(closeButtonPressed), for: .touchUpInside)
closeButton.isPointerInteractionEnabled = true
closeButton.pointerStyleProvider = { button, effect, shape in
return UIPointerStyle(effect: .highlight(effect.preview), shape: .roundedRect(button.frame))
}
closeButton.translatesAutoresizingMaskIntoConstraints = false closeButton.translatesAutoresizingMaskIntoConstraints = false
topControlsView.addSubview(closeButton) topControlsView.addSubview(closeButton)
@ -160,10 +170,12 @@ class GalleryItemViewController: UIViewController {
shareButtonLeadingConstraint, shareButtonLeadingConstraint,
shareButtonTopConstraint, shareButtonTopConstraint,
shareButton.bottomAnchor.constraint(equalTo: topControlsView.bottomAnchor), shareButton.bottomAnchor.constraint(equalTo: topControlsView.bottomAnchor),
shareButton.widthAnchor.constraint(equalTo: shareButton.heightAnchor),
closeButtonTrailingConstraint, closeButtonTrailingConstraint,
closeButtonTopConstraint, closeButtonTopConstraint,
closeButton.bottomAnchor.constraint(equalTo: topControlsView.bottomAnchor), closeButton.bottomAnchor.constraint(equalTo: topControlsView.bottomAnchor),
closeButton.widthAnchor.constraint(equalTo: closeButton.heightAnchor),
bottomControlsView.leadingAnchor.constraint(equalTo: view.leadingAnchor), bottomControlsView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
bottomControlsView.trailingAnchor.constraint(equalTo: view.trailingAnchor), bottomControlsView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
@ -172,6 +184,8 @@ class GalleryItemViewController: UIViewController {
captionTextView.heightAnchor.constraint(equalToConstant: 150), captionTextView.heightAnchor.constraint(equalToConstant: 150),
]) ])
updateTopControlsInsets()
singleTap = UITapGestureRecognizer(target: self, action: #selector(viewPressed)) singleTap = UITapGestureRecognizer(target: self, action: #selector(viewPressed))
singleTap.delegate = self singleTap.delegate = self
doubleTap = UITapGestureRecognizer(target: self, action: #selector(viewDoublePressed)) doubleTap = UITapGestureRecognizer(target: self, action: #selector(viewDoublePressed))
@ -358,6 +372,11 @@ class GalleryItemViewController: UIViewController {
shareButtonTopConstraint.constant = 24 shareButtonTopConstraint.constant = 24
closeButtonTrailingConstraint.constant = 24 closeButtonTrailingConstraint.constant = 24
closeButtonTopConstraint.constant = 24 closeButtonTopConstraint.constant = 24
} else {
shareButtonLeadingConstraint.constant = 8
shareButtonTopConstraint.constant = 8
closeButtonTrailingConstraint.constant = 8
closeButtonTopConstraint.constant = 8
} }
} }

View File

@ -102,6 +102,8 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
} }
animator.addCompletion { _ in animator.addCompletion { _ in
dimmingView.removeFromSuperview()
to.view.backgroundColor = .black to.view.backgroundColor = .black
if sourceToDestTransform != nil { if sourceToDestTransform != nil {

View File

@ -348,6 +348,8 @@ private class MuteButton: UIControl {
imageView.centerXAnchor.constraint(equalTo: centerXAnchor), imageView.centerXAnchor.constraint(equalTo: centerXAnchor),
imageView.centerYAnchor.constraint(equalTo: centerYAnchor), imageView.centerYAnchor.constraint(equalTo: centerYAnchor),
]) ])
addInteraction(UIPointerInteraction(delegate: nil))
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
@ -395,6 +397,8 @@ private class MenuButton: UIControl {
isContextMenuInteractionEnabled = true isContextMenuInteractionEnabled = true
showsMenuAsPrimaryAction = true showsMenuAsPrimaryAction = true
addInteraction(UIPointerInteraction(delegate: nil))
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -158,6 +158,8 @@ private class VideoOverlayButton: UIControl {
imageView.topAnchor.constraint(equalTo: topAnchor, constant: 8), imageView.topAnchor.constraint(equalTo: topAnchor, constant: 8),
imageView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8), imageView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
]) ])
addInteraction(UIPointerInteraction(delegate: self))
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
@ -175,21 +177,25 @@ private class VideoOverlayButton: UIControl {
} }
override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
if touch.type != .indirectPointer {
UIView.animate(withDuration: 0.2) { UIView.animate(withDuration: 0.2) {
self.backgroundView.alpha = 1 self.backgroundView.alpha = 1
self.backgroundView.transform = CGAffineTransform(scaleX: 1/0.8, y: 1/0.8) self.backgroundView.transform = CGAffineTransform(scaleX: 1/0.8, y: 1/0.8)
self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
} }
}
return super.beginTracking(touch, with: event) return super.beginTracking(touch, with: event)
} }
override func endTracking(_ touch: UITouch?, with event: UIEvent?) { override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
if touch?.type != .indirectPointer {
UIView.animate(withDuration: 0.2) { UIView.animate(withDuration: 0.2) {
self.backgroundView.alpha = 0 self.backgroundView.alpha = 0
self.backgroundView.transform = .identity self.backgroundView.transform = .identity
self.transform = .identity self.transform = .identity
} }
} }
}
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer is UITapGestureRecognizer { if gestureRecognizer is UITapGestureRecognizer {
@ -198,3 +204,14 @@ private class VideoOverlayButton: UIControl {
return true return true
} }
} }
extension VideoOverlayButton: UIPointerInteractionDelegate {
func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
return UIPointerRegion(rect: bounds)
}
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
let preview = UITargetedPreview(view: self)
return UIPointerStyle(effect: .highlight(preview), shape: .path(UIBezierPath(ovalIn: frame)))
}
}

View File

@ -499,6 +499,7 @@ extension AttachmentView: UIContextMenuInteractionDelegate {
var actions = [ var actions = [
UIAction(title: "Share…", image: UIImage(systemName: "square.and.arrow.up")) { [unowned self] _ in UIAction(title: "Share…", image: UIImage(systemName: "square.and.arrow.up")) { [unowned self] _ in
let vc = UIActivityViewController(activityItems: [itemSource], applicationActivities: [SaveToPhotosActivity()]) let vc = UIActivityViewController(activityItems: [itemSource], applicationActivities: [SaveToPhotosActivity()])
vc.popoverPresentationController?.sourceView = self
self.delegate?.attachmentViewPresent(vc, animated: true) self.delegate?.attachmentViewPresent(vc, animated: true)
} }
] ]