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 {
buttonIconNode = current
} 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.setup(source: AnimatedStickerNodeLocalFileSource(name: buttonIcon), width: 60, height: 60, playbackMode: .loop, mode: .direct(cachePathPrefix: nil))
strongSelf.buttonContentNode.addSubnode(buttonIconNode)
@ -965,11 +977,26 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
buttonIconNode.updateLayout(size: iconSize)
buttonIconNode.visibility = strongSelf.visibilityStatus == true
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)
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 strongSelf.ribbonBackgroundNode.image == nil {

View File

@ -516,7 +516,7 @@ public final class GiftItemComponent: Component {
switch 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:
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 text: String
let entities: [MessageTextEntity]
let includeUpgrade: Bool
let upgradeStars: Int64?
init(
context: AccountContext,
@ -52,7 +52,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
isSelf: Bool,
text: String,
entities: [MessageTextEntity],
includeUpgrade: Bool
upgradeStars: Int64?
) {
self.context = context
self.theme = theme
@ -69,7 +69,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
self.isSelf = isSelf
self.text = text
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) {
@ -146,7 +146,7 @@ final class ChatGiftPreviewItem: ListViewItem, ItemListItem, ListItemComponentAd
if lhs.entities != rhs.entities {
return false
}
if lhs.includeUpgrade != rhs.includeUpgrade {
if lhs.upgradeStars != rhs.upgradeStars {
return false
}
return true
@ -234,7 +234,7 @@ final class ChatGiftPreviewItemNode: ListViewItemNode {
case let .starGift(gift):
media = [
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,
options: options ?? [],
purpose: .starGift(peerId: component.peerId, requiredStars: starGift.price),
completion: { [weak starsContext] stars in
guard let starsContext else {
completion: { [weak self, weak starsContext] stars in
guard let self, let starsContext else {
return
}
self.inProgress = true
self.state?.updated()
starsContext.add(balance: StarsAmount(value: stars, nanos: 0))
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)
if let accountPeer = self.peerMap[component.context.account.peerId] {
var upgradeStars: Int64?
let subject: ChatGiftPreviewItem.Subject
switch component.subject {
case let .premium(product):
@ -816,6 +820,7 @@ final class GiftSetupScreenComponent: Component {
subject = .premium(months: product.months, amount: amount, currency: currency)
case let .starGift(gift):
subject = .starGift(gift: gift)
upgradeStars = gift.upgradeStars
}
let introContentSize = self.introContent.update(
@ -838,7 +843,7 @@ final class GiftSetupScreenComponent: Component {
isSelf: component.peerId == component.context.account.peerId,
text: self.textInputState.text.string,
entities: generateChatInputTextEntities(self.textInputState.text),
includeUpgrade: self.includeUpgrade
upgradeStars: self.includeUpgrade ? upgradeStars : nil
),
params: listItemParams
)

View File

@ -777,11 +777,6 @@ private final class GiftViewSheetContent: CombinedComponent {
.disappear(.default(alpha: true))
)
// originY += 32.0
// if soldOut {
// originY -= 12.0
// }
if !descriptionText.isEmpty {
let linkColor = theme.actionSheet.controlAccentColor
if state.cachedChevronImage == nil || state.cachedChevronImage?.1 !== environment.theme {
@ -845,7 +840,7 @@ private final class GiftViewSheetContent: CombinedComponent {
}
}
} else {
originY += 21.0
originY += 9.0
}
if nameHidden && uniqueGift == nil {
@ -855,28 +850,30 @@ private final class GiftViewSheetContent: CombinedComponent {
let hiddenDescription: String
if incoming {
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
} else {
hiddenDescription = ""
}
let hiddenText = hiddenText.update(
component: MultilineTextComponent(
text: .plain(NSAttributedString(string: hiddenDescription, font: textFont, textColor: textColor)),
horizontalAlignment: .center,
maximumNumberOfLines: 2,
lineSpacing: 0.2
),
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0 - 60.0, height: CGFloat.greatestFiniteMagnitude),
transition: .immediate
)
context.add(hiddenText
.position(CGPoint(x: context.availableSize.width / 2.0, y: originY))
)
originY += hiddenText.size.height
originY += 11.0
if !hiddenDescription.isEmpty {
let hiddenText = hiddenText.update(
component: MultilineTextComponent(
text: .plain(NSAttributedString(string: hiddenDescription, font: textFont, textColor: textColor)),
horizontalAlignment: .center,
maximumNumberOfLines: 2,
lineSpacing: 0.2
),
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0 - 60.0, height: CGFloat.greatestFiniteMagnitude),
transition: .immediate
)
context.add(hiddenText
.position(CGPoint(x: context.availableSize.width / 2.0, y: originY))
)
originY += hiddenText.size.height
originY += 11.0
}
}
let tableFont = Font.regular(15.0)