From 2e2fc91cc28d4bf1c4e5fdd67f8d00bf6eca7b18 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 4 Nov 2019 19:44:25 +0400 Subject: [PATCH] Fix passcode layout --- .buckconfig | 1 + .../Sources/PasscodeEntryController.swift | 10 +++- .../Sources/PasscodeEntryControllerNode.swift | 7 ++- .../PasscodeUI/Sources/PasscodeLayout.swift | 57 ++++++++++++------- .../PasscodeOptionsController.swift | 8 ++- .../TelegramUI/ShareExtensionContext.swift | 13 ++++- 6 files changed, 68 insertions(+), 28 deletions(-) diff --git a/.buckconfig b/.buckconfig index 36f4b583bd..bfe54b4d99 100644 --- a/.buckconfig +++ b/.buckconfig @@ -17,6 +17,7 @@ generate_missing_umbrella_headers = true iphonesimulator_target_sdk_version = 9.0 iphoneos_target_sdk_version = 9.0 + watchos_target_sdk_version = 5.0 provisioning_profile_read_command = security cms -Di xctool_default_destination_specifier = platform=iOS Simulator,OS=latest xctool_path = tools/xctool/bin/xctool diff --git a/submodules/PasscodeUI/Sources/PasscodeEntryController.swift b/submodules/PasscodeUI/Sources/PasscodeEntryController.swift index e6f5a5062e..ad96c44ada 100644 --- a/submodules/PasscodeUI/Sources/PasscodeEntryController.swift +++ b/submodules/PasscodeUI/Sources/PasscodeEntryController.swift @@ -15,12 +15,14 @@ public final class PasscodeEntryControllerPresentationArguments { let fadeIn: Bool let lockIconInitialFrame: () -> CGRect let cancel: (() -> Void)? + let modalPresentation: Bool - public init(animated: Bool = true, fadeIn: Bool = false, lockIconInitialFrame: @escaping () -> CGRect = { return CGRect() }, cancel: (() -> Void)? = nil) { + public init(animated: Bool = true, fadeIn: Bool = false, lockIconInitialFrame: @escaping () -> CGRect = { return CGRect() }, cancel: (() -> Void)? = nil, modalPresentation: Bool = false) { self.animated = animated self.fadeIn = fadeIn self.lockIconInitialFrame = lockIconInitialFrame self.cancel = cancel + self.modalPresentation = modalPresentation } } @@ -111,18 +113,22 @@ public final class PasscodeEntryController: ViewController { let biometricsType: LocalAuthBiometricAuthentication? if case let .enabled(data) = self.biometrics { if #available(iOSApplicationExtension 9.0, iOS 9.0, *) { + #if targetEnvironment(simulator) + biometricsType = .touchId + #else if data == LocalAuth.evaluatedPolicyDomainState || (data == nil && !self.applicationBindings.isMainApp) { biometricsType = LocalAuth.biometricAuthentication } else { biometricsType = nil } + #endif } else { biometricsType = LocalAuth.biometricAuthentication } } else { biometricsType = nil } - self.displayNode = PasscodeEntryControllerNode(accountManager: self.accountManager, theme: self.presentationData.theme, strings: self.presentationData.strings, wallpaper: self.presentationData.chatWallpaper, passcodeType: passcodeType, biometricsType: biometricsType, arguments: self.arguments, statusBar: self.statusBar) + self.displayNode = PasscodeEntryControllerNode(accountManager: self.accountManager, theme: self.presentationData.theme, strings: self.presentationData.strings, wallpaper: self.presentationData.chatWallpaper, passcodeType: passcodeType, biometricsType: biometricsType, arguments: self.arguments, statusBar: self.statusBar, modalPresentation: self.arguments.modalPresentation) self.displayNodeDidLoad() let _ = (self.appLockContext.invalidAttempts diff --git a/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift b/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift index 3503cbac78..5927a1bd54 100644 --- a/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift +++ b/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift @@ -29,6 +29,8 @@ final class PasscodeEntryControllerNode: ASDisplayNode { private let statusBar: StatusBar + private let modalPresentation: Bool + private let backgroundNode: ASImageNode private let iconNode: PasscodeLockIconNode private let titleNode: PasscodeEntryLabelNode @@ -50,7 +52,7 @@ final class PasscodeEntryControllerNode: ASDisplayNode { var checkPasscode: ((String) -> Void)? var requestBiometrics: (() -> Void)? - init(accountManager: AccountManager, theme: PresentationTheme, strings: PresentationStrings, wallpaper: TelegramWallpaper, passcodeType: PasscodeEntryFieldType, biometricsType: LocalAuthBiometricAuthentication?, arguments: PasscodeEntryControllerPresentationArguments, statusBar: StatusBar) { + init(accountManager: AccountManager, theme: PresentationTheme, strings: PresentationStrings, wallpaper: TelegramWallpaper, passcodeType: PasscodeEntryFieldType, biometricsType: LocalAuthBiometricAuthentication?, arguments: PasscodeEntryControllerPresentationArguments, statusBar: StatusBar, modalPresentation: Bool) { self.accountManager = accountManager self.theme = theme self.strings = strings @@ -59,6 +61,7 @@ final class PasscodeEntryControllerNode: ASDisplayNode { self.biometricsType = biometricsType self.arguments = arguments self.statusBar = statusBar + self.modalPresentation = modalPresentation self.backgroundNode = ASImageNode() self.backgroundNode.contentMode = .scaleToFill @@ -373,7 +376,7 @@ final class PasscodeEntryControllerNode: ASDisplayNode { self.iconNode.alpha = 0.0 } - let passcodeLayout = PasscodeLayout(layout: layout) + let passcodeLayout = PasscodeLayout(layout: layout, modalPresentation: self.modalPresentation) let inputFieldOffset: CGFloat if isLandscape { let bottomInset = layout.inputHeight ?? 0.0 diff --git a/submodules/PasscodeUI/Sources/PasscodeLayout.swift b/submodules/PasscodeUI/Sources/PasscodeLayout.swift index d9ea84cebe..1a104d88fa 100644 --- a/submodules/PasscodeUI/Sources/PasscodeLayout.swift +++ b/submodules/PasscodeUI/Sources/PasscodeLayout.swift @@ -3,18 +3,23 @@ import UIKit import Display struct PasscodeKeyboardLayout { - let buttonSize: CGFloat - let horizontalSecond: CGFloat - let horizontalThird: CGFloat - let verticalSecond: CGFloat - let verticalThird: CGFloat - let verticalFourth: CGFloat - let size: CGSize - let topOffset: CGFloat - let biometricsOffset: CGFloat - let deleteOffset: CGFloat + var buttonSize: CGFloat + var horizontalSecond: CGFloat + var horizontalThird: CGFloat + var verticalSecond: CGFloat + var verticalThird: CGFloat + var verticalFourth: CGFloat + var size: CGSize + var topOffset: CGFloat + var biometricsOffset: CGFloat + var deleteOffset: CGFloat - fileprivate init(layout: ContainerViewLayout) { + fileprivate init(layout: ContainerViewLayout, modalPresentation: Bool) { + var modalOffset: CGFloat = 0.0 + if modalPresentation { + modalOffset -= 20.0 + } + switch layout.deviceMetrics { case .iPhone4: self.buttonSize = 75.0 @@ -105,20 +110,28 @@ struct PasscodeKeyboardLayout { self.biometricsOffset = 30.0 self.deleteOffset = 20.0 } + + self.topOffset += modalOffset * 2.0 + self.biometricsOffset += modalOffset } } public struct PasscodeLayout { - let layout: ContainerViewLayout - let keyboard: PasscodeKeyboardLayout - let titleOffset: CGFloat - let subtitleOffset: CGFloat - let inputFieldOffset: CGFloat + var layout: ContainerViewLayout + var keyboard: PasscodeKeyboardLayout + var titleOffset: CGFloat + var subtitleOffset: CGFloat + var inputFieldOffset: CGFloat - init(layout: ContainerViewLayout) { + init(layout: ContainerViewLayout, modalPresentation: Bool) { self.layout = layout - self.keyboard = PasscodeKeyboardLayout(layout: layout) + var modalOffset: CGFloat = 0.0 + if modalPresentation { + modalOffset -= 20.0 + } + + self.keyboard = PasscodeKeyboardLayout(layout: layout, modalPresentation: modalPresentation) switch layout.deviceMetrics { case .iPhone4: self.titleOffset = 30.0 @@ -153,11 +166,15 @@ public struct PasscodeLayout { self.subtitleOffset = 0.0 self.inputFieldOffset = 140.0 } + + self.titleOffset += modalOffset + self.subtitleOffset += modalOffset + self.inputFieldOffset += modalOffset } - public init(layout: ContainerViewLayout, titleOffset: CGFloat, subtitleOffset: CGFloat, inputFieldOffset: CGFloat) { + public init(layout: ContainerViewLayout, titleOffset: CGFloat, subtitleOffset: CGFloat, inputFieldOffset: CGFloat, modalPresentation: Bool) { self.layout = layout - self.keyboard = PasscodeKeyboardLayout(layout: layout) + self.keyboard = PasscodeKeyboardLayout(layout: layout, modalPresentation: modalPresentation) self.titleOffset = titleOffset self.subtitleOffset = subtitleOffset self.inputFieldOffset = inputFieldOffset diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift index 336599c918..3b4c1fe359 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift @@ -441,7 +441,7 @@ public func passcodeOptionsAccessController(context: AccountContext, animateIn: } } -public func passcodeEntryController(context: AccountContext, animateIn: Bool = true, completion: @escaping (Bool) -> Void) -> Signal { +public func passcodeEntryController(context: AccountContext, animateIn: Bool = true, modalPresentation: Bool = false, completion: @escaping (Bool) -> Void) -> Signal { return context.sharedContext.accountManager.transaction { transaction -> PostboxAccessChallengeData in return transaction.getAccessChallengeData() } @@ -458,14 +458,18 @@ public func passcodeEntryController(context: AccountContext, animateIn: Bool = t return nil } else { let biometrics: PasscodeEntryControllerBiometricsMode + #if targetEnvironment(simulator) + biometrics = .enabled(nil) + #else if let passcodeSettings = passcodeSettings, passcodeSettings.enableBiometrics { biometrics = .enabled(context.sharedContext.applicationBindings.isMainApp ? passcodeSettings.biometricsDomainState : passcodeSettings.shareBiometricsDomainState) } else { biometrics = .none } + #endif let controller = PasscodeEntryController(applicationBindings: context.sharedContext.applicationBindings, accountManager: context.sharedContext.accountManager, appLockContext: context.sharedContext.appLockContext, presentationData: context.sharedContext.currentPresentationData.with { $0 }, presentationDataSignal: context.sharedContext.presentationData, challengeData: challenge, biometrics: biometrics, arguments: PasscodeEntryControllerPresentationArguments(animated: false, fadeIn: true, cancel: { completion(false) - })) + }, modalPresentation: modalPresentation)) controller.presentationCompleted = { [weak controller] in Queue.mainQueue().after(0.5, { [weak controller] in controller?.requestBiometrics() diff --git a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift index 6304d1cdcd..b9860e4542 100644 --- a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift +++ b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift @@ -122,8 +122,10 @@ public class ShareRootControllerImpl { mainWindow.hostView.eventView.isHidden = false self.mainWindow = mainWindow + let bounds = view.bounds + view.addSubview(mainWindow.hostView.containerView) - mainWindow.hostView.containerView.frame = view.bounds + mainWindow.hostView.containerView.frame = bounds let rootPath = rootPathForBasePath(self.initializationData.appGroupPath) performAppGroupUpgrades(appGroupPath: self.initializationData.appGroupPath, rootPath: rootPath) @@ -340,7 +342,14 @@ public class ShareRootControllerImpl { context.account.resetStateManagement() } - let _ = passcodeEntryController(context: context, animateIn: true, completion: { value in + let modalPresentation: Bool + if #available(iOSApplicationExtension 13.0, iOS 13.0, *) { + modalPresentation = true + } else { + modalPresentation = false + } + + let _ = passcodeEntryController(context: context, animateIn: true, modalPresentation: modalPresentation, completion: { value in if value { displayShare() } else {