From 3095a6eb6ed4c5c867d0c1be5b66b1faa4812f50 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 6 Sep 2022 01:13:48 +0400 Subject: [PATCH] Reaction improvements --- .../Sources/ReactionContextNode.swift | 1 + .../EmojiStatusSelectionComponent.swift | 1 + .../Sources/EmojiPagerContentComponent.swift | 82 ++++++++++++++++++- .../TelegramUI/Sources/ChatController.swift | 4 + .../Sources/ChatEntityKeyboardInputNode.swift | 3 + 5 files changed, 87 insertions(+), 4 deletions(-) diff --git a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift index 5665fb27cf..e5b520cbb1 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift @@ -1180,6 +1180,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate { externalBackground: EmojiPagerContentComponent.ExternalBackground( effectContainerView: self.backgroundNode.vibrancyEffectView?.contentView ), + externalExpansionView: self.view, useOpaqueTheme: false ) } diff --git a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift index a805f7a6e9..9055218b40 100644 --- a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift +++ b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift @@ -345,6 +345,7 @@ public final class EmojiStatusSelectionController: ViewController { peekBehavior: nil, customLayout: nil, externalBackground: nil, + externalExpansionView: nil, useOpaqueTheme: true ) diff --git a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift index 1434b4b3a3..55c09f8237 100644 --- a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift +++ b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift @@ -1581,6 +1581,7 @@ public final class EmojiPagerContentComponent: Component { public let peekBehavior: EmojiContentPeekBehavior? public let customLayout: CustomLayout? public let externalBackground: ExternalBackground? + public let externalExpansionView: UIView? public let useOpaqueTheme: Bool public init( @@ -1599,6 +1600,7 @@ public final class EmojiPagerContentComponent: Component { peekBehavior: EmojiContentPeekBehavior?, customLayout: CustomLayout?, externalBackground: ExternalBackground?, + externalExpansionView: UIView?, useOpaqueTheme: Bool ) { self.performItemAction = performItemAction @@ -1616,6 +1618,7 @@ public final class EmojiPagerContentComponent: Component { self.peekBehavior = peekBehavior self.customLayout = customLayout self.externalBackground = externalBackground + self.externalExpansionView = externalExpansionView self.useOpaqueTheme = useOpaqueTheme } } @@ -2201,6 +2204,9 @@ public final class EmojiPagerContentComponent: Component { } } + final class CloneItemLayer: SimpleLayer { + } + public final class ItemLayer: MultiAnimationRenderTarget { public struct Key: Hashable { var groupId: AnyHashable @@ -2244,6 +2250,22 @@ public final class EmojiPagerContentComponent: Component { } public private(set) var displayPlaceholder: Bool = false public let onUpdateDisplayPlaceholder: (Bool, Double) -> Void + + weak var cloneLayer: CloneItemLayer? { + didSet { + if let cloneLayer = self.cloneLayer { + cloneLayer.contents = self.contents + } + } + } + + override public var contents: Any? { + didSet { + if let cloneLayer = self.cloneLayer { + cloneLayer.contents = self.contents + } + } + } public init( item: Item, @@ -3374,6 +3396,7 @@ public final class EmojiPagerContentComponent: Component { private let longPressDuration: Double = 0.5 private var longPressItem: EmojiPagerContentComponent.View.ItemLayer.Key? + private var currentLongPressLayer: CloneItemLayer? private var hapticFeedback: HapticFeedback? private var continuousHaptic: AnyObject? private var longPressTimer: SwiftSignalKit.Timer? @@ -3402,9 +3425,23 @@ public final class EmojiPagerContentComponent: Component { self.hapticFeedback = HapticFeedback() } - let _ = itemLayer - //let transition = Transition(animation: .curve(duration: longPressDuration, curve: .easeInOut)) - //transition.setScale(layer: itemLayer, scale: 1.3) + if let externalExpansionView = self.component?.inputInteractionHolder.inputInteraction?.externalExpansionView { + if let currentLongPressLayer = self.currentLongPressLayer { + self.currentLongPressLayer = nil + currentLongPressLayer.removeFromSuperlayer() + } + let currentLongPressLayer = CloneItemLayer() + currentLongPressLayer.position = self.scrollView.layer.convert(itemLayer.position, to: externalExpansionView.layer) + currentLongPressLayer.bounds = itemLayer.convert(itemLayer.bounds, to: externalExpansionView.layer) + currentLongPressLayer.transform = itemLayer.transform + externalExpansionView.layer.addSublayer(currentLongPressLayer) + self.currentLongPressLayer = currentLongPressLayer + itemLayer.cloneLayer = currentLongPressLayer + + itemLayer.isHidden = true + let transition = Transition(animation: .curve(duration: longPressDuration, curve: .easeInOut)) + transition.setScale(layer: currentLongPressLayer, scale: 1.85) + } self.longPressTimer?.invalidate() self.longPressTimer = SwiftSignalKit.Timer(timeout: longPressDuration, repeat: false, completion: { [weak self] in @@ -3431,7 +3468,23 @@ public final class EmojiPagerContentComponent: Component { if let itemLayer = self.visibleItemLayers[itemKey] { let transition = Transition(animation: .curve(duration: 0.3, curve: .spring)) transition.setScale(layer: itemLayer, scale: 1.0) + + if let currentLongPressLayer = self.currentLongPressLayer { + self.currentLongPressLayer = nil + + let transition = Transition(animation: .curve(duration: 0.3, curve: .spring)) + transition.setScale(layer: currentLongPressLayer, scale: 1.0, completion: { [weak itemLayer, weak currentLongPressLayer] _ in + itemLayer?.isHidden = false + currentLongPressLayer?.removeFromSuperlayer() + }) + } + } else if let currentLongPressLayer = self.currentLongPressLayer { + self.currentLongPressLayer = nil + currentLongPressLayer.removeFromSuperlayer() } + } else if let currentLongPressLayer = self.currentLongPressLayer { + self.currentLongPressLayer = nil + currentLongPressLayer.removeFromSuperlayer() } case .ended: self.longPressTimer?.invalidate() @@ -3441,11 +3494,32 @@ public final class EmojiPagerContentComponent: Component { self.longPressItem = nil if let component = self.component, let itemLayer = self.visibleItemLayers[itemKey] { - component.inputInteractionHolder.inputInteraction?.performItemAction(itemKey.groupId, itemLayer.item, self, self.scrollView.convert(itemLayer.frame, to: self), itemLayer, true) + if let externalExpansionView = self.component?.inputInteractionHolder.inputInteraction?.externalExpansionView, let currentLongPressLayer = self.currentLongPressLayer { + component.inputInteractionHolder.inputInteraction?.performItemAction(itemKey.groupId, itemLayer.item, externalExpansionView, currentLongPressLayer.frame, currentLongPressLayer, true) + } else { + component.inputInteractionHolder.inputInteraction?.performItemAction(itemKey.groupId, itemLayer.item, self, self.scrollView.convert(itemLayer.frame, to: self), itemLayer, true) + } } else { if let itemLayer = self.visibleItemLayers[itemKey] { let transition = Transition(animation: .curve(duration: 0.3, curve: .spring)) transition.setScale(layer: itemLayer, scale: 1.0) + + if let currentLongPressLayer = self.currentLongPressLayer { + self.currentLongPressLayer = nil + + let transition = Transition(animation: .curve(duration: 0.3, curve: .spring)) + transition.setScale(layer: currentLongPressLayer, scale: 1.0, completion: { [weak itemLayer, weak currentLongPressLayer] _ in + itemLayer?.isHidden = false + currentLongPressLayer?.removeFromSuperlayer() + }) + } + } else if let currentLongPressLayer = self.currentLongPressLayer { + self.currentLongPressLayer = nil + + let transition = Transition(animation: .curve(duration: 0.3, curve: .spring)) + transition.setScale(layer: currentLongPressLayer, scale: 1.0, completion: { [weak currentLongPressLayer] _ in + currentLongPressLayer?.removeFromSuperlayer() + }) } } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 41de5f3e5b..708eba20b0 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -17031,6 +17031,10 @@ enum AllowedReactions { } func peerMessageAllowedReactions(context: AccountContext, message: Message) -> Signal { + if message.containsSecretMedia { + return .single(AllowedReactions.set(Set())) + } + return combineLatest( context.engine.data.get( TelegramEngine.EngineData.Item.Peer.Peer(id: message.id.peerId), diff --git a/submodules/TelegramUI/Sources/ChatEntityKeyboardInputNode.swift b/submodules/TelegramUI/Sources/ChatEntityKeyboardInputNode.swift index bd2bb99839..17b614b533 100644 --- a/submodules/TelegramUI/Sources/ChatEntityKeyboardInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatEntityKeyboardInputNode.swift @@ -1105,6 +1105,7 @@ final class ChatEntityKeyboardInputNode: ChatInputNode { peekBehavior: nil, customLayout: nil, externalBackground: nil, + externalExpansionView: nil, useOpaqueTheme: false ) @@ -1310,6 +1311,7 @@ final class ChatEntityKeyboardInputNode: ChatInputNode { peekBehavior: stickerPeekBehavior, customLayout: nil, externalBackground: nil, + externalExpansionView: nil, useOpaqueTheme: false ) @@ -2020,6 +2022,7 @@ final class EntityInputView: UIView, AttachmentTextInputPanelInputView, UIInputV peekBehavior: nil, customLayout: nil, externalBackground: nil, + externalExpansionView: nil, useOpaqueTheme: false )