Skip to content

Commit

Permalink
Update to 2.1.2
Browse files Browse the repository at this point in the history
Added customize icon for permission
  • Loading branch information
ivanvorobei committed Nov 20, 2018
1 parent 3a77b8d commit fdd73e4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion SPPermission.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SPPermission"
s.version = "2.1.1"
s.version = "2.1.2"
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
Binary file not shown.
Expand Up @@ -100,4 +100,8 @@ extension ViewController: SPPermissionDialogDataSource {
return "App will can check your location"
}
}

func image(for permission: SPPermissionType) -> UIImage? {
return nil // default icon
}
}
1 change: 1 addition & 0 deletions source/sparrow/permission/dialog/SPPermissionDialog.swift
Expand Up @@ -58,4 +58,5 @@ extension SPPermission {
@objc optional var showCloseButton: 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 Up @@ -66,7 +66,8 @@ public class SPPermissionDialogController: SPBaseViewController {
title: (self.dataSource?.name?(for: permission) ?? permission.name),
subtitle: (self.dataSource?.description?(for: permission) ?? self.description(for: permission)),
allowTitle: self.dataSource?.allowTitle ?? "Allow",
allowedTitle: self.dataSource?.allowedTitle ?? "Allowed"
allowedTitle: self.dataSource?.allowedTitle ?? "Allowed",
image: self.dataSource?.image?(for: permission)
)
view.button.addTarget(self, action: #selector(self.request(with:)), for: .touchUpInside)
self.areaView.add(view: view)
Expand Down
63 changes: 39 additions & 24 deletions source/sparrow/permission/dialog/SPPermissionDialogView.swift
Expand Up @@ -144,45 +144,56 @@ class SPPermissionDialogLineView: UIView {
let titleLabel = UILabel()
let subtitleLabel = UILabel()
var iconView: SPGolubevIconView = SPGolubevIconView.init()
var imageView = UIImageView()
var button = SPAppStoreActionButton()
var separatorView = UIView()

var permission: SPPermissionType
private var allowTitle: String
private var allowedTitle: String

init(permission: SPPermissionType, title: String, subtitle: String, allowTitle: String, allowedTitle: String) {
init(permission: SPPermissionType, title: String, subtitle: String, allowTitle: String, allowedTitle: String, image: UIImage? = nil) {
self.permission = permission
self.allowTitle = allowTitle
self.allowedTitle = allowedTitle
super.init(frame: .zero)
self.titleLabel.text = title
self.subtitleLabel.text = subtitle

switch permission {
case .calendar:
self.iconView.type = .calendar
case .camera:
self.iconView.type = .camera
case .contacts:
self.iconView.type = .book
case .microphone:
self.iconView.type = .micro
case .notification:
self.iconView.type = .ball
case .photoLibrary:
self.iconView.type = .photoLibrary
case .reminders:
self.iconView.type = .calendar
case .speech:
self.iconView.type = .micro
case .locationWhenInUse:
self.iconView.type = .compass
case .locationAlways:
self.iconView.type = .compass
case .locationWithBackground:
self.iconView.type = .compass
self.imageView.isHidden = true

if let image = image {
self.imageView.contentMode = .scaleAspectFit
self.imageView.image = image
self.iconView.isHidden = true
self.imageView.isHidden = false
} else {
switch permission {
case .calendar:
self.iconView.type = .calendar
case .camera:
self.iconView.type = .camera
case .contacts:
self.iconView.type = .book
case .microphone:
self.iconView.type = .micro
case .notification:
self.iconView.type = .ball
case .photoLibrary:
self.iconView.type = .photoLibrary
case .reminders:
self.iconView.type = .calendar
case .speech:
self.iconView.type = .micro
case .locationWhenInUse:
self.iconView.type = .compass
case .locationAlways:
self.iconView.type = .compass
case .locationWithBackground:
self.iconView.type = .compass
}
}

self.commonInit()
}

Expand All @@ -196,6 +207,8 @@ class SPPermissionDialogLineView: UIView {

private func commonInit() {
self.backgroundColor = SPNativeStyleKit.Colors.white

self.addSubview(self.imageView)
self.addSubview(self.iconView)

self.titleLabel.numberOfLines = 1
Expand Down Expand Up @@ -240,6 +253,8 @@ class SPPermissionDialogLineView: UIView {
self.iconView.frame = CGRect.init(x: 0, y: 0, width: 45, height: 45)
self.iconView.center.y = self.frame.height / 2

self.imageView.frame = self.iconView.frame

self.button.sizeToFit()
self.button.frame.bottomXPosition = self.frame.width
self.button.center.y = self.frame.height / 2
Expand Down

0 comments on commit fdd73e4

Please sign in to comment.