Skip to content

Commit 62d29ee

Browse files
author
Isaac
committed
Passkeys
1 parent 2e279e8 commit 62d29ee

File tree

6 files changed

+84
-13
lines changed

6 files changed

+84
-13
lines changed

submodules/AccountContext/Sources/AccountContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ public protocol SharedAccountContext: AnyObject {
14751475
func makeNewContactScreen(context: AccountContext, peer: EnginePeer?, phoneNumber: String?, shareViaException: Bool, completion: @escaping (EnginePeer?, DeviceContactStableId?, DeviceContactExtendedData?) -> Void) -> ViewController
14761476

14771477
func makeLoginEmailSetupController(context: AccountContext, blocking: Bool, emailPattern: String?, canAutoDismissIfNeeded: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: @escaping () -> Void) -> ViewController
1478-
public func makePasskeySetupController(context: AccountContext, displaySkip: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: completion: @escaping () -> Void) -> ViewController
1478+
func makePasskeySetupController(context: AccountContext, displaySkip: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: @escaping () -> Void) -> ViewController
14791479

14801480
func navigateToCurrentCall()
14811481
var hasOngoingCall: ValuePromise<Bool> { get }

submodules/ChatListUI/Sources/ChatListController.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,11 +2604,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
26042604
}, dismiss: {
26052605
let _ = context.engine.notices.dismissServerProvidedSuggestion(suggestion: ServerProvidedSuggestion.setupPasskey.id).startStandalone()
26062606
})
2607-
if let layout = strongSelf.validLayout, layout.metrics.isTablet {
2608-
controller.navigationPresentation = .standaloneFlatModal
2609-
} else {
2610-
controller.navigationPresentation = .flatModal
2611-
}
26122607
navigationController.pushViewController(controller)
26132608
}
26142609
})

submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,9 +1268,9 @@ public func privacyAndSecurityController(
12681268
}, openPasskeys: {
12691269
Task { @MainActor in
12701270
let initialPasskeysData = await (passkeysDataValue.get() |> take(1)).get()
1271-
let passkeysScreen = await PasskeysScreen(context: context, initialPasskeysData: initialPasskeysData, passkeysDataUpdated: { passkeysData in
1271+
let passkeysScreen = PasskeysScreen(context: context, displaySkip: false, initialPasskeysData: initialPasskeysData, passkeysDataUpdated: { passkeysData in
12721272
passkeysDataValue.set(.single(passkeysData))
1273-
})
1273+
}, completion: {}, cancel: {})
12741274
pushControllerImpl?(passkeysScreen, true)
12751275
}
12761276
}, openActiveSessions: {

submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreen.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class PasskeysScreenComponent: Component {
4848
class View: UIView, ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
4949
private var intro: ComponentView<Empty>?
5050
private var list: ComponentView<Empty>?
51+
private var activityIndicator: UIActivityIndicatorView?
5152

5253
private var component: PasskeysScreenComponent?
5354
private var environment: EnvironmentType?
@@ -168,6 +169,8 @@ final class PasskeysScreenComponent: Component {
168169
authController.delegate = self
169170
authController.presentationContextProvider = self
170171
authController.performRequests()
172+
173+
component.completion()
171174
}
172175
}
173176
}
@@ -264,11 +267,19 @@ final class PasskeysScreenComponent: Component {
264267
context: component.context,
265268
theme: environment.theme,
266269
insets: UIEdgeInsets(top: environment.statusBarHeight + environment.navigationHeight, left: 0.0, bottom: environment.safeInsets.bottom, right: 0.0),
270+
displaySkip: component.displaySkip,
267271
createPasskeyAction: { [weak self] in
268272
guard let self else {
269273
return
270274
}
271275
self.createPasskey()
276+
},
277+
skipAction: { [weak self] in
278+
guard let self, let component = self.component else {
279+
return
280+
}
281+
component.cancel()
282+
self.environment?.controller()?.dismiss()
272283
}
273284
)),
274285
environment: {},
@@ -346,6 +357,27 @@ final class PasskeysScreenComponent: Component {
346357
}
347358
}
348359

