mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-04-08 14:17:54 +00:00
Fixes
fix localeWithStrings globally (#30)
Fix badge on zoomed devices. closes #9
Hide channel bottom panel closes #27
Another attempt to fix badge on some Zoomed devices
Force System Share sheet tg://sg/debug
fixes for device badge
New Crowdin updates (#34)
* New translations sglocalizable.strings (Chinese Traditional)
* New translations sglocalizable.strings (Chinese Simplified)
* New translations sglocalizable.strings (Chinese Traditional)
Fix input panel hidden on selection (#31)
* added if check for selectionState != nil
* same order of subnodes
Revert "Fix input panel hidden on selection (#31)"
This reverts commit e8a8bb1496.
Fix input panel for channels Closes #37
Quickly share links with system's share menu
force tabbar when editing
increase height for correct animation
New translations sglocalizable.strings (Ukrainian) (#38)
Hide Post Story button
Fix 10.15.1
Fix archive option for long-tap
Enable in-app Safari
Disable some unsupported purchases
disableDeleteChatSwipeOption + refactor restart alert
Hide bot in suggestions list
Fix merge v11.0
Fix exceptions for safari webview controller
New Crowdin updates (#47)
* New translations sglocalizable.strings (Romanian)
* New translations sglocalizable.strings (French)
* New translations sglocalizable.strings (Spanish)
* New translations sglocalizable.strings (Afrikaans)
* New translations sglocalizable.strings (Arabic)
* New translations sglocalizable.strings (Catalan)
* New translations sglocalizable.strings (Czech)
* New translations sglocalizable.strings (Danish)
* New translations sglocalizable.strings (German)
* New translations sglocalizable.strings (Greek)
* New translations sglocalizable.strings (Finnish)
* New translations sglocalizable.strings (Hebrew)
* New translations sglocalizable.strings (Hungarian)
* New translations sglocalizable.strings (Italian)
* New translations sglocalizable.strings (Japanese)
* New translations sglocalizable.strings (Korean)
* New translations sglocalizable.strings (Dutch)
* New translations sglocalizable.strings (Norwegian)
* New translations sglocalizable.strings (Polish)
* New translations sglocalizable.strings (Portuguese)
* New translations sglocalizable.strings (Serbian (Cyrillic))
* New translations sglocalizable.strings (Swedish)
* New translations sglocalizable.strings (Turkish)
* New translations sglocalizable.strings (Vietnamese)
* New translations sglocalizable.strings (Indonesian)
* New translations sglocalizable.strings (Hindi)
* New translations sglocalizable.strings (Uzbek)
New Crowdin updates (#49)
* New translations sglocalizable.strings (Arabic)
* New translations sglocalizable.strings (Arabic)
New translations sglocalizable.strings (Russian) (#51)
Call confirmation
WIP Settings search
Settings Search
Localize placeholder
Update AccountUtils.swift
mark mutual contact
Align back context action to left
New Crowdin updates (#54)
* New translations sglocalizable.strings (Chinese Simplified)
* New translations sglocalizable.strings (Chinese Traditional)
* New translations sglocalizable.strings (Ukrainian)
Independent Playground app for simulator
New translations sglocalizable.strings (Ukrainian) (#55)
Playground UIKit base and controllers
Inject SwiftUI view with overflow to AsyncDisplayKit
Launch Playgound project on simulator
Create .swiftformat
Move Playground to example
Update .swiftformat
Init SwiftUIViewController
wip
New translations sglocalizable.strings (Chinese Traditional) (#57)
Xcode 16 fixes
Fix
New translations sglocalizable.strings (Italian) (#59)
New translations sglocalizable.strings (Chinese Simplified) (#63)
Force disable CallKit integration due to missing NSE Entitlement
Fix merge
Fix whole chat translator
Sweetpad config
Bump version
11.3.1 fixes
Mutual contact placement fix
Disable Video PIP swipe
Update versions.json
Fix PIP crash
291 lines
14 KiB
Swift
291 lines
14 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import AsyncDisplayKit
|
|
import Display
|
|
import TelegramPresentationData
|
|
import ChatControllerInteraction
|
|
import AccountContext
|
|
import TelegramCore
|
|
import Postbox
|
|
import WallpaperBackgroundNode
|
|
import ChatMessageItemCommon
|
|
|
|
public class ChatMessageShareButton: ASDisplayNode {
|
|
private var backgroundContent: WallpaperBubbleBackgroundNode?
|
|
private var backgroundBlurView: PortalView?
|
|
|
|
private let topButton: HighlightTrackingButtonNode
|
|
private let topIconNode: ASImageNode
|
|
private var topIconOffset = CGPoint()
|
|
|
|
private var bottomButton: HighlightTrackingButtonNode?
|
|
private var bottomIconNode: ASImageNode?
|
|
|
|
private var separatorNode: ASDisplayNode?
|
|
|
|
private var theme: PresentationTheme?
|
|
private var isReplies: Bool = false
|
|
private var hasMore: Bool = false
|
|
|
|
private var textNode: ImmediateTextNode?
|
|
|
|
private var absolutePosition: (CGRect, CGSize)?
|
|
|
|
public var pressed: (() -> Void)?
|
|
public var morePressed: (() -> Void)?
|
|
|
|
override public init() {
|
|
self.topButton = HighlightTrackingButtonNode()
|
|
self.topIconNode = ASImageNode()
|
|
self.topIconNode.displaysAsynchronously = false
|
|
|
|
super.init()
|
|
|
|
self.allowsGroupOpacity = true
|
|
|
|
self.addSubnode(self.topIconNode)
|
|
self.addSubnode(self.topButton)
|
|
|
|
self.topButton.addTarget(self, action: #selector(self.buttonPressed), forControlEvents: .touchUpInside)
|
|
self.topButton.highligthedChanged = { [weak self] highlighted in
|
|
guard let self else {
|
|
return
|
|
}
|
|
if highlighted {
|
|
self.topIconNode.layer.removeAnimation(forKey: "opacity")
|
|
self.topIconNode.alpha = 0.4
|
|
self.textNode?.layer.removeAnimation(forKey: "opacity")
|
|
self.textNode?.alpha = 0.4
|
|
} else {
|
|
self.topIconNode.alpha = 1.0
|
|
self.topIconNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
|
|
self.textNode?.alpha = 1.0
|
|
self.textNode?.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
|
|
}
|
|
}
|
|
}
|
|
|
|
required public init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc private func buttonPressed() {
|
|
self.pressed?()
|
|
}
|
|
|
|
@objc private func moreButtonPressed() {
|
|
self.morePressed?()
|
|
}
|
|
|
|
public func update(hasTranslation: Bool? = nil, presentationData: ChatPresentationData, controllerInteraction: ChatControllerInteraction, chatLocation: ChatLocation, subject: ChatControllerSubject?, message: Message, account: Account, disableComments: Bool = false) -> CGSize {
|
|
var isReplies = false
|
|
var replyCount = 0
|
|
if let channel = message.peers[message.id.peerId] as? TelegramChannel, case .broadcast = channel.info {
|
|
for attribute in message.attributes {
|
|
if let attribute = attribute as? ReplyThreadMessageAttribute {
|
|
replyCount = Int(attribute.count)
|
|
isReplies = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if case let .replyThread(replyThreadMessage) = chatLocation, replyThreadMessage.effectiveTopId == message.id {
|
|
replyCount = 0
|
|
isReplies = false
|
|
}
|
|
if disableComments {
|
|
replyCount = 0
|
|
isReplies = false
|
|
}
|
|
|
|
var hasMore = false
|
|
if let adAttribute = message.adAttribute, adAttribute.canReport {
|
|
hasMore = true
|
|
}
|
|
|
|
if self.theme !== presentationData.theme.theme || self.isReplies != isReplies || self.hasMore != hasMore {
|
|
self.theme = presentationData.theme.theme
|
|
self.isReplies = isReplies
|
|
self.hasMore = hasMore
|
|
|
|
var updatedIconImage: UIImage?
|
|
var updatedBottomIconImage: UIImage?
|
|
var updatedIconOffset = CGPoint()
|
|
if let _ = message.adAttribute {
|
|
updatedIconImage = PresentationResourcesChat.chatFreeCloseButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
|
|
updatedIconOffset = CGPoint(x: UIScreenPixel, y: UIScreenPixel)
|
|
|
|
if hasMore {
|
|
updatedBottomIconImage = PresentationResourcesChat.chatFreeMoreButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
|
|
}
|
|
} else if case let .customChatContents(contents) = subject, case .hashTagSearch = contents.kind {
|
|
updatedIconImage = PresentationResourcesChat.chatFreeNavigateButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
|
|
updatedIconOffset = CGPoint(x: UIScreenPixel, y: 1.0)
|
|
} else if let hasTranslation = hasTranslation {
|
|
updatedIconImage = PresentationResourcesChat.chatTranslateShareButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper, undoTranslate: hasTranslation)
|
|
} 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 {
|
|
updatedIconImage = PresentationResourcesChat.chatFreeCommentButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
|
|
} else if message.id.peerId.isRepliesOrSavedMessages(accountPeerId: account.peerId) {
|
|
updatedIconImage = PresentationResourcesChat.chatFreeNavigateButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
|
|
updatedIconOffset = CGPoint(x: UIScreenPixel, y: 1.0)
|
|
} else {
|
|
updatedIconImage = PresentationResourcesChat.chatFreeShareButtonIcon(presentationData.theme.theme, wallpaper: presentationData.theme.wallpaper)
|
|
}
|
|
|
|
self.topIconNode.image = updatedIconImage
|
|
self.topIconOffset = updatedIconOffset
|
|
|
|
if let updatedBottomIconImage {
|
|
let bottomButton: HighlightTrackingButtonNode
|
|
let bottomIconNode: ASImageNode
|
|
let separatorNode: ASDisplayNode
|
|
if let currentButton = self.bottomButton, let currentIcon = self.bottomIconNode, let currentSeparator = self.separatorNode {
|
|
bottomButton = currentButton
|
|
bottomIconNode = currentIcon
|
|
separatorNode = currentSeparator
|
|
} else {
|
|
bottomButton = HighlightTrackingButtonNode()
|
|
bottomButton.addTarget(self, action: #selector(self.moreButtonPressed), forControlEvents: .touchUpInside)
|
|
self.bottomButton = bottomButton
|
|
|
|
bottomIconNode = ASImageNode()
|
|
bottomIconNode.displaysAsynchronously = false
|
|
self.bottomIconNode = bottomIconNode
|
|
|
|
bottomButton.highligthedChanged = { [weak self] highlighted in
|
|
guard let self, let bottomIconNode = self.bottomIconNode else {
|
|
return
|
|
}
|
|
if highlighted {
|
|
bottomIconNode.layer.removeAnimation(forKey: "opacity")
|
|
bottomIconNode.alpha = 0.4
|
|
} else {
|
|
bottomIconNode.alpha = 1.0
|
|
bottomIconNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
|
|
}
|
|
}
|
|
|
|
separatorNode = ASDisplayNode()
|
|
self.separatorNode = separatorNode
|
|
|
|
self.addSubnode(separatorNode)
|
|
self.addSubnode(bottomIconNode)
|
|
self.addSubnode(bottomButton)
|
|
}
|
|
separatorNode.backgroundColor = bubbleVariableColor(variableColor: presentationData.theme.theme.chat.message.shareButtonForegroundColor, wallpaper: presentationData.theme.wallpaper).withAlphaComponent(0.15)
|
|
bottomIconNode.image = updatedBottomIconImage
|
|
} else {
|
|
self.bottomButton?.removeFromSupernode()
|
|
self.bottomButton = nil
|
|
self.bottomIconNode?.removeFromSupernode()
|
|
self.bottomIconNode = nil
|
|
self.separatorNode?.removeFromSupernode()
|
|
self.separatorNode = nil
|
|
}
|
|
}
|
|
var size = CGSize(width: 30.0, height: 30.0)
|
|
if hasMore {
|
|
size.height += 30.0
|
|
}
|
|
var offsetIcon = false
|
|
if isReplies, replyCount > 0 {
|
|
offsetIcon = true
|
|
|
|
let textNode: ImmediateTextNode
|
|
if let current = self.textNode {
|
|
textNode = current
|
|
} else {
|
|
textNode = ImmediateTextNode()
|
|
self.textNode = textNode
|
|
self.addSubnode(textNode)
|
|
}
|
|
|
|
let textColor = bubbleVariableColor(variableColor: presentationData.theme.theme.chat.message.shareButtonForegroundColor, wallpaper: presentationData.theme.wallpaper)
|
|
|
|
let countString: String
|
|
if replyCount >= 1000 * 1000 {
|
|
countString = "\(replyCount / 1000_000)M"
|
|
} else if replyCount >= 1000 {
|
|
countString = "\(replyCount / 1000)K"
|
|
} else {
|
|
countString = "\(replyCount)"
|
|
}
|
|
|
|
textNode.attributedText = NSAttributedString(string: countString, font: Font.regular(11.0), textColor: textColor)
|
|
let textSize = textNode.updateLayout(CGSize(width: 100.0, height: 100.0))
|
|
size.height += textSize.height - 1.0
|
|
textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: size.height - textSize.height - 4.0), size: textSize)
|
|
} else if let textNode = self.textNode {
|
|
self.textNode = nil
|
|
textNode.removeFromSupernode()
|
|
}
|
|
|
|
if self.backgroundBlurView == nil {
|
|
if let backgroundBlurView = controllerInteraction.presentationContext.backgroundNode?.makeFreeBackground() {
|
|
self.backgroundBlurView = backgroundBlurView
|
|
self.view.insertSubview(backgroundBlurView.view, at: 0)
|
|
|
|
backgroundBlurView.view.clipsToBounds = true
|
|
}
|
|
}
|
|
if let backgroundBlurView = self.backgroundBlurView {
|
|
backgroundBlurView.view.frame = CGRect(origin: CGPoint(), size: size)
|
|
backgroundBlurView.view.layer.cornerRadius = min(size.width, size.height) / 2.0
|
|
}
|
|
|
|
if let image = self.topIconNode.image {
|
|
self.topIconNode.frame = CGRect(origin: CGPoint(x: floor((size.width - image.size.width) / 2.0) + self.topIconOffset.x, y: floor((size.width - image.size.width) / 2.0) - (offsetIcon ? 1.0 : 0.0) + self.topIconOffset.y), size: image.size)
|
|
}
|
|
self.topButton.frame = CGRect(origin: .zero, size: CGSize(width: size.width, height: size.width))
|
|
|
|
if let bottomIconNode = self.bottomIconNode, let bottomButton = self.bottomButton, let bottomImage = bottomIconNode.image {
|
|
bottomIconNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - bottomImage.size.width) / 2.0), y: size.height - size.width + floorToScreenPixels((size.width - bottomImage.size.height) / 2.0)), size: bottomImage.size)
|
|
bottomButton.frame = CGRect(origin: CGPoint(x: 0.0, y: size.height - size.width), size: CGSize(width: size.width, height: size.width))
|
|
}
|
|
|
|
self.separatorNode?.frame = CGRect(origin: CGPoint(x: 0.0, y: size.height / 2.0), size: CGSize(width: size.width, height: 1.0 - UIScreenPixel))
|
|
|
|
if controllerInteraction.presentationContext.backgroundNode?.hasExtraBubbleBackground() == true {
|
|
if self.backgroundContent == nil, let backgroundContent = controllerInteraction.presentationContext.backgroundNode?.makeBubbleBackground(for: .free) {
|
|
backgroundContent.clipsToBounds = true
|
|
self.backgroundContent = backgroundContent
|
|
self.insertSubnode(backgroundContent, at: 0)
|
|
}
|
|
} else {
|
|
self.backgroundContent?.removeFromSupernode()
|
|
self.backgroundContent = nil
|
|
}
|
|
|
|
if let backgroundContent = self.backgroundContent {
|
|
//self.backgroundNode.isHidden = true
|
|
self.backgroundBlurView?.view.isHidden = true
|
|
backgroundContent.cornerRadius = min(size.width, size.height) / 2.0
|
|
backgroundContent.frame = CGRect(origin: CGPoint(), size: size)
|
|
if let (rect, containerSize) = self.absolutePosition {
|
|
var backgroundFrame = backgroundContent.frame
|
|
backgroundFrame.origin.x += rect.minX
|
|
backgroundFrame.origin.y += rect.minY
|
|
backgroundContent.update(rect: backgroundFrame, within: containerSize, transition: .immediate)
|
|
}
|
|
} else {
|
|
//self.backgroundNode.isHidden = false
|
|
self.backgroundBlurView?.view.isHidden = false
|
|
}
|
|
|
|
return size
|
|
}
|
|
|
|
public func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
|
|
self.absolutePosition = (rect, containerSize)
|
|
if let backgroundContent = self.backgroundContent {
|
|
var backgroundFrame = backgroundContent.frame
|
|
backgroundFrame.origin.x += rect.minX
|
|
backgroundFrame.origin.y += rect.minY
|
|
backgroundContent.update(rect: backgroundFrame, within: containerSize, transition: .immediate)
|
|
}
|
|
}
|
|
}
|