Present lock view only if needed for an action

* Do not present lock view in 'viewDidLoad' since this might be too early for an extension ("Not running foreground").
* Instead, show it for actions requiring authentication, e.g. showing the password list or providing a password, or only in 'viewDidAppear'.
* Refactor and lazily load other view controllers and data.
* Let credential providing view controllers decide when to hide themselves.
This commit is contained in:
Danny Moesch 2021-08-27 23:34:30 +02:00 committed by Mingshen Sun
parent 942f462db8
commit bc2d9aa8e8
4 changed files with 67 additions and 51 deletions

View file

@ -19,15 +19,12 @@ class PasscodeExtensionDisplay {
}
// present the passcode lock view if passcode is set and the view controller is not presented
func presentPasscodeLockIfNeeded(_ extensionVC: UIViewController) {
extensionVC.view.isHidden = true
guard PasscodeLock.shared.hasPasscode else {
extensionVC.view.isHidden = false
return
}
passcodeLockVC.modalPresentationStyle = .fullScreen
extensionVC.parent?.present(passcodeLockVC, animated: false) {
extensionVC.view.isHidden = false
func presentPasscodeLockIfNeeded(_ sender: UIViewController, before: (() -> Void)? = nil, after: (() -> Void)? = nil) {
if PasscodeLock.shared.hasPasscode {
before?()
passcodeLockVC.successCallback = after
passcodeLockVC.modalPresentationStyle = .fullScreen
sender.parent?.present(passcodeLockVC, animated: false)
}
}
}