Various fixes

This commit is contained in:
Ilya Laktyushin 2025-01-02 15:39:10 +04:00
parent d9e35e7882
commit c15f28474d
5 changed files with 63 additions and 34 deletions

View File

@ -954,6 +954,18 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if let current = strongSelf.buttonIconNode { if let current = strongSelf.buttonIconNode {
buttonIconNode = current buttonIconNode = current
} else { } else {
if animation.isAnimated {
if let snapshotView = strongSelf.buttonContentNode.view.snapshotView(afterScreenUpdates: false) {
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
snapshotView.removeFromSuperview()
})
snapshotView.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2, removeOnCompletion: false)
strongSelf.buttonNode.view.addSubview(snapshotView)
}
strongSelf.buttonContentNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
strongSelf.buttonContentNode.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
}
buttonIconNode = DefaultAnimatedStickerNodeImpl() buttonIconNode = DefaultAnimatedStickerNodeImpl()
buttonIconNode.setup(source: AnimatedStickerNodeLocalFileSource(name: buttonIcon), width: 60, height: 60, playbackMode: .loop, mode: .direct(cachePathPrefix: nil)) buttonIconNode.setup(source: AnimatedStickerNodeLocalFileSource(name: buttonIcon), width: 60, height: 60, playbackMode: .loop, mode: .direct(cachePathPrefix: nil))
strongSelf.buttonContentNode.addSubnode(buttonIconNode) strongSelf.buttonContentNode.addSubnode(buttonIconNode)
@ -965,11 +977,26 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
buttonIconNode.updateLayout(size: iconSize) buttonIconNode.updateLayout(size: iconSize)
buttonIconNode.visibility = strongSelf.visibilityStatus == true buttonIconNode.visibility = strongSelf.visibilityStatus == true
buttonIconNode.dynamicColor = primaryTextColor buttonIconNode.dynamicColor = primaryTextColor
} else if let buttonIconNode = strongSelf.buttonIconNode {
if animation.isAnimated {
if let snapshotView = strongSelf.buttonContentNode.view.snapshotView(afterScreenUpdates: false) {
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
snapshotView.removeFromSuperview()
})
snapshotView.layer.animateScale(from: 1.0, to: 0.1, duration: 0.2, removeOnCompletion: false)
strongSelf.buttonNode.view.addSubview(snapshotView)
}
strongSelf.buttonContentNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
strongSelf.buttonContentNode.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
}
strongSelf.buttonIconNode = nil
buttonIconNode.removeFromSupernode()
} }
animation.animator.updateFrame(layer: strongSelf.buttonNode.layer, frame: CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - buttonSize.width) / 2.0), y: buttonOriginY), size: buttonSize), completion: nil) animation.animator.updateFrame(layer: strongSelf.buttonNode.layer, frame: CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - buttonSize.width) / 2.0), y: buttonOriginY), size: buttonSize), completion: nil)
strongSelf.buttonStarsNode.frame = CGRect(origin: .zero, size: buttonSize) strongSelf.buttonStarsNode.frame = CGRect(origin: .zero, size: buttonSize)
animation.animator.updateFrame(layer: strongSelf.buttonContentNode.layer, frame: CGRect(origin: .zero, size: buttonSize), completion: nil) strongSelf.buttonContentNode.frame = CGRect(origin: .zero, size: buttonSize)
if ribbonTextLayout.size.width > 0.0 { if ribbonTextLayout.size.width > 0.0 {
if strongSelf.ribbonBackgroundNode.image == nil { if strongSelf.ribbonBackgroundNode.image == nil {

View File

@ -516,7 +516,7 @@ public final class GiftItemComponent: Component {
switch peer { switch peer {
case let .peer(peer): case let .peer(peer):
avatarNode.setPeerV2(context: component.context, theme: component.theme, peer: peer, displayDimensions: CGSize(width: 20.0, height: 20.0)) avatarNode.setPeer(context: component.context, theme: component.theme, peer: peer, displayDimensions: CGSize(width: 20.0, height: 20.0))
case .anonymous: case .anonymous:
avatarNode.setPeer(context: component.context, theme: component.theme, peer: nil, overrideImage: .anonymousSavedMessagesIcon(isColored: true)) avatarNode.setPeer(context: component.context, theme: component.theme, peer: nil, overrideImage: .anonymousSavedMessagesIcon(isColored: true))
} }

View File

@ -34,7 +34,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
let isSelf: Bool let isSelf: Bool
let text: String let text: String
let entities: [MessageTextEntity] let entities: [MessageTextEntity]
let includeUpgrade: Bool let upgradeStars: Int64?
init( init(
context: AccountContext, context: AccountContext,
@ -52,7 +52,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
isSelf: Bool, isSelf: Bool,
text: String, text: String,
entities: [MessageTextEntity], entities: [MessageTextEntity],
includeUpgrade: Bool upgradeStars: Int64?
) { ) {
self.context = context self.context = context
self.theme = theme self.theme = theme
@ -69,7 +69,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
self.isSelf = isSelf self.isSelf = isSelf
self.text = text self.text = text
self.entities = entities self.entities = entities
self.includeUpgrade = includeUpgrade self.upgradeStars = upgradeStars
} }
func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) { func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
@ -146,7 +146,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
if lhs.entities != rhs.entities { if lhs.entities != rhs.entities {
return false return false
} }
if lhs.includeUpgrade != rhs.includeUpgrade { if lhs.upgradeStars != rhs.upgradeStars {
return false return false
} }
return true return true
@ -234,7 +234,7 @@ final class ChatGiftPreviewItemNode: ListViewItemNode {
case let .starGift(gift): case let .starGift(gift):
media = [ media = [
TelegramMediaAction( TelegramMediaAction(
action: .starGift(gift: .generic(gift), convertStars: gift.convertStars, text: item.text, entities: item.entities, nameHidden: false, savedToProfile: false, converted: false, upgraded: false, canUpgrade: true, upgradeStars: item.includeUpgrade ? 1 : nil, isRefunded: false, upgradeMessageId: nil) action: .starGift(gift: .generic(gift), convertStars: gift.convertStars, text: item.text, entities: item.entities, nameHidden: false, savedToProfile: false, converted: false, upgraded: false, canUpgrade: true, upgradeStars: item.upgradeStars, isRefunded: false, upgradeMessageId: nil)
) )
] ]
} }

View File

@ -416,10 +416,13 @@ final class GiftSetupScreenComponent: Component {
starsContext: starsContext, starsContext: starsContext,
options: options ?? [], options: options ?? [],
purpose: .starGift(peerId: component.peerId, requiredStars: starGift.price), purpose: .starGift(peerId: component.peerId, requiredStars: starGift.price),
completion: { [weak starsContext] stars in completion: { [weak self, weak starsContext] stars in
guard let starsContext else { guard let self, let starsContext else {
return return
} }
self.inProgress = true
self.state?.updated()
starsContext.add(balance: StarsAmount(value: stars, nanos: 0)) starsContext.add(balance: StarsAmount(value: stars, nanos: 0))
let _ = (starsContext.state let _ = (starsContext.state
@ -809,6 +812,7 @@ final class GiftSetupScreenComponent: Component {
let listItemParams = ListViewItemLayoutParams(width: availableSize.width - sideInset * 2.0, leftInset: 0.0, rightInset: 0.0, availableHeight: 10000.0, isStandalone: true) let listItemParams = ListViewItemLayoutParams(width: availableSize.width - sideInset * 2.0, leftInset: 0.0, rightInset: 0.0, availableHeight: 10000.0, isStandalone: true)
if let accountPeer = self.peerMap[component.context.account.peerId] { if let accountPeer = self.peerMap[component.context.account.peerId] {
var upgradeStars: Int64?
let subject: ChatGiftPreviewItem.Subject let subject: ChatGiftPreviewItem.Subject
switch component.subject { switch component.subject {
case let .premium(product): case let .premium(product):
@ -816,6 +820,7 @@ final class GiftSetupScreenComponent: Component {
subject = .premium(months: product.months, amount: amount, currency: currency) subject = .premium(months: product.months, amount: amount, currency: currency)
case let .starGift(gift): case let .starGift(gift):
subject = .starGift(gift: gift) subject = .starGift(gift: gift)
upgradeStars = gift.upgradeStars
} }
let introContentSize = self.introContent.update( let introContentSize = self.introContent.update(
@ -838,7 +843,7 @@ final class GiftSetupScreenComponent: Component {
isSelf: component.peerId == component.context.account.peerId, isSelf: component.peerId == component.context.account.peerId,
text: self.textInputState.text.string, text: self.textInputState.text.string,
entities: generateChatInputTextEntities(self.textInputState.text), entities: generateChatInputTextEntities(self.textInputState.text),
includeUpgrade: self.includeUpgrade upgradeStars: self.includeUpgrade ? upgradeStars : nil
), ),
params: listItemParams params: listItemParams
) )

View File

@ -777,11 +777,6 @@ private final class GiftViewSheetContent: CombinedComponent {
.disappear(.default(alpha: true)) .disappear(.default(alpha: true))
) )
// originY += 32.0
// if soldOut {
// originY -= 12.0
// }
if !descriptionText.isEmpty { if !descriptionText.isEmpty {
let linkColor = theme.actionSheet.controlAccentColor let linkColor = theme.actionSheet.controlAccentColor
if state.cachedChevronImage == nil || state.cachedChevronImage?.1 !== environment.theme { if state.cachedChevronImage == nil || state.cachedChevronImage?.1 !== environment.theme {
@ -845,7 +840,7 @@ private final class GiftViewSheetContent: CombinedComponent {
} }
} }
} else { } else {
originY += 21.0 originY += 9.0
} }
if nameHidden && uniqueGift == nil { if nameHidden && uniqueGift == nil {
@ -855,12 +850,13 @@ private final class GiftViewSheetContent: CombinedComponent {
let hiddenDescription: String let hiddenDescription: String
if incoming { if incoming {
hiddenDescription = text != nil ? strings.Gift_View_NameAndMessageHidden : strings.Gift_View_NameHidden hiddenDescription = text != nil ? strings.Gift_View_NameAndMessageHidden : strings.Gift_View_NameHidden
} else if let peerId = subject.arguments?.peerId, let peer = state.peerMap[peerId] { } else if let peerId = subject.arguments?.peerId, let peer = state.peerMap[peerId], subject.arguments?.fromPeerId != nil {
hiddenDescription = text != nil ? strings.Gift_View_Outgoing_NameAndMessageHidden(peer.compactDisplayTitle).string : strings.Gift_View_Outgoing_NameHidden(peer.compactDisplayTitle).string hiddenDescription = text != nil ? strings.Gift_View_Outgoing_NameAndMessageHidden(peer.compactDisplayTitle).string : strings.Gift_View_Outgoing_NameHidden(peer.compactDisplayTitle).string
} else { } else {
hiddenDescription = "" hiddenDescription = ""
} }
if !hiddenDescription.isEmpty {
let hiddenText = hiddenText.update( let hiddenText = hiddenText.update(
component: MultilineTextComponent( component: MultilineTextComponent(
text: .plain(NSAttributedString(string: hiddenDescription, font: textFont, textColor: textColor)), text: .plain(NSAttributedString(string: hiddenDescription, font: textFont, textColor: textColor)),
@ -878,6 +874,7 @@ private final class GiftViewSheetContent: CombinedComponent {
originY += hiddenText.size.height originY += hiddenText.size.height
originY += 11.0 originY += 11.0
} }
}
let tableFont = Font.regular(15.0) let tableFont = Font.regular(15.0)
let tableBoldFont = Font.semibold(15.0) let tableBoldFont = Font.semibold(15.0)