Various fixes

This commit is contained in:
Ilya Laktyushin
2022-07-10 20:35:05 +02:00
parent fc609c6c70
commit aa46e81a49
5 changed files with 140 additions and 138 deletions

View File

@@ -500,14 +500,14 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
typealias EnvironmentType = (ViewControllerComponentContainer.Environment, ScrollChildEnvironment)
let context: AccountContext
let peer: EnginePeer
let products: [InAppPurchaseManager.Product]
let selectedProductId: String
let peer: EnginePeer?
let products: [InAppPurchaseManager.Product]?
let selectedProductId: String?
let present: (ViewController) -> Void
let selectProduct: (String) -> Void
init(context: AccountContext, peer: EnginePeer, products: [InAppPurchaseManager.Product], selectedProductId: String, present: @escaping (ViewController) -> Void, selectProduct: @escaping (String) -> Void) {
init(context: AccountContext, peer: EnginePeer?, products: [InAppPurchaseManager.Product]?, selectedProductId: String?, present: @escaping (ViewController) -> Void, selectProduct: @escaping (String) -> Void) {
self.context = context
self.peer = peer
self.products = products
@@ -583,7 +583,6 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
let textColor = theme.list.itemPrimaryTextColor
let subtitleColor = theme.list.itemSecondaryTextColor
// let arrowColor = theme.list.disclosureArrowColor
let textFont = Font.regular(15.0)
let boldTextFont = Font.semibold(15.0)
@@ -594,7 +593,7 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
let text = text.update(
component: MultilineTextComponent(
text: .markdown(
text: strings.Premium_Gift_Description(component.peer.compactDisplayTitle).string,
text: strings.Premium_Gift_Description(component.peer?.compactDisplayTitle ?? "").string,
attributes: markdownAttributes
),
horizontalAlignment: .center,
@@ -620,52 +619,54 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
]
var i = 0
for product in component.products {
let monthsCount: Int
let giftTitle: String
let discount: String
switch product.id {
case "org.telegram.telegramPremium.twelveMonths":
giftTitle = strings.Premium_Gift_Years(1)
monthsCount = 12
discount = "-15%"
case "org.telegram.telegramPremium.sixMonths":
giftTitle = strings.Premium_Gift_Months(6)
monthsCount = 6
discount = "-10%"
case "org.telegram.telegramPremium.threeMonths":
giftTitle = strings.Premium_Gift_Months(3)
monthsCount = 3
discount = "-7%"
default:
giftTitle = ""
monthsCount = 1
discount = ""
}
items.append(ProductGroupComponent.Item(
AnyComponentWithIdentity(
id: product.id,
component: AnyComponent(
GiftComponent(
title: giftTitle,
totalPrice: product.price,
perMonthPrice: strings.Premium_Gift_PricePerMonth(product.pricePerMonth(monthsCount)).string,
discount: discount,
selected: product.id == component.selectedProductId,
primaryTextColor: textColor,
secondaryTextColor: subtitleColor,
accentColor: gradientColors[i],
checkForegroundColor: environment.theme.list.itemCheckColors.foregroundColor,
checkBorderColor: environment.theme.list.itemCheckColors.strokeColor
if let products = component.products {
for product in products {
let monthsCount: Int
let giftTitle: String
let discount: String
switch product.id {
case "org.telegram.telegramPremium.twelveMonths":
giftTitle = strings.Premium_Gift_Years(1)
monthsCount = 12
discount = "-15%"
case "org.telegram.telegramPremium.sixMonths":
giftTitle = strings.Premium_Gift_Months(6)
monthsCount = 6
discount = "-10%"
case "org.telegram.telegramPremium.threeMonths":
giftTitle = strings.Premium_Gift_Months(3)
monthsCount = 3
discount = "-7%"
default:
giftTitle = ""
monthsCount = 1
discount = ""
}
items.append(ProductGroupComponent.Item(
AnyComponentWithIdentity(
id: product.id,
component: AnyComponent(
GiftComponent(
title: giftTitle,
totalPrice: product.price,
perMonthPrice: strings.Premium_Gift_PricePerMonth(product.pricePerMonth(monthsCount)).string,
discount: discount,
selected: product.id == component.selectedProductId,
primaryTextColor: textColor,
secondaryTextColor: subtitleColor,
accentColor: gradientColors[i],
checkForegroundColor: environment.theme.list.itemCheckColors.foregroundColor,
checkBorderColor: environment.theme.list.itemCheckColors.strokeColor
)
)
)
),
action: {
component.selectProduct(product.id)
})
)
i += 1
),
action: {
component.selectProduct(product.id)
})
)
i += 1
}
}
let section = section.update(
@@ -960,45 +961,43 @@ private final class PremiumGiftScreenComponent: CombinedComponent {
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
)
if let peer = state.peer, let products = state.products, let selectedProductId = state.selectedProductId {
let scrollContent = scrollContent.update(
component: ScrollComponent<EnvironmentType>(
content: AnyComponent(PremiumGiftScreenContentComponent(
context: context.component.context,
peer: peer,
products: products,
selectedProductId: selectedProductId,
present: context.component.present,
selectProduct: { [weak state] productId in
state?.selectProduct(id: productId)
}
)),
contentInsets: UIEdgeInsets(top: environment.navigationHeight, left: 0.0, bottom: bottomPanelHeight, right: 0.0),
contentOffsetUpdated: { [weak state] topContentOffset, bottomContentOffset in
state?.topContentOffset = topContentOffset
state?.bottomContentOffset = bottomContentOffset
Queue.mainQueue().justDispatch {
state?.updated(transition: .immediate)
}
},
contentOffsetWillCommit: { targetContentOffset in
if targetContentOffset.pointee.y < 100.0 {
targetContentOffset.pointee = CGPoint(x: 0.0, y: 0.0)
} else if targetContentOffset.pointee.y < 123.0 {
targetContentOffset.pointee = CGPoint(x: 0.0, y: 123.0)
}
let scrollContent = scrollContent.update(
component: ScrollComponent<EnvironmentType>(
content: AnyComponent(PremiumGiftScreenContentComponent(
context: context.component.context,
peer: state.peer,
products: state.products,
selectedProductId: state.selectedProductId,
present: context.component.present,
selectProduct: { [weak state] productId in
state?.selectProduct(id: productId)
}
),
environment: { environment },
availableSize: context.availableSize,
transition: context.transition
)
context.add(scrollContent
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
)
}
)),
contentInsets: UIEdgeInsets(top: environment.navigationHeight, left: 0.0, bottom: bottomPanelHeight, right: 0.0),
contentOffsetUpdated: { [weak state] topContentOffset, bottomContentOffset in
state?.topContentOffset = topContentOffset
state?.bottomContentOffset = bottomContentOffset
Queue.mainQueue().justDispatch {
state?.updated(transition: .immediate)
}
},
contentOffsetWillCommit: { targetContentOffset in
if targetContentOffset.pointee.y < 100.0 {
targetContentOffset.pointee = CGPoint(x: 0.0, y: 0.0)
} else if targetContentOffset.pointee.y < 123.0 {
targetContentOffset.pointee = CGPoint(x: 0.0, y: 123.0)
}
}
),
environment: { environment },
availableSize: context.availableSize,
transition: context.transition
)
context.add(scrollContent
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
)
let topPanelAlpha: CGFloat
let titleOffset: CGFloat
let titleScale: CGFloat
@@ -1019,23 +1018,21 @@ private final class PremiumGiftScreenComponent: CombinedComponent {
titleAlpha = 1.0
}
if let peer = context.state.peer {
let star = star.update(
component: GiftAvatarComponent(
context: context.component.context,
peer: peer,
isVisible: starIsVisible,
hasIdleAnimations: state.hasIdleAnimations
),
availableSize: CGSize(width: min(390.0, context.availableSize.width), height: 220.0),
transition: context.transition
)
context.add(star
.position(CGPoint(x: context.availableSize.width / 2.0, y: topInset + star.size.height / 2.0 - 30.0 - titleOffset * titleScale))
.scale(titleScale)
)
}
let star = star.update(
component: GiftAvatarComponent(
context: context.component.context,
peer: context.state.peer,
isVisible: starIsVisible,
hasIdleAnimations: state.hasIdleAnimations
),
availableSize: CGSize(width: min(390.0, context.availableSize.width), height: 220.0),
transition: context.transition
)
context.add(star
.position(CGPoint(x: context.availableSize.width / 2.0, y: topInset + star.size.height / 2.0 - 30.0 - titleOffset * titleScale))
.scale(titleScale)
)
context.add(topPanel
.position(CGPoint(x: context.availableSize.width / 2.0, y: topPanel.size.height / 2.0))
@@ -1251,27 +1248,16 @@ public final class PremiumGiftScreen: ViewControllerComponentContainer {
strongSelf.view.disablesInteractiveModalDismiss = inProgress
}
}
// presentImpl = { [weak self] c in
// self?.present(c, in: .window(.root))
// }
pushImpl = { [weak self] c in
self?.push(c)
}
completionImpl = { [weak self] duration in
if let strongSelf = self, let navigationController = strongSelf.navigationController as? NavigationController {
// let introController = PremiumIntroScreen(context: context, source: .gift(from: context.account.peerId, to: peerId, duration: duration))
var controllers = navigationController.viewControllers
controllers = controllers.filter { !($0 is PeerInfoScreen) && !($0 is PremiumGiftScreen) }
navigationController.setViewControllers(controllers, animated: true)
Queue.mainQueue().after(2.8, {
if let topController = navigationController.viewControllers.last {
topController.view.addSubview(ConfettiView(frame: topController.view.bounds))
}
})
}
}
}