From 47b9ac890afd333167ce87e87dbda071e8980ba1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 20 Jul 2024 10:27:49 -0700 Subject: [PATCH] Fix gallery controls visibility not transferring between pages Closes #511 --- .../Sources/GalleryVC/GalleryItemViewController.swift | 5 +++++ .../GalleryVC/Sources/GalleryVC/GalleryViewController.swift | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift index 4c810c42..5578e623 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift @@ -44,6 +44,7 @@ class GalleryItemViewController: UIViewController { private(set) var scrollAndZoomEnabled = true private var scrollViewSizeForLastZoomScaleUpdate: CGSize? + override var prefersHomeIndicatorAutoHidden: Bool { return !controlsVisible } @@ -227,6 +228,8 @@ class GalleryItemViewController: UIViewController { updateZoomScale(resetZoom: true) } centerContent() + // Ensure the transform is correct if the controls are hidden and their size changed. + setControlsVisible(controlsVisible, animated: false) } override func viewDidAppear(_ animated: Bool) { @@ -289,10 +292,12 @@ class GalleryItemViewController: UIViewController { func setControlsVisible(_ visible: Bool, animated: Bool) { controlsVisible = visible + guard let topControlsView, let bottomControlsView else { return } + func updateControlsViews() { topControlsView.transform = CGAffineTransform(translationX: 0, y: visible ? 0 : -topControlsView.bounds.height) bottomControlsView.transform = CGAffineTransform(translationX: 0, y: visible ? 0 : bottomControlsView.bounds.height) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryViewController.swift index 6131f73c..e53e90ea 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryViewController.swift @@ -125,6 +125,8 @@ extension GalleryViewController: UIPageViewControllerDataSource { extension GalleryViewController: UIPageViewControllerDelegate { public func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) { currentItemViewController.content.galleryContentWillDisappear() + let new = pendingViewControllers[0] as! GalleryItemViewController + new.setControlsVisible(currentItemViewController.controlsVisible, animated: false) } public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {