mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Various improvements [skip ci]
This commit is contained in:
@@ -33,6 +33,7 @@ import LottieComponent
|
||||
import ContextUI
|
||||
import TelegramNotices
|
||||
import PremiumLockButtonSubtitleComponent
|
||||
import StarsBalanceOverlayComponent
|
||||
|
||||
private let modelButtonTag = GenericComponentViewTag()
|
||||
private let backdropButtonTag = GenericComponentViewTag()
|
||||
@@ -267,7 +268,6 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if let starsContext = context.starsContext, let state = starsContext.currentState, state.balance < StarsAmount(value: 100, nanos: 0) {
|
||||
self.optionsDisposable = (context.engine.payments.starsTopUpOptions()
|
||||
|> deliverOnMainQueue).start(next: { [weak self] options in
|
||||
@@ -286,17 +286,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
self.upgradeDisposable?.dispose()
|
||||
self.levelsDisposable.dispose()
|
||||
}
|
||||
|
||||
func requestUpgradePreview() {
|
||||
guard let arguments = self.subject.arguments, arguments.canUpgrade || arguments.upgradeStars != nil else {
|
||||
return
|
||||
}
|
||||
self.context.starsContext?.load(force: false)
|
||||
|
||||
self.inUpgradePreview = true
|
||||
self.updated(transition: .spring(duration: 0.4))
|
||||
}
|
||||
|
||||
|
||||
func requestWearPreview() {
|
||||
self.inWearPreview = true
|
||||
self.updated(transition: .spring(duration: 0.4))
|
||||
@@ -329,6 +319,29 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
}
|
||||
}
|
||||
|
||||
func requestUpgradePreview() {
|
||||
guard let arguments = self.subject.arguments, arguments.canUpgrade || arguments.upgradeStars != nil else {
|
||||
return
|
||||
}
|
||||
self.context.starsContext?.load(force: false)
|
||||
|
||||
self.inUpgradePreview = true
|
||||
self.updated(transition: .spring(duration: 0.4))
|
||||
|
||||
if let controller = self.getController() as? GiftViewScreen {
|
||||
controller.showBalance = true
|
||||
}
|
||||
}
|
||||
|
||||
func cancelUpgradePreview() {
|
||||
self.inUpgradePreview = false
|
||||
self.updated(transition: .spring(duration: 0.4))
|
||||
|
||||
if let controller = self.getController() as? GiftViewScreen {
|
||||
controller.showBalance = false
|
||||
}
|
||||
}
|
||||
|
||||
func commitUpgrade() {
|
||||
guard let arguments = self.subject.arguments, let peerId = arguments.peerId, let starsContext = self.context.starsContext, let starsState = starsContext.currentState else {
|
||||
return
|
||||
@@ -382,6 +395,10 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
proceed(upgradeForm.id)
|
||||
}
|
||||
}
|
||||
|
||||
if let controller = self.getController() as? GiftViewScreen {
|
||||
controller.showBalance = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,8 +563,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
state.inWearPreview = false
|
||||
state.updated(transition: .spring(duration: 0.4))
|
||||
} else if state.inUpgradePreview {
|
||||
state.inUpgradePreview = false
|
||||
state.updated(transition: .spring(duration: 0.4))
|
||||
state.cancelUpgradePreview()
|
||||
} else {
|
||||
cancel(true)
|
||||
}
|
||||
@@ -2089,7 +2105,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
||||
}
|
||||
var upgradeString = strings.Gift_Upgrade_Upgrade
|
||||
if let upgradeForm = state.upgradeForm, let price = upgradeForm.invoice.prices.first?.amount {
|
||||
upgradeString += " # \(price)"
|
||||
upgradeString += " # \(presentationStringsFormattedNumber(Int32(price), environment.dateTimeFormat.groupingSeparator))"
|
||||
}
|
||||
let buttonTitle = subject.arguments?.upgradeStars != nil ? strings.Gift_Upgrade_Confirm : upgradeString
|
||||
let buttonAttributedString = NSMutableAttributedString(string: buttonTitle, font: Font.semibold(17.0), textColor: theme.list.itemCheckColors.foregroundColor, paragraphAlignment: .center)
|
||||
@@ -2456,6 +2472,13 @@ public class GiftViewScreen: ViewControllerComponentContainer {
|
||||
fileprivate var subject: GiftViewScreen.Subject
|
||||
public var disposed: () -> Void = {}
|
||||
|
||||
fileprivate var showBalance = false {
|
||||
didSet {
|
||||
self.requestLayout(transition: .immediate)
|
||||
}
|
||||
}
|
||||
private let balanceOverlay = ComponentView<Empty>()
|
||||
|
||||
private let hapticFeedback = HapticFeedback()
|
||||
|
||||
public init(
|
||||
@@ -2702,7 +2725,11 @@ public class GiftViewScreen: ViewControllerComponentContainer {
|
||||
|
||||
if let navigationController {
|
||||
Queue.mainQueue().after(0.5) {
|
||||
if !isChannelGift {
|
||||
let text: String
|
||||
if isChannelGift {
|
||||
text = presentationData.strings.Gift_Convert_Success_ChannelText(presentationData.strings.Gift_Convert_Success_ChannelText_Stars(Int32(convertStars))).string
|
||||
} else {
|
||||
text = presentationData.strings.Gift_Convert_Success_Text(presentationData.strings.Gift_Convert_Success_Text_Stars(Int32(convertStars))).string
|
||||
if let starsContext = context.starsContext {
|
||||
navigationController.pushViewController(context.sharedContext.makeStarsTransactionsScreen(context: context, starsContext: starsContext), animated: true)
|
||||
}
|
||||
@@ -2716,7 +2743,7 @@ public class GiftViewScreen: ViewControllerComponentContainer {
|
||||
scale: 0.066,
|
||||
colors: [:],
|
||||
title: presentationData.strings.Gift_Convert_Success_Title,
|
||||
text: presentationData.strings.Gift_Convert_Success_Text(presentationData.strings.Gift_Convert_Success_Text_Stars(Int32(convertStars))).string,
|
||||
text: text,
|
||||
customUndoText: nil,
|
||||
timeout: nil
|
||||
),
|
||||
@@ -3031,6 +3058,11 @@ public class GiftViewScreen: ViewControllerComponentContainer {
|
||||
if let view = self.node.hostView.findTaggedView(tag: SheetComponent<ViewControllerComponentContainer.Environment>.View.Tag()) as? SheetComponent<ViewControllerComponentContainer.Environment>.View {
|
||||
view.dismissAnimated()
|
||||
}
|
||||
|
||||
if let view = self.balanceOverlay.view, view.superview != nil {
|
||||
view.layer.animateScale(from: 1.0, to: 0.8, duration: 0.4, removeOnCompletion: false)
|
||||
view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func dismissAllTooltips() {
|
||||
@@ -3052,6 +3084,45 @@ public class GiftViewScreen: ViewControllerComponentContainer {
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
public override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
super.containerLayoutUpdated(layout, transition: transition)
|
||||
|
||||
if self.showBalance {
|
||||
let insets = layout.insets(options: .statusBar)
|
||||
let balanceSize = self.balanceOverlay.update(
|
||||
transition: .immediate,
|
||||
component: AnyComponent(
|
||||
StarsBalanceOverlayComponent(
|
||||
context: self.context,
|
||||
theme: self.context.sharedContext.currentPresentationData.with { $0 }.theme,
|
||||
action: {
|
||||
|
||||
}
|
||||
)
|
||||
),
|
||||
environment: {},
|
||||
containerSize: layout.size
|
||||
)
|
||||
if let view = self.balanceOverlay.view {
|
||||
if view.superview == nil {
|
||||
self.view.addSubview(view)
|
||||
|
||||
view.layer.animatePosition(from: CGPoint(x: 0.0, y: -64.0), to: .zero, duration: 0.4, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
|
||||
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)
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25)
|
||||
}
|
||||
view.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((layout.size.width - balanceSize.width) / 2.0), y: insets.top + 5.0), size: balanceSize)
|
||||
}
|
||||
} else if let view = self.balanceOverlay.view, view.superview != nil {
|
||||
view.alpha = 0.0
|
||||
view.layer.animateScale(from: 1.0, to: 0.8, duration: 0.4)
|
||||
view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, completion: { _ in
|
||||
view.removeFromSuperview()
|
||||
view.alpha = 1.0
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func formatPercentage(_ value: Float) -> String {
|
||||
|
||||
Reference in New Issue
Block a user