Skip to content

Commit

Permalink
Merge pull request #20 from niralishaha25/dev
Browse files Browse the repository at this point in the history
stop spinner if photo permission not given
  • Loading branch information
niralishaha25 authored Jan 30, 2023
2 parents 8634b0e + adb12c5 commit 3c0f2b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Source/Helpers/Permissions/YPPermissionCheckable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
}

Expand Down
16 changes: 10 additions & 6 deletions Source/Pages/Gallery/YPLibraryVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down Expand Up @@ -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()
}
}

Expand Down
8 changes: 6 additions & 2 deletions Source/YPPickerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3c0f2b9

Please sign in to comment.