From a645b57563566e7b2b24052505e55d8901b875ca Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 19 Oct 2022 21:23:10 +0300 Subject: [PATCH] Dark theme improvements --- .../Sources/ChatMessageBackground.swift | 25 ++++++++-- .../DefaultDarkPresentationTheme.swift | 20 ++++---- .../Sources/ChatControllerNode.swift | 5 +- .../ChatHistoryNavigationButtonNode.swift | 34 ++++++++++++- .../ChatHistoryNavigationButtons.swift | 49 ++++++++++++++----- .../ChatMessageAnimatedStickerItemNode.swift | 3 +- .../ChatMessageBubbleContentNode.swift | 3 +- .../Sources/ChatMessageBubbleItemNode.swift | 1 + .../ChatMessagePollBubbleContentNode.swift | 22 +++++++-- 9 files changed, 125 insertions(+), 37 deletions(-) diff --git a/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift b/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift index 35ffb48e3b..2adfdea6dc 100644 --- a/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift +++ b/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift @@ -60,6 +60,8 @@ public enum ChatMessageBackgroundType: Equatable { } public class ChatMessageBackground: ASDisplayNode { + public weak var backdropNode: ASDisplayNode? + public private(set) var type: ChatMessageBackgroundType? private var currentHighlighted: Bool? private var hasWallpaper: Bool? @@ -116,7 +118,7 @@ public class ChatMessageBackground: ASDisplayNode { self.backgroundNode = backgroundNode self.hasWallpaper = hasWallpaper - let image: UIImage? + var image: UIImage? switch type { case .none: @@ -227,7 +229,7 @@ public class ChatMessageBackground: ASDisplayNode { tempLayer.contentsGravity = self.imageNode.layer.contentsGravity tempLayer.contentsCenter = self.imageNode.layer.contentsCenter - tempLayer.frame = self.bounds + tempLayer.frame = self.imageNode.frame self.layer.insertSublayer(tempLayer, above: self.imageNode.layer) transition.updateAlpha(layer: tempLayer, alpha: 0.0, completion: { [weak tempLayer] _ in tempLayer?.removeFromSuperlayer() @@ -246,9 +248,11 @@ public class ChatMessageBackground: ASDisplayNode { tempLayer.rasterizationScale = self.imageNode.layer.rasterizationScale tempLayer.contentsGravity = self.imageNode.layer.contentsGravity tempLayer.contentsCenter = self.imageNode.layer.contentsCenter + tempLayer.compositingFilter = self.imageNode.layer.compositingFilter - tempLayer.frame = self.bounds - self.layer.insertSublayer(tempLayer, above: self.imageNode.layer) + tempLayer.frame = self.imageNode.frame + + self.imageNode.supernode?.layer.insertSublayer(tempLayer, above: self.imageNode.layer) transition.updateAlpha(layer: tempLayer, alpha: 0.0, completion: { [weak tempLayer] _ in tempLayer?.removeFromSuperlayer() }) @@ -257,6 +261,19 @@ public class ChatMessageBackground: ASDisplayNode { } self.imageNode.image = image + if highlighted && maskMode, let backdropNode = self.backdropNode { + self.imageNode.layer.compositingFilter = "overlayBlendMode" + self.imageNode.alpha = 1.0 + + backdropNode.addSubnode(self.imageNode) + } else { + self.imageNode.layer.compositingFilter = nil + self.imageNode.alpha = 1.0 + + if self.imageNode.supernode != self { + self.addSubnode(self.imageNode) + } + } self.outlineImageNode.image = outlineImage } diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index 154fa5571c..bf2855b54e 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -206,7 +206,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit fileTitleColor: accentColor, polls: chat.message.incoming.polls.withUpdated( radioProgress: accentColor, - highlight: accentColor?.withAlphaComponent(0.12), + highlight: UIColor(rgb: 0xffffff, alpha: 0.5), bar: accentColor, barIconForeground: accentColor.flatMap { accentColor -> UIColor in if accentColor.rgb == 0xffffff { @@ -261,7 +261,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit ), freeform: chat.message.freeform.withUpdated( withWallpaper: chat.message.freeform.withWallpaper.withUpdated( - reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.12), + reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.07), reactionInactiveForeground: UIColor(rgb: 0xffffff), reactionActiveBackground: accentColor, reactionActiveForeground: monochrome ? UIColor(rgb: 0x000000) : UIColor(rgb: 0xffffff), @@ -269,7 +269,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit reactionActiveMediaPlaceholder: UIColor(rgb: 0xffffff, alpha: 0.1) ), withoutWallpaper: chat.message.freeform.withoutWallpaper.withUpdated( - reactionInactiveBackground: chat.message.incoming.bubble.withoutWallpaper.fill.last, + reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.07), reactionInactiveForeground: UIColor(rgb: 0xffffff), reactionActiveBackground: accentColor, reactionActiveForeground: monochrome ? UIColor(rgb: 0x000000) : UIColor(rgb: 0xffffff), @@ -511,10 +511,10 @@ public func makeDefaultDarkPresentationTheme(extendingThemeReference: Presentati bubble: PresentationThemeBubbleColor( withWallpaper: PresentationThemeBubbleColorComponents( fill: [UIColor(rgb: 0x1D1D1D, alpha: incomingBubbleAlpha)], - highlightedFill: UIColor(rgb: 0x353539), + highlightedFill: UIColor(rgb: 0xffffff, alpha: 1.0), stroke: .clear, shadow: nil, - reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.1), + reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.07), reactionInactiveForeground: UIColor(rgb: 0xffffff), reactionActiveBackground: UIColor(rgb: 0xffffff, alpha: 1.0), reactionActiveForeground: .clear, @@ -523,10 +523,10 @@ public func makeDefaultDarkPresentationTheme(extendingThemeReference: Presentati ), withoutWallpaper: PresentationThemeBubbleColorComponents( fill: [UIColor(rgb: 0x1D1D1D, alpha: incomingBubbleAlpha)], - highlightedFill: UIColor(rgb: 0x353539), + highlightedFill: UIColor(rgb: 0xffffff, alpha: 1.0), stroke: .clear, shadow: nil, - reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.1), + reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.07), reactionInactiveForeground: UIColor(rgb: 0xffffff), reactionActiveBackground: UIColor(rgb: 0xffffff, alpha: 1.0), reactionActiveForeground: .clear, @@ -535,7 +535,7 @@ public func makeDefaultDarkPresentationTheme(extendingThemeReference: Presentati ) ), primaryTextColor: UIColor(rgb: 0xffffff), - secondaryTextColor: UIColor(rgb: 0xffffff, alpha: 0.5), linkTextColor: UIColor(rgb: 0xffffff), linkHighlightColor: UIColor(rgb: 0xffffff, alpha: 0.5), scamColor: UIColor(rgb: 0xeb5545), textHighlightColor: UIColor(rgb: 0xf5c038), accentTextColor: UIColor(rgb: 0xffffff), accentControlColor: UIColor(rgb: 0xffffff), accentControlDisabledColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaActiveControlColor: UIColor(rgb: 0xffffff), mediaInactiveControlColor: UIColor(rgb: 0xffffff, alpha: 0.4), mediaControlInnerBackgroundColor: UIColor(rgb: 0x262628), pendingActivityColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileTitleColor: UIColor(rgb: 0xffffff), fileDescriptionColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaPlaceholderColor: UIColor(rgb: 0x1f1f1f).mixedWith(UIColor(rgb: 0xffffff), alpha: 0.05), polls: PresentationThemeChatBubblePolls(radioButton: UIColor(rgb: 0x737373), radioProgress: UIColor(rgb: 0xffffff), highlight: UIColor(rgb: 0xffffff, alpha: 0.12), separator: UIColor(rgb: 0x000000), bar: UIColor(rgb: 0xffffff), barIconForeground: .clear, barPositive: UIColor(rgb: 0x00A700), barNegative: UIColor(rgb: 0xFE3824)), actionButtonsFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), actionButtonsStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), actionButtonsTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)), textSelectionColor: UIColor(rgb: 0xffffff, alpha: 0.2), textSelectionKnobColor: UIColor(rgb: 0xffffff) + secondaryTextColor: UIColor(rgb: 0xffffff, alpha: 0.5), linkTextColor: UIColor(rgb: 0xffffff), linkHighlightColor: UIColor(rgb: 0xffffff, alpha: 0.5), scamColor: UIColor(rgb: 0xeb5545), textHighlightColor: UIColor(rgb: 0xf5c038), accentTextColor: UIColor(rgb: 0xffffff), accentControlColor: UIColor(rgb: 0xffffff), accentControlDisabledColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaActiveControlColor: UIColor(rgb: 0xffffff), mediaInactiveControlColor: UIColor(rgb: 0xffffff, alpha: 0.4), mediaControlInnerBackgroundColor: UIColor(rgb: 0x262628), pendingActivityColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileTitleColor: UIColor(rgb: 0xffffff), fileDescriptionColor: UIColor(rgb: 0xffffff, alpha: 0.5), fileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), mediaPlaceholderColor: UIColor(rgb: 0x1f1f1f).mixedWith(UIColor(rgb: 0xffffff), alpha: 0.05), polls: PresentationThemeChatBubblePolls(radioButton: UIColor(rgb: 0x737373), radioProgress: UIColor(rgb: 0xffffff), highlight: UIColor(rgb: 0xffffff, alpha: 0.5), separator: UIColor(rgb: 0x000000), bar: UIColor(rgb: 0xffffff), barIconForeground: .clear, barPositive: UIColor(rgb: 0x00A700), barNegative: UIColor(rgb: 0xFE3824)), actionButtonsFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), actionButtonsStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), actionButtonsTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)), textSelectionColor: UIColor(rgb: 0xffffff, alpha: 0.2), textSelectionKnobColor: UIColor(rgb: 0xffffff) ), outgoing: PresentationThemePartedColors( bubble: PresentationThemeBubbleColor( @@ -571,7 +571,7 @@ public func makeDefaultDarkPresentationTheme(extendingThemeReference: Presentati highlightedFill: UIColor(rgb: 0x2a2a2a), stroke: UIColor(rgb: 0x1f1f1f), shadow: nil, - reactionInactiveBackground: UIColor(rgb: 0x1f1f1f), + reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.07), reactionInactiveForeground: UIColor(rgb: 0xffffff), reactionActiveBackground: UIColor(rgb: 0xffffff, alpha: 1.0), reactionActiveForeground: .clear, @@ -583,7 +583,7 @@ public func makeDefaultDarkPresentationTheme(extendingThemeReference: Presentati highlightedFill: UIColor(rgb: 0x2a2a2a), stroke: UIColor(rgb: 0x1f1f1f), shadow: nil, - reactionInactiveBackground: UIColor(rgb: 0x1f1f1f), + reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.07), reactionInactiveForeground: UIColor(rgb: 0xffffff), reactionActiveBackground: UIColor(rgb: 0xffffff, alpha: 1.0), reactionActiveForeground: .clear, diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 4aab5705e0..c8f71da026 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -454,7 +454,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { self.inputPanelBottomBackgroundSeparatorNode.backgroundColor = self.chatPresentationInterfaceState.theme.chat.inputMediaPanel.panelSeparatorColor self.inputPanelBottomBackgroundSeparatorNode.isLayerBacked = true - self.navigateButtons = ChatHistoryNavigationButtons(theme: self.chatPresentationInterfaceState.theme, dateTimeFormat: self.chatPresentationInterfaceState.dateTimeFormat) + self.navigateButtons = ChatHistoryNavigationButtons(theme: self.chatPresentationInterfaceState.theme, dateTimeFormat: self.chatPresentationInterfaceState.dateTimeFormat, backgroundNode: self.backgroundNode) self.navigateButtons.accessibilityElementsHidden = true super.init() @@ -1764,6 +1764,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { transition.updateFrame(node: self.inputPanelBackgroundSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: apparentInputBackgroundFrame.origin.y), size: CGSize(width: apparentInputBackgroundFrame.size.width, height: UIScreenPixel))) transition.updateFrame(node: self.navigateButtons, frame: apparentNavigateButtonsFrame) + self.navigateButtons.update(rect: apparentNavigateButtonsFrame, within: layout.size, transition: transition) if let titleAccessoryPanelNode = self.titleAccessoryPanelNode, let titleAccessoryPanelFrame = titleAccessoryPanelFrame, !titleAccessoryPanelNode.frame.equalTo(titleAccessoryPanelFrame) { titleAccessoryPanelNode.frame = titleAccessoryPanelFrame @@ -2240,7 +2241,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { let updateInputTextState = self.chatPresentationInterfaceState.interfaceState.effectiveInputState != chatPresentationInterfaceState.interfaceState.effectiveInputState self.chatPresentationInterfaceState = chatPresentationInterfaceState - self.navigateButtons.update(theme: chatPresentationInterfaceState.theme, dateTimeFormat: chatPresentationInterfaceState.dateTimeFormat) + self.navigateButtons.update(theme: chatPresentationInterfaceState.theme, dateTimeFormat: chatPresentationInterfaceState.dateTimeFormat, backgroundNode: self.backgroundNode) if themeUpdated { if case let .color(color) = self.chatPresentationInterfaceState.chatWallpaper, UIColor(rgb: color).isEqual(self.chatPresentationInterfaceState.theme.chat.inputPanel.panelBackgroundColorNoWallpaper) { diff --git a/submodules/TelegramUI/Sources/ChatHistoryNavigationButtonNode.swift b/submodules/TelegramUI/Sources/ChatHistoryNavigationButtonNode.swift index ba35dfb352..47f5de3540 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryNavigationButtonNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryNavigationButtonNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramPresentationData +import WallpaperBackgroundNode private let badgeFont = Font.regular(13.0) @@ -16,6 +17,7 @@ class ChatHistoryNavigationButtonNode: ContextControllerSourceNode { let containerNode: ContextExtractedContentContainingNode private let buttonNode: HighlightTrackingButtonNode private let backgroundNode: NavigationBackgroundNode + private var backgroundContent: WallpaperBubbleBackgroundNode? private let imageNode: ASImageNode private let badgeBackgroundNode: ASImageNode private let badgeTextNode: ASTextNode @@ -43,7 +45,7 @@ class ChatHistoryNavigationButtonNode: ContextControllerSourceNode { private var theme: PresentationTheme private let type: ChatHistoryNavigationButtonType - init(theme: PresentationTheme, type: ChatHistoryNavigationButtonType) { + init(theme: PresentationTheme, backgroundNode: WallpaperBackgroundNode, type: ChatHistoryNavigationButtonType) { self.theme = theme self.type = type @@ -102,7 +104,7 @@ class ChatHistoryNavigationButtonNode: ContextControllerSourceNode { self.frame = CGRect(origin: CGPoint(), size: size) } - func updateTheme(theme: PresentationTheme) { + func updateTheme(theme: PresentationTheme, backgroundNode: WallpaperBackgroundNode) { if self.theme !== theme { self.theme = theme @@ -122,6 +124,34 @@ class ChatHistoryNavigationButtonNode: ContextControllerSourceNode { self.badgeTextNode.redrawIfPossible() } } + + if backgroundNode.hasExtraBubbleBackground() { + if self.backgroundContent == nil { + if let backgroundContent = backgroundNode.makeBubbleBackground(for: .free) { + backgroundContent.allowsGroupOpacity = true + backgroundContent.clipsToBounds = true + backgroundContent.alpha = 0.2 + backgroundContent.cornerRadius = 19.0 + backgroundContent.frame = self.backgroundNode.frame + self.buttonNode.insertSubnode(backgroundContent, aboveSubnode: self.backgroundNode) + self.backgroundContent = backgroundContent + } + } + } else { + self.backgroundContent?.removeFromSupernode() + self.backgroundContent = nil + } + + if let (rect, containerSize) = self.absoluteRect { + self.backgroundContent?.update(rect: rect, within: containerSize, transition: .immediate) + } + } + + private var absoluteRect: (CGRect, CGSize)? + func update(rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition) { + self.absoluteRect = (rect, containerSize) + + self.backgroundContent?.update(rect: rect, within: containerSize, transition: transition) } @objc func onTap() { diff --git a/submodules/TelegramUI/Sources/ChatHistoryNavigationButtons.swift b/submodules/TelegramUI/Sources/ChatHistoryNavigationButtons.swift index 633ca9810e..97053a85e2 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryNavigationButtons.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryNavigationButtons.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramPresentationData +import WallpaperBackgroundNode final class ChatHistoryNavigationButtons: ASDisplayNode { private var theme: PresentationTheme @@ -67,19 +68,19 @@ final class ChatHistoryNavigationButtons: ASDisplayNode { } } - init(theme: PresentationTheme, dateTimeFormat: PresentationDateTimeFormat) { + init(theme: PresentationTheme, dateTimeFormat: PresentationDateTimeFormat, backgroundNode: WallpaperBackgroundNode) { self.theme = theme self.dateTimeFormat = dateTimeFormat - self.mentionsButton = ChatHistoryNavigationButtonNode(theme: theme, type: .mentions) + self.mentionsButton = ChatHistoryNavigationButtonNode(theme: theme, backgroundNode: backgroundNode, type: .mentions) self.mentionsButton.alpha = 0.0 self.mentionsButton.isHidden = true - self.reactionsButton = ChatHistoryNavigationButtonNode(theme: theme, type: .reactions) + self.reactionsButton = ChatHistoryNavigationButtonNode(theme: theme, backgroundNode: backgroundNode, type: .reactions) self.reactionsButton.alpha = 0.0 self.reactionsButton.isHidden = true - self.downButton = ChatHistoryNavigationButtonNode(theme: theme, type: .down) + self.downButton = ChatHistoryNavigationButtonNode(theme: theme, backgroundNode: backgroundNode, type: .down) self.downButton.alpha = 0.0 self.downButton.isHidden = true @@ -104,15 +105,33 @@ final class ChatHistoryNavigationButtons: ASDisplayNode { super.didLoad() } - func update(theme: PresentationTheme, dateTimeFormat: PresentationDateTimeFormat) { - if self.theme !== theme || self.dateTimeFormat != dateTimeFormat { - self.theme = theme - self.dateTimeFormat = dateTimeFormat - - self.reactionsButton.updateTheme(theme: theme) - self.mentionsButton.updateTheme(theme: theme) - self.downButton.updateTheme(theme: theme) - } + func update(theme: PresentationTheme, dateTimeFormat: PresentationDateTimeFormat, backgroundNode: WallpaperBackgroundNode) { + self.theme = theme + self.dateTimeFormat = dateTimeFormat + + self.reactionsButton.updateTheme(theme: theme, backgroundNode: backgroundNode) + self.mentionsButton.updateTheme(theme: theme, backgroundNode: backgroundNode) + self.downButton.updateTheme(theme: theme, backgroundNode: backgroundNode) + } + + private var absoluteRect: (CGRect, CGSize)? + func update(rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition) { + self.absoluteRect = (rect, containerSize) + + var reactionsFrame = self.reactionsButton.frame + reactionsFrame.origin.x += rect.minX + reactionsFrame.origin.y += rect.minY + self.reactionsButton.update(rect: reactionsFrame, within: containerSize, transition: transition) + + var mentionsFrame = self.mentionsButton.frame + mentionsFrame.origin.x += rect.minX + mentionsFrame.origin.y += rect.minY + self.mentionsButton.update(rect: mentionsFrame, within: containerSize, transition: transition) + + var downFrame = self.downButton.frame + downFrame.origin.x += rect.minX + downFrame.origin.y += rect.minY + self.downButton.update(rect: downFrame, within: containerSize, transition: transition) } func updateLayout(transition: ContainedViewLayoutTransition) -> CGSize { @@ -173,6 +192,10 @@ final class ChatHistoryNavigationButtons: ASDisplayNode { transition.updatePosition(node: self.reactionsButton, position: CGRect(origin: CGPoint(x: 0.0, y: completeSize.height - buttonSize.height - mentionsOffset - reactionsOffset), size: buttonSize).center) + if let (rect, containerSize) = self.absoluteRect { + self.update(rect: rect, within: containerSize, transition: transition) + } + return completeSize } diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index e374afb19a..c4e7adcdea 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -76,6 +76,8 @@ class ChatMessageShareButton: HighlightableButtonNode { super.init(pointerStyle: nil) + self.allowsGroupOpacity = true + self.addSubnode(self.backgroundNode) self.addSubnode(self.iconNode) } @@ -169,7 +171,6 @@ class ChatMessageShareButton: HighlightableButtonNode { if controllerInteraction.presentationContext.backgroundNode?.hasExtraBubbleBackground() == true { if self.backgroundContent == nil, let backgroundContent = controllerInteraction.presentationContext.backgroundNode?.makeBubbleBackground(for: .free) { backgroundContent.clipsToBounds = true - backgroundContent.allowsGroupOpacity = true self.backgroundContent = backgroundContent self.insertSubnode(backgroundContent, at: 0) } diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleContentNode.swift index 65d8d357eb..a13b92843f 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleContentNode.swift @@ -7,6 +7,7 @@ import TelegramCore import TelegramUIPreferences import TelegramPresentationData import AccountContext +import ChatMessageBackground enum ChatMessageBubbleContentBackgroundHiding { case never @@ -134,7 +135,7 @@ class ChatMessageBubbleContentNode: ASDisplayNode { return false } - weak var bubbleBackgroundNode: ASDisplayNode? + weak var bubbleBackgroundNode: ChatMessageBackground? var visibility: ListViewItemNodeVisibility = .none diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift index 596dbd9398..3a8f54710c 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift @@ -571,6 +571,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode self.contentContainersWrapperNode = ASDisplayNode() self.backgroundNode = ChatMessageBackground() + self.backgroundNode.backdropNode = self.backgroundWallpaperNode self.shadowNode = ChatMessageShadowNode() self.clippingNode = ChatMessageBubbleClippingNode() diff --git a/submodules/TelegramUI/Sources/ChatMessagePollBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessagePollBubbleContentNode.swift index f9ae0f5c2f..a0e6ea40fc 100644 --- a/submodules/TelegramUI/Sources/ChatMessagePollBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessagePollBubbleContentNode.swift @@ -10,6 +10,7 @@ import SwiftSignalKit import AccountContext import AvatarNode import TelegramPresentationData +import ChatMessageBackground func isPollEffectivelyClosed(message: Message, poll: TelegramMediaPoll) -> Bool { if poll.isClosed { @@ -512,7 +513,7 @@ private final class ChatMessagePollOptionNode: ASDisplayNode { self.percentageNode.isLayerBacked = true super.init() - + self.addSubnode(self.highlightedBackgroundNode) self.addSubnode(self.separatorNode) self.addSubnode(self.resultBarNode) @@ -524,6 +525,12 @@ private final class ChatMessagePollOptionNode: ASDisplayNode { self.buttonNode.highligthedChanged = { [weak self] highlighted in if let strongSelf = self { if highlighted { + if "".isEmpty, let contentNode = strongSelf.supernode as? ChatMessagePollBubbleContentNode, let backdropNode = contentNode.bubbleBackgroundNode?.backdropNode { + strongSelf.highlightedBackgroundNode.layer.compositingFilter = "overlayBlendMode" + strongSelf.highlightedBackgroundNode.frame = strongSelf.view.convert(strongSelf.highlightedBackgroundNode.frame, to: backdropNode.view) + backdropNode.addSubnode(strongSelf.highlightedBackgroundNode) + } + strongSelf.highlightedBackgroundNode.layer.removeAnimation(forKey: "opacity") strongSelf.highlightedBackgroundNode.alpha = 1.0 @@ -534,7 +541,13 @@ private final class ChatMessagePollOptionNode: ASDisplayNode { strongSelf.previousOptionNode?.separatorNode.alpha = 0.0 } else { strongSelf.highlightedBackgroundNode.alpha = 0.0 - strongSelf.highlightedBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3) + strongSelf.highlightedBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, completion: { finished in + if finished && strongSelf.highlightedBackgroundNode.supernode != strongSelf { + strongSelf.highlightedBackgroundNode.layer.compositingFilter = nil + strongSelf.highlightedBackgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -UIScreenPixel), size: strongSelf.highlightedBackgroundNode.frame.size) + strongSelf.insertSubnode(strongSelf.highlightedBackgroundNode, at: 0) + } + }) strongSelf.separatorNode.alpha = 1.0 strongSelf.separatorNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) @@ -733,8 +746,9 @@ private final class ChatMessagePollOptionNode: ASDisplayNode { } node.buttonNode.frame = CGRect(origin: CGPoint(x: 1.0, y: 0.0), size: CGSize(width: width - 2.0, height: contentHeight)) - node.highlightedBackgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -UIScreenPixel), size: CGSize(width: width, height: contentHeight + UIScreenPixel)) - + if node.highlightedBackgroundNode.supernode == node { + node.highlightedBackgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -UIScreenPixel), size: CGSize(width: width, height: contentHeight + UIScreenPixel)) + } node.separatorNode.backgroundColor = incoming ? presentationData.theme.theme.chat.message.incoming.polls.separator : presentationData.theme.theme.chat.message.outgoing.polls.separator node.separatorNode.frame = CGRect(origin: CGPoint(x: leftInset, y: contentHeight - UIScreenPixel), size: CGSize(width: width - leftInset, height: UIScreenPixel))