Compare commits
3 Commits
da4787946d
...
86e1403230
Author | SHA1 | Date | |
---|---|---|---|
86e1403230 | |||
370b589a6b | |||
4fb7cacf31 |
@ -1,5 +1,5 @@
|
||||
//
|
||||
// EditAttachmentWrapperGalleryContentViewController.swift
|
||||
// AttachmentWrapperGalleryContentViewController.swift
|
||||
// ComposeUI
|
||||
//
|
||||
// Created by Shadowfacts on 11/22/24.
|
||||
@ -8,7 +8,7 @@
|
||||
import UIKit
|
||||
import GalleryVC
|
||||
|
||||
class EditAttachmentWrapperGalleryContentViewController: UIViewController, GalleryContentViewController {
|
||||
class AttachmentWrapperGalleryContentViewController: UIViewController, GalleryContentViewController {
|
||||
let draftAttachment: DraftAttachment
|
||||
let wrapped: any GalleryContentViewController
|
||||
|
||||
@ -76,6 +76,16 @@ class EditAttachmentWrapperGalleryContentViewController: UIViewController, Galle
|
||||
if !visible {
|
||||
editDescriptionViewController.textView?.resignFirstResponder()
|
||||
}
|
||||
if #available(iOS 16.0, macCatalyst 17.0, *),
|
||||
let wrapped = wrapped as? ImageGalleryContentViewController,
|
||||
let interaction = wrapped.analysisInteraction {
|
||||
if visible {
|
||||
let bottom = editDescriptionViewController.view.bounds.height - editDescriptionViewController.view.keyboardLayoutGuide.layoutFrame.height
|
||||
interaction.supplementaryInterfaceContentInsets = UIEdgeInsets(top: 0, left: 0, bottom: bottom, right: 0)
|
||||
} else {
|
||||
interaction.supplementaryInterfaceContentInsets = .zero
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func galleryContentDidAppear() {
|
||||
@ -94,6 +104,15 @@ class EditAttachmentWrapperGalleryContentViewController: UIViewController, Galle
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func galleryShouldBeginInteractiveDismiss() -> Bool {
|
||||
if editDescriptionViewController.textView.isFirstResponder {
|
||||
editDescriptionViewController.textView.resignFirstResponder()
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class EditAttachmentDescriptionViewController: UIViewController {
|
@ -60,7 +60,7 @@ struct AttachmentsGalleryDataSource: GalleryDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
return EditAttachmentWrapperGalleryContentViewController(draftAttachment: attachment, wrapped: content)
|
||||
return AttachmentWrapperGalleryContentViewController(draftAttachment: attachment, wrapped: content)
|
||||
}
|
||||
|
||||
func galleryContentTransitionSourceView(forItemAt index: Int) -> UIView? {
|
||||
|
@ -25,7 +25,7 @@ open class ImageGalleryContentViewController: UIViewController, GalleryContentVi
|
||||
private static let analyzer = ImageAnalyzer()
|
||||
private var _analysisInteraction: AnyObject?
|
||||
@available(iOS 16.0, macCatalyst 17.0, *)
|
||||
private var analysisInteraction: ImageAnalysisInteraction? { _analysisInteraction as? ImageAnalysisInteraction }
|
||||
public var analysisInteraction: ImageAnalysisInteraction? { _analysisInteraction as? ImageAnalysisInteraction }
|
||||
|
||||
public init(image: UIImage, caption: String?, gifController: GIFController?) {
|
||||
self.caption = caption
|
||||
|
@ -23,6 +23,7 @@ public protocol GalleryContentViewController: UIViewController {
|
||||
func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool)
|
||||
func galleryContentDidAppear()
|
||||
func galleryContentWillDisappear()
|
||||
func galleryShouldBeginInteractiveDismiss() -> Bool
|
||||
}
|
||||
|
||||
public extension GalleryContentViewController {
|
||||
@ -58,6 +59,10 @@ public extension GalleryContentViewController {
|
||||
|
||||
func galleryContentWillDisappear() {
|
||||
}
|
||||
|
||||
func galleryShouldBeginInteractiveDismiss() -> Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
public enum GalleryContentPresentationAnimation {
|
||||
|
@ -106,12 +106,8 @@ extension GalleryDismissInteraction: UIGestureRecognizerDelegate {
|
||||
let itemVC = viewController.currentItemViewController
|
||||
if viewController.galleryDataSource.galleryContentTransitionSourceView(forItemAt: itemVC.itemIndex) == nil {
|
||||
return false
|
||||
} else if itemVC.scrollView.zoomScale > itemVC.scrollView.minimumZoomScale {
|
||||
return false
|
||||
} else if !itemVC.scrollAndZoomEnabled {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
return itemVC.shouldBeginInteractiveDismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,6 +228,10 @@ class GalleryItemViewController: UIViewController {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillUpdate), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillUpdate), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillUpdate), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
|
||||
|
||||
if #available(iOS 17.0, *) {
|
||||
view.keyboardLayoutGuide.usesBottomSafeArea = false
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func keyboardWillUpdate() {
|
||||
@ -354,7 +358,17 @@ class GalleryItemViewController: UIViewController {
|
||||
return
|
||||
}
|
||||
|
||||
let heightScale = (view.bounds.height - view.keyboardLayoutGuide.layoutFrame.height) / content.contentSize.height
|
||||
// Post-iOS 17, we can ask the keyboard layout guide to ignore the bottom safe area.
|
||||
// Pre, we have to do that ourselves.
|
||||
let keyboardHeight: CGFloat
|
||||
if #available(iOS 17.0, *) {
|
||||
keyboardHeight = view.keyboardLayoutGuide.layoutFrame.height
|
||||
} else {
|
||||
let bottomSafeArea = view.bounds.height - view.safeAreaLayoutGuide.layoutFrame.maxY
|
||||
let rawKeyboardHeight = view.keyboardLayoutGuide.layoutFrame.height
|
||||
keyboardHeight = abs(rawKeyboardHeight - bottomSafeArea) < 1 ? 0 : rawKeyboardHeight
|
||||
}
|
||||
let heightScale = (view.bounds.height - keyboardHeight) / content.contentSize.height
|
||||
let widthScale = view.bounds.width / content.contentSize.width
|
||||
let minScale = min(widthScale, heightScale)
|
||||
let maxScale = minScale >= 1 ? minScale + 2 : 2
|
||||
@ -514,6 +528,16 @@ class GalleryItemViewController: UIViewController {
|
||||
present(activityVC, animated: true)
|
||||
}
|
||||
|
||||
func shouldBeginInteractiveDismiss() -> Bool {
|
||||
if scrollView.zoomScale > scrollView.minimumZoomScale {
|
||||
false
|
||||
} else if !scrollAndZoomEnabled {
|
||||
false
|
||||
} else {
|
||||
content.galleryShouldBeginInteractiveDismiss()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension GalleryItemViewController: GalleryContentViewControllerContainer {
|
||||
|
Loading…
x
Reference in New Issue
Block a user