From d42a74118c30cb7ae060d2d3897680529a2b1e2c Mon Sep 17 00:00:00 2001 From: Michael Scoff Date: Sat, 7 Oct 2017 01:57:23 -0700 Subject: [PATCH] Add SplashViewController --- .../SplashViewController.swift | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Trust/Authentication/ViewControllers/SplashViewController.swift diff --git a/Trust/Authentication/ViewControllers/SplashViewController.swift b/Trust/Authentication/ViewControllers/SplashViewController.swift new file mode 100644 index 000000000..2b78a40bc --- /dev/null +++ b/Trust/Authentication/ViewControllers/SplashViewController.swift @@ -0,0 +1,96 @@ +// Copyright SIX DAY LLC. All rights reserved. + +import UIKit +import VENTouchLock + +class SplashViewController: VENTouchLockSplashViewController { + + let label = UILabel() + + override func viewDidLoad() { + super.viewDidLoad() + + view.backgroundColor = .white + + label.translatesAutoresizingMaskIntoConstraints = false + label.numberOfLines = 0 + label.textAlignment = .center + + view.addSubview(label) + + let logoImageView = UIImageView(image: R.image.launch_screen_logo()) + logoImageView.translatesAutoresizingMaskIntoConstraints = false + + view.addSubview(logoImageView) + + NSLayoutConstraint.activate([ + logoImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + logoImageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), + label.topAnchor.constraint(equalTo: logoImageView.bottomAnchor, constant: 40), + label.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor), + label.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor), + ]) + } + + override func dismiss(withUnlockSuccess success: Bool, unlockType: VENTouchLockSplashViewControllerUnlockType, animated: Bool) { + switch unlockType { + case .passcode, .touchID: + super.dismiss(withUnlockSuccess: success, unlockType: unlockType, animated: animated) + case .none: + transition(to: .error(.numberOfTries)) + dismiss(animated: false, completion: nil) + } + } + + override func showUnlock(animated: Bool) { + + NSLog("showUnlock \(VENTouchLock.canUseTouchID())") + + NSLog("shouldUseTouchID \(VENTouchLock.shouldUseTouchID())") + + transition(to: .new) + if VENTouchLock.shouldUseTouchID() { + showTouchID() + } else { + showPasscode(animated: animated) + } + } + + override func showTouchID() { + + touchLock.requestTouchID(completion: { response in + switch response { + case .success: + self.dismiss(withUnlockSuccess: true, unlockType: .touchID, animated: false) + case .usePasscode, .canceled, .promptAlreadyPresent: + self.showPasscode(animated: false) + case .undefined: + self.showTouchID() + } + }) + } + + override func showPasscode(animated: Bool) { + let controller = VENTouchLockEnterPasscodeViewController() + controller.willFinishWithResult = { result in + if result { + self.dismiss(withUnlockSuccess: true, unlockType: .passcode, animated: false) + } + } + present(controller, animated: animated, completion: nil) + } + + func transition(to state: SplashState) { + switch state { + case .new: + label.text = "" + case .error(let error): + label.text = error.errorDescription + } + } + + override func setIsSnapshot(_ isSnapshotViewController: Bool) { + transition(to: .new) + return super.setIsSnapshot(isSnapshotViewController) + } +}