From adb12c594b44be23a5bebb633b5c7de238857aa0 Mon Sep 17 00:00:00 2001 From: Nirali Shah Date: Mon, 30 Jan 2023 15:28:16 +0530 Subject: [PATCH] stop spinner if photo permission not given --- .../Permissions/YPPermissionCheckable.swift | 10 +++++----- Source/Pages/Gallery/YPLibraryVC.swift | 16 ++++++++++------ Source/YPPickerVC.swift | 8 ++++++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/Helpers/Permissions/YPPermissionCheckable.swift b/Source/Helpers/Permissions/YPPermissionCheckable.swift index fb433a2c5..6f83247af 100644 --- a/Source/Helpers/Permissions/YPPermissionCheckable.swift +++ b/Source/Helpers/Permissions/YPPermissionCheckable.swift @@ -9,20 +9,20 @@ import UIKit internal protocol YPPermissionCheckable { - func doAfterLibraryPermissionCheck(block: @escaping () -> Void) + func doAfterLibraryPermissionCheck(block: @escaping (Bool) -> 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 (Bool) -> Void) { YPPermissionManager.checkLibraryPermissionAndAskIfNeeded(sourceVC: self) { hasPermission in - if hasPermission { - block() - } else { + if !hasPermission { ypLog("Not enough permissions.") } + block(hasPermission) + } } diff --git a/Source/Pages/Gallery/YPLibraryVC.swift b/Source/Pages/Gallery/YPLibraryVC.swift index 2776e79f9..64ee6f41a 100644 --- a/Source/Pages/Gallery/YPLibraryVC.swift +++ b/Source/Pages/Gallery/YPLibraryVC.swift @@ -157,8 +157,10 @@ internal final class YPLibraryVC: UIViewController, YPPermissionCheckable { @objc func squareCropButtonTapped() { - doAfterLibraryPermissionCheck { [weak self] in - self?.v.assetViewContainer.squareCropButtonTapped() + doAfterLibraryPermissionCheck { hasPermission in + if hasPermission { + self.v.assetViewContainer.squareCropButtonTapped() + } } } @@ -194,11 +196,13 @@ internal final class YPLibraryVC: UIViewController, YPPermissionCheckable { return } - doAfterLibraryPermissionCheck { [weak self] in - if self?.isMultipleSelectionEnabled == false { - self?.selectedItems.removeAll() + doAfterLibraryPermissionCheck { hasPermission in + if hasPermission { + if self.isMultipleSelectionEnabled == false { + self.selectedItems.removeAll() + } + self.toggleMultipleSelection() } - self?.toggleMultipleSelection() } } diff --git a/Source/YPPickerVC.swift b/Source/YPPickerVC.swift index d1747e730..b67e70c8e 100644 --- a/Source/YPPickerVC.swift +++ b/Source/YPPickerVC.swift @@ -166,8 +166,12 @@ open class YPPickerVC: YPBottomPager, YPBottomPagerDelegate { // Re-trigger permission check if let vc = vc as? YPLibraryVC { - vc.doAfterLibraryPermissionCheck { [weak vc] in - vc?.initialize() + vc.doAfterLibraryPermissionCheck { hasPermission in + if hasPermission { + vc.initialize() + } else { + vc.v.stopSpinner() + } } } else if let cameraVC = vc as? YPCameraVC { cameraVC.start()