@@ -4,6 +4,7 @@ import SwiftSignalKit
4
4
import AsyncDisplayKit
5
5
import Display
6
6
import ComponentFlow
7
+ import ComponentDisplayAdapters
7
8
import Postbox
8
9
import TelegramCore
9
10
import TelegramPresentationData
@@ -323,28 +324,41 @@ public class ChatMessagePaymentAlertController: AlertController {
323
324
private weak var parentNavigationController : NavigationController ?
324
325
private let chatPeerId : EnginePeer . Id
325
326
private let showBalance : Bool
327
+ private let animateBalanceOverlay : Bool
326
328
329
+ private var didUpdateCurrency = false
327
330
public var currency : CurrencyAmount . Currency {
328
331
didSet {
332
+ self . didUpdateCurrency = true
329
333
if let layout = self . validLayout {
330
- self . containerLayoutUpdated ( layout, transition: . immediate )
334
+ self . containerLayoutUpdated ( layout, transition: . animated ( duration : 0.25 , curve : . easeInOut ) )
331
335
}
332
336
}
333
337
}
334
-
338
+
335
339
private let balance = ComponentView < Empty > ( )
336
340
337
341
private var didAppear = false
338
342
339
343
private var validLayout : ContainerViewLayout ?
340
344
341
- public init ( context: AccountContext ? , presentationData: PresentationData , contentNode: AlertContentNode , navigationController: NavigationController ? , chatPeerId: EnginePeer . Id , showBalance: Bool = true , currency: CurrencyAmount . Currency = . stars) {
345
+ public init (
346
+ context: AccountContext ? ,
347
+ presentationData: PresentationData ,
348
+ contentNode: AlertContentNode ,
349
+ navigationController: NavigationController ? ,
350
+ chatPeerId: EnginePeer . Id ,
351
+ showBalance: Bool = true ,
352
+ currency: CurrencyAmount . Currency = . stars,
353
+ animateBalanceOverlay: Bool = true
354
+ ) {
342
355
self . context = context
343
356
self . presentationData = presentationData
344
357
self . parentNavigationController = navigationController
345
358
self . chatPeerId = chatPeerId
346
359
self . showBalance = showBalance
347
360
self . currency = currency
361
+ self . animateBalanceOverlay = animateBalanceOverlay
348
362
349
363
super. init ( theme: AlertControllerTheme ( presentationData: presentationData) , contentNode: contentNode)
350
364
@@ -361,9 +375,18 @@ public class ChatMessagePaymentAlertController: AlertController {
361
375
}
362
376
363
377
private func animateOut( ) {
364
- if let view = self . balance. view {
365
- view. layer. animateScale ( from: 1.0 , to: 0.8 , duration: 0.4 , removeOnCompletion: false )
366
- view. layer. animateAlpha ( from: 1.0 , to: 0.0 , duration: 0.3 , removeOnCompletion: false )
378
+ if !self . animateBalanceOverlay {
379
+ if self . currency == . ton && self . didUpdateCurrency {
380
+ self . currency = . stars
381
+ }
382
+ Queue . mainQueue ( ) . after ( 0.39 , {
383
+
384
+ } )
385
+ } else {
386
+ if let view = self . balance. view {
387
+ view. layer. animateScale ( from: 1.0 , to: 0.8 , duration: 0.4 , removeOnCompletion: false )
388
+ view. layer. animateAlpha ( from: 1.0 , to: 0.0 , duration: 0.3 , removeOnCompletion: false )
389
+ }
367
390
}
368
391
}
369
392
@@ -389,8 +412,13 @@ public class ChatMessagePaymentAlertController: AlertController {
389
412
390
413
if let context = self . context, let _ = self . parentNavigationController, self . showBalance {
391
414
let insets = layout. insets ( options: . statusBar)
415
+ var balanceTransition = ComponentTransition ( transition)
416
+ if self . balance. view == nil {
417
+ balanceTransition = . immediate
418
+ }
419
+
392
420
let balanceSize = self . balance. update (
393
- transition: . immediate ,
421
+ transition: balanceTransition ,
394
422
component: AnyComponent (
395
423
StarsBalanceOverlayComponent (
396
424
context: context,
@@ -401,20 +429,28 @@ public class ChatMessagePaymentAlertController: AlertController {
401
429
guard let self, let starsContext = context. starsContext, let navigationController = self . parentNavigationController else {
402
430
return
403
431
}
432
+ switch self . currency {
433
+ case . stars:
434
+ let _ = ( context. engine. payments. starsTopUpOptions ( )
435
+ |> take ( 1 )
436
+ |> deliverOnMainQueue) . startStandalone ( next: { options in
437
+ let controller = context. sharedContext. makeStarsPurchaseScreen (
438
+ context: context,
439
+ starsContext: starsContext,
440
+ options: options,
441
+ purpose: . generic,
442
+ completion: { _ in }
443
+ )
444
+ navigationController. pushViewController ( controller)
445
+ } )
446
+ case . ton:
447
+ var fragmentUrl = " https://fragment.com/ads/topup "
448
+ if let data = context. currentAppConfiguration. with ( { $0 } ) . data, let value = data [ " ton_topup_url " ] as? String {
449
+ fragmentUrl = value
450
+ }
451
+ context. sharedContext. applicationBindings. openUrl ( fragmentUrl)
452
+ }
404
453
self . dismissAnimated ( )
405
-
406
- let _ = ( context. engine. payments. starsTopUpOptions ( )
407
- |> take ( 1 )
408
- |> deliverOnMainQueue) . startStandalone ( next: { options in
409
- let controller = context. sharedContext. makeStarsPurchaseScreen (
410
- context: context,
411
- starsContext: starsContext,
412
- options: options,
413
- purpose: . generic,
414
- completion: { _ in }
415
- )
416
- navigationController. pushViewController ( controller)
417
- } )
418
454
}
419
455
)
420
456
) ,
@@ -425,11 +461,13 @@ public class ChatMessagePaymentAlertController: AlertController {
425
461
if view. superview == nil {
426
462
self . view. addSubview ( view)
427
463
428
- view. layer. animatePosition ( from: CGPoint ( x: 0.0 , y: - 64.0 ) , to: . zero, duration: 0.4 , timingFunction: kCAMediaTimingFunctionSpring, additive: true )
429
- view. layer. animateSpring ( from: 0.8 as NSNumber , to: 1.0 as NSNumber , keyPath: " transform.scale " , duration: 0.5 , initialVelocity: 0.0 , removeOnCompletion: true , additive: false , completion: nil )
430
- view. layer. animateAlpha ( from: 0.0 , to: 1.0 , duration: 0.25 )
464
+ if self . animateBalanceOverlay {
465
+ view. layer. animatePosition ( from: CGPoint ( x: 0.0 , y: - 64.0 ) , to: . zero, duration: 0.4 , timingFunction: kCAMediaTimingFunctionSpring, additive: true )
466
+ view. layer. animateSpring ( from: 0.8 as NSNumber , to: 1.0 as NSNumber , keyPath: " transform.scale " , duration: 0.5 , initialVelocity: 0.0 , removeOnCompletion: true , additive: false , completion: nil )
467
+ view. layer. animateAlpha ( from: 0.0 , to: 1.0 , duration: 0.25 )
468
+ }
431
469
}
432
- view . frame = CGRect ( origin: CGPoint ( x: floorToScreenPixels ( ( layout. size. width - balanceSize. width) / 2.0 ) , y: insets. top + 5.0 ) , size: balanceSize)
470
+ balanceTransition . setFrame ( view : view , frame : CGRect ( origin: CGPoint ( x: floorToScreenPixels ( ( layout. size. width - balanceSize. width) / 2.0 ) , y: insets. top + 5.0 ) , size: balanceSize) )
433
471
}
434
472
}
435
473
}
0 commit comments