mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Progress indicators
This commit is contained in:
@@ -39,6 +39,7 @@ swift_library(
|
||||
"//submodules/TelegramUI/Components/WallpaperPreviewMedia",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageAttachedContentButtonNode",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessagePollBubbleContentNode",
|
||||
"//submodules/TelegramUI/Components/Chat/MessageInlineBlockBackgroundView",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
||||
@@ -28,6 +28,7 @@ import ChatMessageInteractiveFileNode
|
||||
import ChatMessageInteractiveMediaNode
|
||||
import WallpaperPreviewMedia
|
||||
import ChatMessageAttachedContentButtonNode
|
||||
import MessageInlineBlockBackgroundView
|
||||
|
||||
public enum ChatMessageAttachedContentActionIcon {
|
||||
case instant
|
||||
@@ -52,8 +53,7 @@ public struct ChatMessageAttachedContentNodeMediaFlags: OptionSet {
|
||||
}
|
||||
|
||||
public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
private var backgroundView: UIImageView?
|
||||
private var lineDashView: UIImageView?
|
||||
private var backgroundView: MessageInlineBlockBackgroundView?
|
||||
|
||||
private let transformContainer: ASDisplayNode
|
||||
private var title: TextNodeWithEntities?
|
||||
@@ -84,6 +84,8 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
public var activateAction: (() -> Void)?
|
||||
public var requestUpdateLayout: (() -> Void)?
|
||||
|
||||
private var currentProgressDisposable: Disposable?
|
||||
|
||||
public var defaultContentAction: () -> ChatMessageBubbleContentTapAction = { return ChatMessageBubbleContentTapAction(content: .none) }
|
||||
|
||||
public var visibility: ListViewItemNodeVisibility = .none {
|
||||
@@ -125,6 +127,20 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
|
||||
public typealias AsyncLayout = (_ presentationData: ChatPresentationData, _ automaticDownloadSettings: MediaAutoDownloadSettings, _ associatedData: ChatMessageItemAssociatedData, _ attributes: ChatMessageEntryAttributes, _ context: AccountContext, _ controllerInteraction: ChatControllerInteraction, _ message: Message, _ messageRead: Bool, _ chatLocation: ChatLocation, _ title: String?, _ subtitle: NSAttributedString?, _ text: String?, _ entities: [MessageTextEntity]?, _ media: (Media, ChatMessageAttachedContentNodeMediaFlags)?, _ mediaBadge: String?, _ actionIcon: ChatMessageAttachedContentActionIcon?, _ actionTitle: String?, _ displayLine: Bool, _ layoutConstants: ChatMessageItemLayoutConstants, _ preparePosition: ChatMessageBubblePreparePosition, _ constrainedSize: CGSize, _ animationCache: AnimationCache, _ animationRenderer: MultiAnimationRenderer) -> (CGFloat, (CGSize, ChatMessageBubbleContentPosition) -> (CGFloat, (CGFloat) -> (CGSize, (ListViewItemUpdateAnimation, Bool, ListViewItemApply?) -> Void)))
|
||||
|
||||
public func makeProgress() -> Promise<Bool> {
|
||||
let progress = Promise<Bool>()
|
||||
self.currentProgressDisposable?.dispose()
|
||||
self.currentProgressDisposable = (progress.get()
|
||||
|> distinctUntilChanged
|
||||
|> deliverOnMainQueue).start(next: { [weak self] hasProgress in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.backgroundView?.displayProgress = hasProgress
|
||||
})
|
||||
return progress
|
||||
}
|
||||
|
||||
public func asyncLayout() -> AsyncLayout {
|
||||
let makeTitleLayout = TextNodeWithEntities.asyncLayout(self.title)
|
||||
let makeSubtitleLayout = TextNodeWithEntities.asyncLayout(self.subtitle)
|
||||
@@ -167,31 +183,12 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
if !incoming {
|
||||
mainColor = messageTheme.accentTextColor
|
||||
if let _ = author?.nameColor?.dashColors.1 {
|
||||
secondaryColor = messageTheme.accentTextColor
|
||||
secondaryColor = .clear
|
||||
}
|
||||
} else {
|
||||
var authorNameColor: UIColor?
|
||||
// if [Namespaces.Peer.CloudGroup, Namespaces.Peer.CloudChannel].contains(message.id.peerId.namespace), author?.id.namespace == Namespaces.Peer.CloudUser {
|
||||
authorNameColor = author?.nameColor?.color
|
||||
secondaryColor = author?.nameColor?.dashColors.1
|
||||
|
||||
// if let rawAuthorNameColor = authorNameColor {
|
||||
// var dimColors = false
|
||||
// switch presentationData.theme.theme.name {
|
||||
// case .builtin(.nightAccent), .builtin(.night):
|
||||
// dimColors = true
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
// if dimColors {
|
||||
// var hue: CGFloat = 0.0
|
||||
// var saturation: CGFloat = 0.0
|
||||
// var brightness: CGFloat = 0.0
|
||||
// rawAuthorNameColor.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: nil)
|
||||
// authorNameColor = UIColor(hue: hue, saturation: saturation * 0.7, brightness: min(1.0, brightness * 1.2), alpha: 1.0)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
authorNameColor = author?.nameColor?.color
|
||||
secondaryColor = author?.nameColor?.dashColors.1
|
||||
|
||||
if let authorNameColor {
|
||||
mainColor = authorNameColor
|
||||
@@ -768,39 +765,18 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
if displayLine {
|
||||
let backgroundFrame = CGRect(origin: CGPoint(x: backgroundInsets.left, y: backgroundInsets.top), size: CGSize(width: actualSize.width - backgroundInsets.left - backgroundInsets.right, height: actualSize.height - backgroundInsets.top - backgroundInsets.bottom))
|
||||
|
||||
let backgroundView: UIImageView
|
||||
let backgroundView: MessageInlineBlockBackgroundView
|
||||
if let current = self.backgroundView {
|
||||
backgroundView = current
|
||||
animation.animator.updateFrame(layer: backgroundView.layer, frame: backgroundFrame, completion: nil)
|
||||
} else {
|
||||
backgroundView = UIImageView()
|
||||
backgroundView.image = PresentationResourcesChat.chatReplyBackgroundTemplateImage(presentationData.theme.theme, dashedOutgoing: !incoming && secondaryColor != nil)
|
||||
backgroundView = MessageInlineBlockBackgroundView()
|
||||
self.backgroundView = backgroundView
|
||||
backgroundView.frame = backgroundFrame
|
||||
self.transformContainer.view.insertSubview(backgroundView, at: 0)
|
||||
}
|
||||
|
||||
backgroundView.tintColor = mainColor
|
||||
|
||||
if let secondaryColor {
|
||||
let lineDashView: UIImageView
|
||||
if let current = self.lineDashView {
|
||||
lineDashView = current
|
||||
} else {
|
||||
lineDashView = UIImageView(image: PresentationResourcesChat.chatReplyLineDashTemplateImage(presentationData.theme.theme, incoming: incoming))
|
||||
lineDashView.clipsToBounds = true
|
||||
self.lineDashView = lineDashView
|
||||
self.transformContainer.view.insertSubview(lineDashView, aboveSubview: backgroundView)
|
||||
}
|
||||
lineDashView.tintColor = secondaryColor
|
||||
lineDashView.frame = CGRect(origin: backgroundFrame.origin, size: CGSize(width: 12.0, height: backgroundFrame.height))
|
||||
lineDashView.layer.cornerRadius = 6.0
|
||||
} else {
|
||||
if let lineDashView = self.lineDashView {
|
||||
self.lineDashView = nil
|
||||
lineDashView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
backgroundView.update(size: backgroundFrame.size, primaryColor: mainColor, secondaryColor: secondaryColor, pattern: nil, animation: animation)
|
||||
} else {
|
||||
if let backgroundView = self.backgroundView {
|
||||
self.backgroundView = nil
|
||||
|
||||
Reference in New Issue
Block a user