Skip to content

Commit

Permalink
Update to 2.6 version
Browse files Browse the repository at this point in the history
- New func `didDenied` in `SPPermissionDialogDelegate`
- Rename `dragToDiscard` to `dragEnabled`
- Close dialog if tap around view

If `dragEnabled` set to `false`, auto added gester for close dialog if tap around and close button. For disable need ovveride parametrs
  • Loading branch information
ivanvorobei committed Jan 12, 2019
1 parent 43ad3c8 commit 686b5ec
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 143 deletions.
238 changes: 119 additions & 119 deletions Example/request-permission.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import UIKit

extension ViewController: SPPermissionDialogDataSource {

var dragToDiscard: Bool {
var dragToDismiss: Bool {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ extension ViewController: SPPermissionDialogDelegate {
func didAllow(permission: SPPermissionType) {
print("SPPermissionDialogDelegate - didAllow \(permission.name)")
}

func didDenied(permission: SPPermissionType) {
print("SPPermissionDialogDelegate - didDenied \(permission.name)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class SPPermissionDialogController: UIViewController {
}
}
} else {
self.delegate?.didDenied?(permission: permission)
let alertController = UIAlertController.init(
title: self.dataSource?.deniedTitle?(for: permission) ?? "Permission denied",
message: self.dataSource?.deniedSubtitle?(for: permission) ?? "Please, go to Settings and allow permissions",
Expand Down Expand Up @@ -179,8 +180,14 @@ public class SPPermissionDialogController: UIViewController {
SPPermissionStyle.Delay.wait(0.2, closure: {
SPPermissionStyle.Animation.base(0.3, animations: {
self.bottomLabel.alpha = 1
if self.dataSource?.showCloseButton ?? false {
self.closeButton.alpha = 1
if let showCloseButton = self.dataSource?.showCloseButton {
if showCloseButton {
self.closeButton.alpha = 1
}
} else {
if !(self.dataSource?.dragEnabled ?? true) {
self.closeButton.alpha = 1
}
}
})
})
Expand Down Expand Up @@ -228,17 +235,19 @@ public class SPPermissionDialogController: UIViewController {
}

private func setupPanGesture() {
if let dragToDiscard = self.dataSource?.dragToDiscard,
!dragToDiscard {
return
if (self.dataSource?.dragEnabled ?? true) {
let panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(self.handleGesture(sender:)))
panGesture.maximumNumberOfTouches = 1
self.areaView.addGestureRecognizer(panGesture)
} else {
let tapGester = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
tapGester.cancelsTouchesInView = false
self.view.addGestureRecognizer(tapGester)
}
let panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(self.handleGesture(sender:)))
panGesture.maximumNumberOfTouches = 1
self.areaView.addGestureRecognizer(panGesture)
}

private func updateLayout(with size: CGSize) {
animator.removeAllBehaviors()
self.animator.removeAllBehaviors()

self.closeButton.frame = CGRect.init(x: 0, y: 0, width: 35, height: 35)
self.closeButton.frame.origin.x = size.width - 27 - self.closeButton.frame.width
Expand Down Expand Up @@ -327,6 +336,10 @@ public class SPPermissionDialogController: UIViewController {
}
}

@objc func handleTap() {
self.hide(withDialog: true)
}

//MARK: - other
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension SPPermission {

@objc optional func didHide()
@objc optional func didAllow(permission: SPPermissionType)
@objc optional func didDenied(permission: SPPermissionType)
}

@objc public protocol SPPermissionDialogDataSource: class {
Expand All @@ -52,7 +53,7 @@ extension SPPermission {
@objc optional var allowedTitle: String { get }
@objc optional var bottomComment: String { get }
@objc optional var showCloseButton: Bool { get }
@objc optional var dragToDiscard: Bool { get }
@objc optional var dragEnabled: Bool { get }
@objc optional func name(for permission: SPPermissionType) -> String?
@objc optional func description(for permission: SPPermissionType) -> String?
@objc optional func image(for permission: SPPermissionType) -> UIImage?
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ To track events of hiding & allowing permissions associated with `SPPermission`,

@objc optional func didHide()
@objc optional func didAllow(permission: SPPermissionType)
@objc optional func didDenied(permission: SPPermissionType)
}
```

Expand All @@ -98,7 +99,7 @@ If you want to change the text, you need to implement `SPPermissionDialogDataSou
@objc optional var allowedTitle: String { get }
@objc optional var bottomComment: String { get }
@objc optional var showCloseButton: Bool { get }
@objc optional var dragToDiscard: Bool { get }
@objc optional var dragEnabled: Bool { get }
@objc optional func name(for permission: SPPermissionType) -> String?
@objc optional func description(for permission: SPPermissionType) -> String?
@objc optional func image(for permission: SPPermissionType) -> UIImage?
Expand All @@ -120,7 +121,7 @@ SPPermission.Dialog.request(
)
```

If you want to inhibite drap gesture to discard the dialog view you need to override `dragToDiscard` parameter, and if you want to add or remove the close button (without the button you’ll have to swipe the dialog to close it), you need to override parameter `showCloseButton`. To see what it looks like, see the picture below:
If you want to inhibite drag gesture to discard the dialog view you need to override `dragEnabled` parameter, and if you want to add or remove the close button (without the button you’ll have to swipe the dialog to close it), you need to override parameter `showCloseButton`. To see what it looks like, see the picture below:

<img src="https://rawcdn.githack.com/IvanVorobei/RequestPermission/b3e613295b73be36c8a3d35126d1f7015ef432a8/resources/request-permission - close button.png"/>

Expand Down
2 changes: 1 addition & 1 deletion SPPermission.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SPPermission"
s.version = "2.4.8"
s.version = "2.6"
s.summary = "Simple request permissions with dialog alert"
s.homepage = "https://github.com/IvanVorobei/RequestPermission"
s.source = { :git => "https://github.com/IvanVorobei/RequestPermission.git", :tag => s.version }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class SPPermissionDialogController: UIViewController {
}
}
} else {
self.delegate?.didDenied?(permission: permission)
let alertController = UIAlertController.init(
title: self.dataSource?.deniedTitle?(for: permission) ?? "Permission denied",
message: self.dataSource?.deniedSubtitle?(for: permission) ?? "Please, go to Settings and allow permissions",
Expand Down Expand Up @@ -179,8 +180,14 @@ public class SPPermissionDialogController: UIViewController {
SPPermissionStyle.Delay.wait(0.2, closure: {
SPPermissionStyle.Animation.base(0.3, animations: {
self.bottomLabel.alpha = 1
if self.dataSource?.showCloseButton ?? false {
self.closeButton.alpha = 1
if let showCloseButton = self.dataSource?.showCloseButton {
if showCloseButton {
self.closeButton.alpha = 1
}
} else {
if !(self.dataSource?.dragEnabled ?? true) {
self.closeButton.alpha = 1
}
}
})
})
Expand Down Expand Up @@ -228,17 +235,19 @@ public class SPPermissionDialogController: UIViewController {
}

private func setupPanGesture() {
if let dragToDiscard = self.dataSource?.dragToDiscard,
!dragToDiscard {
return
if (self.dataSource?.dragEnabled ?? true) {
let panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(self.handleGesture(sender:)))
panGesture.maximumNumberOfTouches = 1
self.areaView.addGestureRecognizer(panGesture)
} else {
let tapGester = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap))
tapGester.cancelsTouchesInView = false
self.view.addGestureRecognizer(tapGester)
}
let panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(self.handleGesture(sender:)))
panGesture.maximumNumberOfTouches = 1
self.areaView.addGestureRecognizer(panGesture)
}

private func updateLayout(with size: CGSize) {
animator.removeAllBehaviors()
self.animator.removeAllBehaviors()

self.closeButton.frame = CGRect.init(x: 0, y: 0, width: 35, height: 35)
self.closeButton.frame.origin.x = size.width - 27 - self.closeButton.frame.width
Expand Down Expand Up @@ -327,6 +336,10 @@ public class SPPermissionDialogController: UIViewController {
}
}

@objc func handleTap() {
self.hide(withDialog: true)
}

//MARK: - other
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down
3 changes: 2 additions & 1 deletion Source/SPPermission/Dialog/SPPermissionDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension SPPermission {

@objc optional func didHide()
@objc optional func didAllow(permission: SPPermissionType)
@objc optional func didDenied(permission: SPPermissionType)
}

@objc public protocol SPPermissionDialogDataSource: class {
Expand All @@ -52,7 +53,7 @@ extension SPPermission {
@objc optional var allowedTitle: String { get }
@objc optional var bottomComment: String { get }
@objc optional var showCloseButton: Bool { get }
@objc optional var dragToDiscard: Bool { get }
@objc optional var dragEnabled: Bool { get }
@objc optional func name(for permission: SPPermissionType) -> String?
@objc optional func description(for permission: SPPermissionType) -> String?
@objc optional func image(for permission: SPPermissionType) -> UIImage?
Expand Down

0 comments on commit 686b5ec

Please sign in to comment.