From 3f6890d42ac18ae173d933658bc26a1a1a878b12 Mon Sep 17 00:00:00 2001 From: Ahava Morse Date: Mon, 29 Dec 2025 15:30:06 -0800 Subject: [PATCH 1/2] fix: hide loader when no items --- Source/Helpers/Permissions/YPPermissionCheckable.swift | 5 +++-- Source/Pages/Gallery/YPLibraryVC.swift | 9 +++++++-- Source/YPPickerVC.swift | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/Helpers/Permissions/YPPermissionCheckable.swift b/Source/Helpers/Permissions/YPPermissionCheckable.swift index fb433a2c..51a81fb8 100644 --- a/Source/Helpers/Permissions/YPPermissionCheckable.swift +++ b/Source/Helpers/Permissions/YPPermissionCheckable.swift @@ -9,18 +9,19 @@ import UIKit internal protocol YPPermissionCheckable { - func doAfterLibraryPermissionCheck(block: @escaping () -> Void) + func doAfterLibraryPermissionCheck(block: @escaping () -> Void, permissionDeniedBlock: (() -> Void)?) func doAfterCameraPermissionCheck(block: @escaping () -> Void) func checkLibraryPermission() func checkCameraPermission() } internal extension YPPermissionCheckable where Self: UIViewController { - func doAfterLibraryPermissionCheck(block: @escaping () -> Void) { + func doAfterLibraryPermissionCheck(block: @escaping () -> Void, permissionDeniedBlock: (() -> Void)? = nil) { YPPermissionManager.checkLibraryPermissionAndAskIfNeeded(sourceVC: self) { hasPermission in if hasPermission { block() } else { + permissionDeniedBlock?() ypLog("Not enough permissions.") } } diff --git a/Source/Pages/Gallery/YPLibraryVC.swift b/Source/Pages/Gallery/YPLibraryVC.swift index 5a5bf782..c96328d9 100644 --- a/Source/Pages/Gallery/YPLibraryVC.swift +++ b/Source/Pages/Gallery/YPLibraryVC.swift @@ -299,12 +299,17 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable { addToSelection(assetIndex: 0) } } else { - delegate?.libraryViewHaveNoItems() + libraryViewHaveNoItems() } scrollToTop() } - + + func libraryViewHaveNoItems() { + v.hideLoader() + delegate?.libraryViewHaveNoItems() + } + func buildPHFetchOptions() -> PHFetchOptions { // Sorting condition if let userOpt = YPConfig.library.options { diff --git a/Source/YPPickerVC.swift b/Source/YPPickerVC.swift index 0a9f628f..23951bcc 100644 --- a/Source/YPPickerVC.swift +++ b/Source/YPPickerVC.swift @@ -181,9 +181,11 @@ open class YPPickerVC: YPBottomPager, YPBottomPagerDelegate { // Re-trigger permission check if let vc = vc as? YPLibraryVC { - vc.doAfterLibraryPermissionCheck { [weak vc] in + vc.doAfterLibraryPermissionCheck(block: { [weak vc] in vc?.initialize() - } + }, permissionDeniedBlock: { [weak vc] in + vc?.libraryViewHaveNoItems() + }) } else if let cameraVC = vc as? YPCameraVC { cameraVC.start() } else if let videoVC = vc as? YPVideoCaptureVC { From e1e3df0360ed206906acb14839cf45bf01c2f4b2 Mon Sep 17 00:00:00 2001 From: Ahava Morse Date: Mon, 29 Dec 2025 15:32:17 -0800 Subject: [PATCH 2/2] chore: make YPPickerVCDelegate public --- Source/YPImagePicker.swift | 4 ++-- Source/YPPickerVC.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/YPImagePicker.swift b/Source/YPImagePicker.swift index 3176e7b7..81623b9d 100644 --- a/Source/YPImagePicker.swift +++ b/Source/YPImagePicker.swift @@ -187,11 +187,11 @@ open class YPImagePicker: UINavigationController { } extension YPImagePicker: YPPickerVCDelegate { - func libraryHasNoItems() { + public func libraryHasNoItems() { self.imagePickerDelegate?.imagePickerHasNoItemsInLibrary(self) } - func shouldAddToSelection(indexPath: IndexPath, numSelections: Int) -> Bool { + public func shouldAddToSelection(indexPath: IndexPath, numSelections: Int) -> Bool { return self.imagePickerDelegate?.shouldAddToSelection(indexPath: indexPath, numSelections: numSelections) ?? true } diff --git a/Source/YPPickerVC.swift b/Source/YPPickerVC.swift index 23951bcc..01deab97 100644 --- a/Source/YPPickerVC.swift +++ b/Source/YPPickerVC.swift @@ -10,7 +10,7 @@ import UIKit import Stevia import Photos -protocol YPPickerVCDelegate: AnyObject { +public protocol YPPickerVCDelegate: AnyObject { func libraryHasNoItems() func shouldAddToSelection(indexPath: IndexPath, numSelections: Int) -> Bool } @@ -26,7 +26,7 @@ open class YPPickerVC: YPBottomPager, YPBottomPagerDelegate { let albumsManager = YPAlbumsManager() var shouldHideStatusBar = false var initialStatusBarHidden = false - weak var pickerVCDelegate: YPPickerVCDelegate? + public weak var pickerVCDelegate: YPPickerVCDelegate? override open var prefersStatusBarHidden: Bool { return (shouldHideStatusBar || initialStatusBarHidden) && YPConfig.hidesStatusBar