Update ad close button

This commit is contained in:
Isaac 2024-02-06 15:27:36 +04:00
parent 7e42a9cc12
commit 98ebf6ddb4
7 changed files with 120 additions and 70 deletions

View File

@ -277,6 +277,7 @@ public enum PresentationResourceKey: Int32 {
case chatFreeCommentButtonIcon
case chatFreeNavigateButtonIcon
case chatFreeShareButtonIcon
case chatFreeCloseButtonIcon
case chatKeyboardActionButtonMessageIcon
case chatKeyboardActionButtonLinkIcon

View File

@ -1108,6 +1108,12 @@ public struct PresentationResourcesChat {
})
}
public static func chatFreeCloseButtonIcon(_ theme: PresentationTheme, wallpaper: TelegramWallpaper) -> UIImage? {
return theme.image(PresentationResourceKey.chatFreeCloseButtonIcon.rawValue, { _ in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/SideCloseIcon"), color: bubbleVariableColor(variableColor: theme.chat.message.shareButtonForegroundColor, wallpaper: wallpaper))
})
}
public static func chatKeyboardActionButtonMessageIconImage(_ theme: PresentationTheme) -> UIImage? {
return theme.image(PresentationResourceKey.chatKeyboardActionButtonMessageIcon.rawValue, { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotMessage"), color: theme.chat.inputButtonPanel.buttonTextColor)

View File

@ -1060,73 +1060,6 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
title.textNode.bounds = CGRect(origin: CGPoint(), size: titleFrame.size)
animation.animator.updatePosition(layer: title.textNode.layer, position: titleFrame.origin, completion: nil)
}
if message.adAttribute != nil {
let closeButtonImage: UIImage
if let current = self.closeButtonImage {
closeButtonImage = current
} else {
closeButtonImage = generateImage(CGSize(width: 12.0, height: 12.0), rotatedContext: { size, context in
context.clear(CGRect(origin: .zero, size: size))
let color = UIColor.white
context.setAlpha(color.alpha)
context.setBlendMode(.copy)
context.setStrokeColor(UIColor.white.cgColor)
context.setLineWidth(1.0 + UIScreenPixel)
context.setLineCap(.round)
let bounds = CGRect(origin: .zero, size: size).insetBy(dx: 1.0 + UIScreenPixel, dy: 1.0 + UIScreenPixel)
context.move(to: CGPoint(x: bounds.minX, y: bounds.minY))
context.addLine(to: CGPoint(x: bounds.maxX, y: bounds.maxY))
context.strokePath()
context.move(to: CGPoint(x: bounds.maxX, y: bounds.minY))
context.addLine(to: CGPoint(x: bounds.minX, y: bounds.maxY))
context.strokePath()
})!.withRenderingMode(.alwaysTemplate)
self.closeButtonImage = closeButtonImage
}
let closeButton: ComponentView<Empty>
if let current = self.closeButton {
closeButton = current
} else {
closeButton = ComponentView()
self.closeButton = closeButton
}
let closeButtonSize = closeButton.update(
transition: .immediate,
component: AnyComponent(PlainButtonComponent(
content: AnyComponent(Image(image: closeButtonImage, tintColor: mainColor)),
effectAlignment: .center,
action: { [weak controllerInteraction] in
guard let controllerInteraction else {
return
}
controllerInteraction.openNoAdsDemo()
}
)),
environment: {},
containerSize: CGSize(width: 12.0, height: 12.0)
)
let closeButtonFrame = CGRect(origin: CGPoint(x: backgroundFrame.maxX - 8.0 - closeButtonSize.width, y: backgroundInsets.top + 8.0), size: closeButtonSize)
if let closeButtonView = closeButton.view {
if closeButtonView.superview == nil {
self.transformContainer.view.addSubview(closeButtonView)
}
animation.animator.updateFrame(layer: closeButtonView.layer, frame: closeButtonFrame, completion: nil)
}
} else {
if let closeButton = self.closeButton {
self.closeButton = nil
closeButton.view?.removeFromSuperview()
}
}
} else {
if let title = self.title {
self.title = nil

View File

@ -1542,7 +1542,7 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
}
let isAd = item.content.firstMessage.adAttribute != nil
if isAd {
needsShareButton = false
needsShareButton = true
}
for attribute in item.content.firstMessage.attributes {
if let attribute = attribute as? RestrictedContentMessageAttribute, attribute.platformText(platform: "ios", contentSettings: item.context.currentContentSettings.with { $0 }) != nil {
@ -3879,6 +3879,11 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
let buttonSize = shareButtonNode.update(presentationData: item.presentationData, controllerInteraction: item.controllerInteraction, chatLocation: item.chatLocation, subject: item.associatedData.subject, message: item.message, account: item.context.account, disableComments: disablesComments)
var buttonFrame = CGRect(origin: CGPoint(x: !incoming ? backgroundFrame.minX - buttonSize.width - 8.0 : backgroundFrame.maxX + 8.0, y: backgroundFrame.maxY - buttonSize.width - 1.0), size: buttonSize)
if item.message.adAttribute != nil {
buttonFrame.origin.y = backgroundFrame.minY + 1.0
}
if let shareButtonOffset = shareButtonOffset {
if incoming {
buttonFrame.origin.x = shareButtonOffset.x
@ -3902,6 +3907,11 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
let buttonSize = shareButtonNode.update(presentationData: item.presentationData, controllerInteraction: item.controllerInteraction, chatLocation: item.chatLocation, subject: item.associatedData.subject, message: item.message, account: item.context.account, disableComments: disablesComments)
var buttonFrame = CGRect(origin: CGPoint(x: !incoming ? backgroundFrame.minX - buttonSize.width - 8.0 : backgroundFrame.maxX + 8.0, y: backgroundFrame.maxY - buttonSize.width - 1.0), size: buttonSize)
if item.message.adAttribute != nil {
buttonFrame.origin.y = backgroundFrame.minY + 1.0
}
if let shareButtonOffset = shareButtonOffset {
if incoming {
buttonFrame.origin.x = shareButtonOffset.x
@ -4941,7 +4951,9 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
@objc private func shareButtonPressed() {
if let item = self.item {
if case .pinnedMessages = item.associatedData.subject {
if item.message.adAttribute != nil {
item.controllerInteraction.openNoAdsDemo()
} else if case .pinnedMessages = item.associatedData.subject {
item.controllerInteraction.navigateToMessageStandalone(item.content.firstMessage.id)
} else if item.content.firstMessage.id.peerId.isRepliesOrSavedMessages(accountPeerId: item.context.account.peerId) {
for attribute in item.content.firstMessage.attributes {

View File

@ -65,7 +65,10 @@ public class ChatMessageShareButton: HighlightableButtonNode {
var updatedIconImage: UIImage?
var updatedIconOffset = CGPoint()
if case .pinnedMessages = subject {
if message.adAttribute != nil {
updatedIconImage = PresentationResourcesChat.chatFreeCloseButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
updatedIconOffset = CGPoint(x: UIScreenPixel, y: UIScreenPixel)
} else if case .pinnedMessages = subject {
updatedIconImage = PresentationResourcesChat.chatFreeNavigateButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
updatedIconOffset = CGPoint(x: UIScreenPixel, y: 1.0)
} else if isReplies {

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "close.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,83 @@
%PDF-1.7
1 0 obj
<< >>
endobj
2 0 obj
<< /Length 3 0 R >>
stream
/DeviceRGB CS
/DeviceRGB cs
q
1.000000 0.000000 -0.000000 1.000000 0.000000 -0.181641 cm
0.000000 0.000000 0.000000 scn
12.589408 1.771262 m
12.952986 1.407684 12.952986 0.818207 12.589408 0.454629 c
12.225830 0.091051 11.636353 0.091051 11.272775 0.454629 c
6.431122 5.296282 l
1.589316 0.454476 l
1.225738 0.090899 0.636262 0.090899 0.272684 0.454476 c
-0.090895 0.818054 -0.090895 1.407532 0.272684 1.771110 c
5.114489 6.612915 l
0.272775 11.454629 l
-0.090803 11.818207 -0.090803 12.407684 0.272775 12.771262 c
0.636353 13.134840 1.225830 13.134840 1.589408 12.771262 c
6.431122 7.929548 l
11.272683 12.771110 l
11.636261 13.134687 12.225739 13.134687 12.589316 12.771110 c
12.952894 12.407532 12.952894 11.818054 12.589316 11.454476 c
7.747756 6.612915 l
12.589408 1.771262 l
h
f*
n
Q
endstream
endobj
3 0 obj
790
endobj
4 0 obj
<< /Annots []
/Type /Page
/MediaBox [ 0.000000 0.000000 12.862061 12.862305 ]
/Resources 1 0 R
/Contents 2 0 R
/Parent 5 0 R
>>
endobj
5 0 obj
<< /Kids [ 4 0 R ]
/Count 1
/Type /Pages
>>
endobj
6 0 obj
<< /Pages 5 0 R
/Type /Catalog
>>
endobj
xref
0 7
0000000000 65535 f
0000000010 00000 n
0000000034 00000 n
0000000880 00000 n
0000000902 00000 n
0000001075 00000 n
0000001149 00000 n
trailer
<< /ID [ (some) (id) ]
/Root 6 0 R
/Size 7
>>
startxref
1208
%%EOF