Skip to content

Commit aa244fb

Browse files
committed
Various improvements
1 parent 6ff5012 commit aa244fb

File tree

8 files changed

+162
-55
lines changed

8 files changed

+162
-55
lines changed

submodules/Components/MultilineTextWithEntitiesComponent/Sources/MultilineTextWithEntitiesComponent.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public final class MultilineTextWithEntitiesComponent: Component {
3434
public let handleSpoilers: Bool
3535
public let manualVisibilityControl: Bool
3636
public let resetAnimationsOnVisibilityChange: Bool
37+
public let displaysAsynchronously: Bool
3738
public let highlightAction: (([NSAttributedString.Key: Any]) -> NSAttributedString.Key?)?
3839
public let tapAction: (([NSAttributedString.Key: Any], Int) -> Void)?
3940
public let longTapAction: (([NSAttributedString.Key: Any], Int) -> Void)?
@@ -58,6 +59,7 @@ public final class MultilineTextWithEntitiesComponent: Component {
5859
handleSpoilers: Bool = false,
5960
manualVisibilityControl: Bool = false,
6061
resetAnimationsOnVisibilityChange: Bool = false,
62+
displaysAsynchronously: Bool = true,
6163
highlightAction: (([NSAttributedString.Key: Any]) -> NSAttributedString.Key?)? = nil,
6264
tapAction: (([NSAttributedString.Key: Any], Int) -> Void)? = nil,
6365
longTapAction: (([NSAttributedString.Key: Any], Int) -> Void)? = nil
@@ -82,6 +84,7 @@ public final class MultilineTextWithEntitiesComponent: Component {
8284
self.handleSpoilers = handleSpoilers
8385
self.manualVisibilityControl = manualVisibilityControl
8486
self.resetAnimationsOnVisibilityChange = resetAnimationsOnVisibilityChange
87+
self.displaysAsynchronously = displaysAsynchronously
8588
self.tapAction = tapAction
8689
self.longTapAction = longTapAction
8790
}
@@ -120,6 +123,9 @@ public final class MultilineTextWithEntitiesComponent: Component {
120123
if lhs.resetAnimationsOnVisibilityChange != rhs.resetAnimationsOnVisibilityChange {
121124
return false
122125
}
126+
if lhs.displaysAsynchronously != rhs.displaysAsynchronously {
127+
return false
128+
}
123129
if let lhsTextShadowColor = lhs.textShadowColor, let rhsTextShadowColor = rhs.textShadowColor {
124130
if !lhsTextShadowColor.isEqual(rhsTextShadowColor) {
125131
return false
@@ -161,6 +167,7 @@ public final class MultilineTextWithEntitiesComponent: Component {
161167
public override init(frame: CGRect) {
162168
self.textNode = ImmediateTextNodeWithEntities()
163169

170+
164171
super.init(frame: frame)
165172

166173
self.addSubview(self.textNode.view)
@@ -175,6 +182,8 @@ public final class MultilineTextWithEntitiesComponent: Component {
175182
}
176183

177184
public func update(component: MultilineTextWithEntitiesComponent, availableSize: CGSize, transition: ComponentTransition) -> CGSize {
185+
self.textNode.displaysAsynchronously = component.displaysAsynchronously
186+
178187
let attributedString: NSAttributedString
179188
switch component.text {
180189
case let .plain(string):

submodules/TelegramUI/Components/Chat/ChatMessagePaymentAlertController/Sources/ChatMessagePaymentAlertController.swift

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SwiftSignalKit
44
import AsyncDisplayKit
55
import Display
66
import ComponentFlow
7+
import ComponentDisplayAdapters
78
import Postbox
89
import TelegramCore
910
import TelegramPresentationData
@@ -323,28 +324,41 @@ public class ChatMessagePaymentAlertController: AlertController {
323324
private weak var parentNavigationController: NavigationController?
324325
private let chatPeerId: EnginePeer.Id
325326
private let showBalance: Bool
327+
private let animateBalanceOverlay: Bool
326328

329+
private var didUpdateCurrency = false
327330
public var currency: CurrencyAmount.Currency {
328331
didSet {
332+
self.didUpdateCurrency = true
329333
if let layout = self.validLayout {
330-
self.containerLayoutUpdated(layout, transition: .immediate)
334+
self.containerLayoutUpdated(layout, transition: .animated(duration: 0.25, curve: .easeInOut))
331335
}
332336
}
333337
}
334-
338+
335339
private let balance = ComponentView<Empty>()
336340

337341
private var didAppear = false
338342

339343
private var validLayout: ContainerViewLayout?
340344

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+
) {
342355
self.context = context
343356
self.presentationData = presentationData
344357
self.parentNavigationController = navigationController
345358
self.chatPeerId = chatPeerId
346359
self.showBalance = showBalance
347360
self.currency = currency
361+
self.animateBalanceOverlay = animateBalanceOverlay
348362

349363
super.init(theme: AlertControllerTheme(presentationData: presentationData), contentNode: contentNode)
350364

@@ -361,9 +375,18 @@ public class ChatMessagePaymentAlertController: AlertController {
361375
}
362376

363377
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+
}
367390
}
368391
}
369392

@@ -389,8 +412,13 @@ public class ChatMessagePaymentAlertController: AlertController {
389412

390413
if let context = self.context, let _ = self.parentNavigationController, self.showBalance {
391414
let insets = layout.insets(options: .statusBar)
415+
var balanceTransition = ComponentTransition(transition)
416+
if self.balance.view == nil {
417+
balanceTransition = .immediate
418+
}
419+
392420
let balanceSize = self.balance.update(
393-
transition: .immediate,
421+
transition: balanceTransition,
394422
component: AnyComponent(
395423
StarsBalanceOverlayComponent(
396424
context: context,
@@ -401,20 +429,28 @@ public class ChatMessagePaymentAlertController: AlertController {
401429
guard let self, let starsContext = context.starsContext, let navigationController = self.parentNavigationController else {
402430
return
403431
}
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+
}
404453
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-
})
418454
}
419455
)
420456
),
@@ -425,11 +461,13 @@ public class ChatMessagePaymentAlertController: AlertController {
425461
if view.superview == nil {
426462
self.view.addSubview(view)
427463

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+
}
431469
}
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))
433471
}
434472
}
435473
}

submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftStoreScreen.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,11 @@ final class GiftStoreScreenComponent: Component {
162162
}
163163

164164
private func updateScrolling(interactive: Bool = false, transition: ComponentTransition) {
165-
guard let environment = self.environment, let component = self.component, self.state?.starGiftsState?.dataState != .loading else {
165+
guard let environment = self.environment, let component = self.component else {
166166
return
167167
}
168+
169+
//, self.state?.starGiftsState?.dataState != .loading
168170

169171
let availableWidth = self.scrollView.bounds.width
170172
let availableHeight = self.scrollView.bounds.height
@@ -456,7 +458,7 @@ final class GiftStoreScreenComponent: Component {
456458
}
457459

458460
let bottomContentOffset = max(0.0, self.scrollView.contentSize.height - self.scrollView.contentOffset.y - self.scrollView.frame.height)
459-
if interactive, bottomContentOffset < 1000.0 {
461+
if interactive, bottomContentOffset < 800.0 {
460462
self.state?.starGiftsContext.loadMore()
461463
}
462464
}
@@ -1142,7 +1144,7 @@ final class GiftStoreScreenComponent: Component {
11421144
context: component.context,
11431145
colors: FilterSelectorComponent.Colors(
11441146
foreground: theme.list.itemPrimaryTextColor.withMultipliedAlpha(0.65),
1145-
background: theme.list.itemSecondaryTextColor.mixedWith(theme.list.blocksBackgroundColor, alpha: 0.85)
1147+
background: theme.list.itemSecondaryTextColor.withMultipliedAlpha(0.15)
11461148
),
11471149
items: filterItems,
11481150
selectedItemId: self.selectedFilterId

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftPurchaseAlertController.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ public func giftPurchaseAlertController(
446446
gift: StarGift.UniqueGift,
447447
peer: EnginePeer,
448448
navigationController: NavigationController?,
449-
commit: @escaping (CurrencyAmount.Currency) -> Void
449+
commit: @escaping (CurrencyAmount.Currency) -> Void,
450+
dismissed: @escaping () -> Void
450451
) -> AlertController {
451452
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
452453
let strings = presentationData.strings
@@ -463,7 +464,19 @@ public func giftPurchaseAlertController(
463464

464465
contentNode = GiftPurchaseAlertContentNode(context: context, theme: AlertControllerTheme(presentationData: presentationData), presentationTheme: presentationData.theme, strings: strings, gift: gift, peer: peer, actions: actions)
465466

466-
let controller = ChatMessagePaymentAlertController(context: context, presentationData: presentationData, contentNode: contentNode!, navigationController: navigationController, chatPeerId: context.account.peerId, showBalance: true, currency: gift.resellForTonOnly ? .ton : .stars)
467+
let controller = ChatMessagePaymentAlertController(
468+
context: context,
469+
presentationData: presentationData,
470+
contentNode: contentNode!,
471+
navigationController: navigationController,
472+
chatPeerId: context.account.peerId,
473+
showBalance: true,
474+
currency: gift.resellForTonOnly ? .ton : .stars,
475+
animateBalanceOverlay: false
476+
)
477+
controller.dismissed = { _ in
478+
dismissed()
479+
}
467480

468481
dismissImpl = { [weak controller] animated in
469482
if animated {

0 commit comments

Comments
 (0)