From f4aaf08e8c1b526a0b4b5c2bd044b59186c33fff Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 12 Nov 2024 00:30:39 +0400 Subject: [PATCH] Various fixes --- .../PremiumPeerShortcutComponent/BUILD | 2 + .../PremiumPeerShortcutComponent.swift | 44 ++++++++++++++++++- .../WebUI/Sources/WebAppController.swift | 2 +- .../Sources/WebAppMessagePreviewScreen.swift | 3 ++ .../Sources/WebAppSetEmojiStatusScreen.swift | 12 +++-- 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/BUILD b/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/BUILD index b59ef6283b..744c5c3c99 100644 --- a/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/BUILD +++ b/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/BUILD @@ -17,6 +17,8 @@ swift_library( "//submodules/AvatarNode", "//submodules/Components/MultilineTextComponent", "//submodules/AccountContext", + "//submodules/TelegramUI/Components/EmojiTextAttachmentView", + "//submodules/TextFormat", ], visibility = [ "//visibility:public", diff --git a/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/Sources/PremiumPeerShortcutComponent.swift b/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/Sources/PremiumPeerShortcutComponent.swift index d75f042acb..8cd41127c4 100644 --- a/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/Sources/PremiumPeerShortcutComponent.swift +++ b/submodules/TelegramUI/Components/PremiumPeerShortcutComponent/Sources/PremiumPeerShortcutComponent.swift @@ -7,6 +7,8 @@ import TelegramPresentationData import AccountContext import AvatarNode import MultilineTextComponent +import EmojiTextAttachmentView +import TextFormat public final class PremiumPeerShortcutComponent: Component { let context: AccountContext @@ -43,6 +45,7 @@ public final class PremiumPeerShortcutComponent: Component { private let backgroundView = UIView() private let avatarNode: AvatarNode private let text = ComponentView() + private var animationLayer: InlineStickerItemLayer? private var component: PremiumPeerShortcutComponent? private weak var state: EmptyComponentState? @@ -88,7 +91,7 @@ public final class PremiumPeerShortcutComponent: Component { containerSize: CGSize(width: availableSize.width - 50.0, height: availableSize.height) ) - let size = CGSize(width: 30.0 + textSize.width + 20.0, height: 32.0) + var size = CGSize(width: 30.0 + textSize.width + 20.0, height: 32.0) if let view = self.text.view { if view.superview == nil { self.addSubview(view) @@ -97,6 +100,45 @@ public final class PremiumPeerShortcutComponent: Component { view.frame = textFrame } + if let icon = component.icon { + let iconSize = CGSize(width: 20.0, height: 20.0) + let iconSpacing: CGFloat = 2.0 + let animationLayer: InlineStickerItemLayer + if let current = self.animationLayer { + animationLayer = current + } else { + let emoji = ChatTextInputTextCustomEmojiAttribute( + interactivelySelectedFromPackId: nil, + fileId: icon.fileId.id, + file: icon + ) + animationLayer = InlineStickerItemLayer( + context: .account(component.context), + userLocation: .other, + attemptSynchronousLoad: false, + emoji: emoji, + file: icon, + cache: component.context.animationCache, + renderer: component.context.animationRenderer, + unique: true, + placeholderColor: component.theme.list.mediaPlaceholderColor, + pointSize: CGSize(width: 20.0, height: 20.0), + loopCount: 1 + ) + animationLayer.isVisibleForAnimations = true + if icon.isCustomTemplateEmoji { + animationLayer.dynamicColor = component.theme.actionSheet.controlAccentColor + } + self.layer.addSublayer(animationLayer) + self.animationLayer = animationLayer + } + animationLayer.frame = CGRect(origin: CGPoint(x: size.width - 7.0, y: floorToScreenPixels((size.height - iconSize.height) / 2.0)), size: iconSize) + size.width += iconSize.width + iconSpacing + } else if let animationLayer = self.animationLayer { + self.animationLayer = nil + animationLayer.removeFromSuperlayer() + } + self.backgroundView.frame = CGRect(origin: .zero, size: size) return size diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 4658294252..c330308583 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -772,7 +772,7 @@ public final class WebAppController: ViewController, AttachmentContainable { if controller.isFullscreen { customInsets.top = layout.statusBarHeight ?? 0.0 } - if layout.intrinsicInsets.bottom > 44.0 { + if layout.intrinsicInsets.bottom > 44.0 || (layout.inputHeight ?? 0.0) > 0.0 { customInsets.bottom = 0.0 } else { customInsets.bottom = layout.intrinsicInsets.bottom diff --git a/submodules/WebUI/Sources/WebAppMessagePreviewScreen.swift b/submodules/WebUI/Sources/WebAppMessagePreviewScreen.swift index 02f6ace094..a5289644f1 100644 --- a/submodules/WebUI/Sources/WebAppMessagePreviewScreen.swift +++ b/submodules/WebUI/Sources/WebAppMessagePreviewScreen.swift @@ -158,6 +158,9 @@ private final class SheetContent: CombinedComponent { case let .auto(textValue, entitiesValue, _): text = textValue entities = entitiesValue + if let content = reference.content { + media = [content] + } case let .text(textValue, entitiesValue, disableUrlPreview, previewParameters, _): text = textValue entities = entitiesValue diff --git a/submodules/WebUI/Sources/WebAppSetEmojiStatusScreen.swift b/submodules/WebUI/Sources/WebAppSetEmojiStatusScreen.swift index db35fbc387..182b5156f7 100644 --- a/submodules/WebUI/Sources/WebAppSetEmojiStatusScreen.swift +++ b/submodules/WebUI/Sources/WebAppSetEmojiStatusScreen.swift @@ -172,7 +172,8 @@ private final class SheetContent: CombinedComponent { component: PremiumPeerShortcutComponent( context: component.context, theme: theme, - peer: component.accountPeer + peer: component.accountPeer, + icon: component.file ), availableSize: CGSize(width: context.availableSize.width - 32.0, height: context.availableSize.height), transition: .immediate @@ -272,7 +273,8 @@ private final class WebAppSetEmojiStatusSheetComponent: CombinedComponent { file: context.component.file, dismiss: { animateOut.invoke(Action { _ in - if let controller = controller() { + if let controller = controller() as? WebAppSetEmojiStatusScreen { + controller.complete(result: false) controller.dismiss(completion: nil) } }) @@ -293,12 +295,14 @@ private final class WebAppSetEmojiStatusSheetComponent: CombinedComponent { dismiss: { animated in if animated { animateOut.invoke(Action { _ in - if let controller = controller() { + if let controller = controller() as? WebAppSetEmojiStatusScreen { + controller.complete(result: false) controller.dismiss(completion: nil) } }) } else { - if let controller = controller() { + if let controller = controller() as? WebAppSetEmojiStatusScreen { + controller.complete(result: false) controller.dismiss(completion: nil) } }