360+
if self.passkeysData == nil {
361+
let activityIndicator: UIActivityIndicatorView
362+
if let current = self.activityIndicator {
363+
activityIndicator = current
364+
} else {
365+
activityIndicator = UIActivityIndicatorView(style: .large)
366+
self.activityIndicator = activityIndicator
367+
self.addSubview(activityIndicator)
368+
}
369+
activityIndicator.tintColor = environment.theme.list.itemPrimaryTextColor
370+
371+
let indicatorSize = activityIndicator.bounds.size
372+
activityIndicator.frame = CGRect(origin: CGPoint(x: floor((availableSize.width - indicatorSize.width) / 2.0), y: floor((availableSize.height - indicatorSize.height) / 2.0)), size: indicatorSize)
373+
if !activityIndicator.isAnimating {
374+
activityIndicator.startAnimating()
375+
}
376+
} else if let activityIndicator = self.activityIndicator {
377+
self.activityIndicator = nil
378+
activityIndicator.removeFromSuperview()
379+
}
380+
349381
return availableSize
350382
}
351383
}
@@ -362,10 +394,10 @@ final class PasskeysScreenComponent: Component {
362394
public final class PasskeysScreen: ViewControllerComponentContainer {
363395
private let context: AccountContext
364396

365-
public init(context: AccountContext, displaySkip: Bool, initialPasskeysData: [TelegramPasskey]?, passkeysDataUpdated: @escaping ([TelegramPasskey]) -> Void, completion: @escaping () -> Void, cancel: @escaping () -> Void) async {
397+
public init(context: AccountContext, displaySkip: Bool, initialPasskeysData: [TelegramPasskey]?, passkeysDataUpdated: @escaping ([TelegramPasskey]) -> Void, completion: @escaping () -> Void, cancel: @escaping () -> Void) {
366398
self.context = context
367399

368-
super.init(context: context, component: PasskeysScreenComponent(context: context, displaySkip: displaySkip, initialPasskeysData: initialPasskeysData, passkeysDataUpdated: passkeysDataUpdated), navigationBarAppearance: .transparent)
400+
super.init(context: context, component: PasskeysScreenComponent(context: context, displaySkip: displaySkip, initialPasskeysData: initialPasskeysData, passkeysDataUpdated: passkeysDataUpdated, completion: completion, cancel: cancel), navigationBarAppearance: .transparent)
369401
}
370402

371403
required public init(coder aDecoder: NSCoder) {

submodules/TelegramUI/Components/Settings/PasskeysScreen/Sources/PasskeysScreenIntroComponent.swift

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ final class PasskeysScreenIntroComponent: Component {
1616
let insets: UIEdgeInsets
1717
let displaySkip: Bool
1818
let createPasskeyAction: () -> Void
19+
let skipAction: () -> Void
1920

2021
init(
2122
context: AccountContext,
2223
theme: PresentationTheme,
2324
insets: UIEdgeInsets,
2425
displaySkip: Bool,
25-
createPasskeyAction: @escaping () -> Void
26+
createPasskeyAction: @escaping () -> Void,
27+
skipAction: @escaping () -> Void
2628
) {
2729
self.context = context
2830
self.theme = theme
2931
self.insets = insets
3032
self.displaySkip = displaySkip
3133
self.createPasskeyAction = createPasskeyAction
34+
self.skipAction = skipAction
3235
}
3336

3437
static func ==(lhs: PasskeysScreenIntroComponent, rhs: PasskeysScreenIntroComponent) -> Bool {
@@ -300,14 +303,55 @@ final class PasskeysScreenIntroComponent: Component {
300303
containerSize: CGSize(width: availableSize.width - buttonInsets.left - buttonInsets.right, height: 52.0)
301304
)
302305

306+
var skipButtonSize: CGSize?
303307
if component.displaySkip {
304308
let skipButton: ComponentView<Empty>
309+
if let current = self.skipButton {
310+
skipButton = current
311+
} else {
312+
skipButton = ComponentView()
313+
self.skipButton = skipButton
314+
}
315+
//TODO:localize
316+
skipButtonSize = skipButton.update(
317+
transition: transition,
318+
component: AnyComponent(ButtonComponent(
319+
background: ButtonComponent.Background(
320+
style: .glass,
321+
color: component.theme.chatList.unreadBadgeInactiveBackgroundColor,
322+
foreground: component.theme.list.itemCheckColors.foregroundColor,
323+
pressedColor: component.theme.chatList.unreadBadgeInactiveBackgroundColor.withMultipliedAlpha(0.9),
324+
cornerRadius: 52.0 * 0.5
325+
),
326+
content: AnyComponentWithIdentity(
327+
id: AnyHashable(0),
328+
component: AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: "Skip", font: Font.semibold(17.0), textColor: component.theme.list.itemCheckColors.foregroundColor))))
329+
),
330+
action: { [weak self] in
331+
guard let self, let component = self.component else {
332+
return
333+
}
334+
component.skipAction()
335+
}
336+
)),
337+
environment: {},
338+
containerSize: CGSize(width: availableSize.width - buttonInsets.left - buttonInsets.right, height: 52.0)
339+
)
305340
} else if let skipButton = self.skipButton {
306341
self.skipButton = nil
307342
skipButton.view?.removeFromSuperview()
308343
}
309344

310-
let buttonFrame = CGRect(origin: CGPoint(x: buttonInsets.left, y: availableSize.height - buttonInsets.bottom - actionButtonSize.height), size: actionButtonSize)
345+
var buttonFrame = CGRect(origin: CGPoint(x: buttonInsets.left, y: availableSize.height - buttonInsets.bottom - actionButtonSize.height), size: actionButtonSize)
346+
if let skipButtonSize, let skipButtonView = self.skipButton?.view {
347+
let skipButtonFrame = buttonFrame
348+
buttonFrame = buttonFrame.offsetBy(dx: 0.0, dy: -8.0 - skipButtonSize.height)
349+
350+
if skipButtonView.superview == nil {
351+
self.addSubview(skipButtonView)
352+
}
353+
transition.setFrame(view: skipButtonView, frame: skipButtonFrame)
354+
}
311355

312356
if let actionButtonView = self.actionButton.view {
313357
if actionButtonView.superview == nil {

submodules/TelegramUI/Sources/SharedAccountContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4065,7 +4065,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
40654065
return loginEmailSetupController(context: context, blocking: blocking, emailPattern: emailPattern, canAutoDismissIfNeeded: canAutoDismissIfNeeded, navigationController: navigationController, completion: completion, dismiss: dismiss)
40664066
}
40674067

4068-
public func makePasskeySetupController(context: AccountContext, displaySkip: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: completion: @escaping () -> Void) -> ViewController {
4068+
public func makePasskeySetupController(context: AccountContext, displaySkip: Bool, navigationController: NavigationController?, completion: @escaping () -> Void, dismiss: @escaping () -> Void) -> ViewController {
40694069
return PasskeysScreen(context: context, displaySkip: displaySkip, initialPasskeysData: nil, passkeysDataUpdated: { _ in }, completion: completion, cancel: dismiss)
40704070
}
40714071
}

0 commit comments

Comments
 (0)