Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge @yankodimitrov main repo PRs #29

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PasscodeLock/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import Foundation
func localizedStringFor(key: String, comment: String) -> String {

let name = "PasscodeLock"
let bundle = bundleForResource(name, ofType: "strings")
let defaultString = NSLocalizedString(key, tableName: name, bundle: NSBundle(forClass: PasscodeLock.self), comment: comment)

return NSLocalizedString(key, tableName: name, bundle: bundle, comment: comment)
return NSLocalizedString(key, value: defaultString, tableName: name, bundle: NSBundle.mainBundle(), comment: comment)
}

func bundleForResource(name: String, ofType type: String) -> NSBundle {
Expand Down
42 changes: 24 additions & 18 deletions PasscodeLock/PasscodeLockPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,34 @@ public class PasscodeLockPresenter {
mainWindow?.makeKeyAndVisible()

if animated {
UIView.animateWithDuration(
0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: [.CurveEaseInOut],
animations: { [weak self] in

self?.passcodeLockWindow.alpha = 0
},
completion: { [weak self] _ in

self?.passcodeLockWindow.windowLevel = 0
self?.passcodeLockWindow.rootViewController = nil
self?.passcodeLockWindow.alpha = 1
self?.toggleKeyboardVisibility(hide: false)
}
)

animatePasscodeLockDismissal()

} else {
passcodeLockWindow.windowLevel = 0
passcodeLockWindow.rootViewController = nil
toggleKeyboardVisibility(hide: false)
}
}

internal func animatePasscodeLockDismissal() {
UIView.animateWithDuration(
0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: [.CurveEaseInOut],
animations: { [weak self] in

self?.passcodeLockWindow.alpha = 0
},
completion: { [weak self] _ in

self?.passcodeLockWindow.windowLevel = 0
self?.passcodeLockWindow.rootViewController = nil
self?.passcodeLockWindow.alpha = 1
self?.toggleKeyboardVisibility(hide: false)
}
)
}
}
6 changes: 4 additions & 2 deletions PasscodeLock/PasscodeLockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg
public override func viewDidLoad() {
super.viewDidLoad()

cancelButton?.setTitle(localizedStringFor("PasscodeLockCancelButtonTitle", comment: "Cancel Button Title"), forState: .Normal)
deleteSignButton?.setTitle(localizedStringFor("PasscodeLockDeleteButtonTitle", comment: "Delete Button Title"), forState: .Normal)
deleteSignButton?.enabled = false

setupEvents()
Expand Down Expand Up @@ -114,8 +116,8 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg

private func setupEvents() {

notificationCenter?.addObserver(self, selector: "appWillEnterForegroundHandler:", name: UIApplicationWillEnterForegroundNotification, object: nil)
notificationCenter?.addObserver(self, selector: "appDidEnterBackgroundHandler:", name: UIApplicationDidEnterBackgroundNotification, object: nil)
notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appWillEnterForegroundHandler(_:)), name: UIApplicationWillEnterForegroundNotification, object: nil)
notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appDidEnterBackgroundHandler(_:)), name: UIApplicationDidEnterBackgroundNotification, object: nil)
}

private func clearEvents() {
Expand Down
6 changes: 3 additions & 3 deletions PasscodeLock/Views/PasscodeSignButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class PasscodeSignButton: UIButton {
return CGSizeMake(60, 60)
}

private var defaultBackgroundColor = UIColor.clearColor()
public var defaultBackgroundColor = UIColor.clearColor()

private func setupView() {

Expand All @@ -71,8 +71,8 @@ public class PasscodeSignButton: UIButton {

private func setupActions() {

addTarget(self, action: Selector("handleTouchDown"), forControlEvents: .TouchDown)
addTarget(self, action: Selector("handleTouchUp"), forControlEvents: [.TouchUpInside, .TouchDragOutside, .TouchCancel])
addTarget(self, action: #selector(PasscodeSignButton.handleTouchDown), forControlEvents: .TouchDown)
addTarget(self, action: #selector(PasscodeSignButton.handleTouchUp), forControlEvents: [.TouchUpInside, .TouchDragOutside, .TouchCancel])
}

func handleTouchDown() {
Expand Down
6 changes: 6 additions & 0 deletions PasscodeLock/en.lproj/PasscodeLock.strings
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"PasscodeLockMismatchTitle" = "Try again";
"PasscodeLockMismatchDescription" = "Passcodes didn\'t match.";

/* Cancel Button Title */
"PasscodeLockCancelButtonTitle" = "Cancel";

/* Delete Button Title */
"PasscodeLockDeleteButtonTitle" = "Delete";

/* Touch ID Reason */
"PasscodeLockTouchIDReason" = "Authentication required to proceed";

Expand Down
3 changes: 2 additions & 1 deletion PasscodeLockDemo/PasscodeSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class PasscodeSettingsViewController: UIViewController {
passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration)

passcodeVC.successCallback = { lock in

self.passcodeSwitch.on = !self.passcodeSwitch.on
self.changePasscodeButton.hidden = true
lock.repository.deletePasscode()
}
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Also you can set the initial passcode lock state to your own implementation of t

### Custom Design

The PasscodeLock will look for `PasscodeLockView.xib` inside your app bundle and if it can't find it will load its default one, so if you want to have a custom design create a new `xib` with the name `PasscodeLockView` and set its owner to an instance of `PasscodeLockViewController` class.
The PasscodeLock will look for `PasscodeLockView.xib` inside your app bundle and if it can't find it will load its default one, so if you want to have a custom design create a new `xib` with the name `PasscodeLockView` and set its owner to an instance of `PasscodeLockViewController` class and module to `PasscodeLock`.

Then connect the `view` outlet to the view of your `xib` file and make sure to conenct the remaining `IBOutlet`s and `IBAction`s.
Then connect the `view` outlet to the view of your `xib` file and make sure to connect the remaining `IBOutlet`s and `IBAction`s. Also make sure to set module to `PasscodeLock` on all `PasscodeSignPlaceholderView` and `PasscodeSignButton` in the nib.

PasscodeLock comes with two view components: `PasscodeSignPlaceholderView` and `PasscodeSignButton` that you can use to create your own custom designs. Both classes are `@IBDesignable` and `@IBInspectable`, so you can see their appearance and change their properties right inside the interface builder:

Expand Down