From 4fb7cacf31ae9a88af89dbd63d0d3e2aa6b02bf9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 4 Feb 2025 18:49:11 -0500 Subject: [PATCH] Fix tall gallery content being inset on the bottom edge --- .../GalleryVC/GalleryItemViewController.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift index 546b9413..dfde3f79 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift @@ -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