From d86112541fa7bfcc95cd32ddba4cc51066d60c86 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 2 Aug 2024 18:25:02 +0200 Subject: [PATCH] Various fixes --- .../Sources/AnimatedStickerNode.swift | 2 +- submodules/BrowserUI/Sources/BrowserScreen.swift | 15 +++++++++++---- .../DrawingUI/Sources/DrawingTextEntityView.swift | 12 ++++++++++++ .../Sources/LegacyPaintStickersContext.swift | 6 ++++-- .../Sources/EmojiTextAttachmentView.swift | 4 ++-- .../Sources/Drawing/DrawingTextEntity.swift | 12 ++++++++---- .../Sources/MultiAnimationRenderer.swift | 3 +++ 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift b/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift index 7e3ccaeb2a..d9eb6947ce 100644 --- a/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift +++ b/submodules/AnimatedStickerNode/Sources/AnimatedStickerNode.swift @@ -653,7 +653,7 @@ public final class DefaultAnimatedStickerNodeImpl: ASDisplayNode, AnimatedSticke strongSelf.frameUpdated(frame.index, frame.totalFrames) strongSelf.currentFrameIndex = frame.index - strongSelf.currentFrameCount = frame.totalFrames; + strongSelf.currentFrameCount = frame.totalFrames strongSelf.currentFrameRate = frameRate if frame.isLastFrame { diff --git a/submodules/BrowserUI/Sources/BrowserScreen.swift b/submodules/BrowserUI/Sources/BrowserScreen.swift index afd4755c0b..a6f0f5ef72 100644 --- a/submodules/BrowserUI/Sources/BrowserScreen.swift +++ b/submodules/BrowserUI/Sources/BrowserScreen.swift @@ -1328,7 +1328,8 @@ public class BrowserScreen: ViewController, MinimizableController { right: layout.safeInsets.right ), navigationBarHeight: navigationBarHeight, - scrollingPanelOffsetFraction: self.scrollingPanelOffsetFraction + scrollingPanelOffsetFraction: self.scrollingPanelOffsetFraction, + hasBottomPanel: !layout.metrics.isTablet || self.presentationState.isSearching ) )) ) @@ -1539,17 +1540,20 @@ private final class BrowserContentComponent: Component { let insets: UIEdgeInsets let navigationBarHeight: CGFloat let scrollingPanelOffsetFraction: CGFloat + let hasBottomPanel: Bool init( content: BrowserContent, insets: UIEdgeInsets, navigationBarHeight: CGFloat, - scrollingPanelOffsetFraction: CGFloat + scrollingPanelOffsetFraction: CGFloat, + hasBottomPanel: Bool ) { self.content = content self.insets = insets self.navigationBarHeight = navigationBarHeight self.scrollingPanelOffsetFraction = scrollingPanelOffsetFraction + self.hasBottomPanel = hasBottomPanel } static func ==(lhs: BrowserContentComponent, rhs: BrowserContentComponent) -> Bool { @@ -1565,6 +1569,9 @@ private final class BrowserContentComponent: Component { if lhs.scrollingPanelOffsetFraction != rhs.scrollingPanelOffsetFraction { return false } + if lhs.hasBottomPanel != rhs.hasBottomPanel { + return false + } return true } @@ -1584,9 +1591,9 @@ private final class BrowserContentComponent: Component { let collapsedHeight: CGFloat = 24.0 let topInset: CGFloat = component.navigationBarHeight * (1.0 - component.scrollingPanelOffsetFraction) + (component.insets.top + collapsedHeight) * component.scrollingPanelOffsetFraction - let bottomInset = (49.0 + component.insets.bottom) * (1.0 - component.scrollingPanelOffsetFraction) + let bottomInset = component.hasBottomPanel ? (49.0 + component.insets.bottom) * (1.0 - component.scrollingPanelOffsetFraction) : 0.0 let insets = UIEdgeInsets(top: topInset, left: component.insets.left, bottom: bottomInset, right: component.insets.right) - let fullInsets = UIEdgeInsets(top: component.insets.top + component.navigationBarHeight, left: component.insets.left, bottom: 49.0 + component.insets.bottom, right: component.insets.right) + let fullInsets = UIEdgeInsets(top: component.insets.top + component.navigationBarHeight, left: component.insets.left, bottom: component.hasBottomPanel ? 49.0 + component.insets.bottom : 0.0, right: component.insets.right) component.content.updateLayout(size: availableSize, insets: insets, fullInsets: fullInsets, safeInsets: component.insets, transition: transition) transition.setFrame(view: component.content, frame: CGRect(origin: .zero, size: availableSize)) diff --git a/submodules/DrawingUI/Sources/DrawingTextEntityView.swift b/submodules/DrawingUI/Sources/DrawingTextEntityView.swift index 4e9b833497..ce68e000e1 100644 --- a/submodules/DrawingUI/Sources/DrawingTextEntityView.swift +++ b/submodules/DrawingUI/Sources/DrawingTextEntityView.swift @@ -624,6 +624,15 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate } func getRenderSubEntities() -> [DrawingEntity] { + var explicitlyStaticStickers = Set() + if let customEmojiContainerView = self.customEmojiContainerView { + for (key, view) in customEmojiContainerView.emojiLayers { + if let view = view as? EmojiTextAttachmentView, let numFrames = view.contentLayer.numFrames, numFrames == 1 { + explicitlyStaticStickers.insert(key.id) + } + } + } + let textSize = self.textView.bounds.size let textPosition = self.textEntity.position let scale = self.textEntity.scale @@ -638,6 +647,9 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate let emojiTextPosition = emojiRect.center.offsetBy(dx: -textSize.width / 2.0, dy: -textSize.height / 2.0) let entity = DrawingStickerEntity(content: .file(.standalone(media: file), .sticker)) + if explicitlyStaticStickers.contains(file.fileId.id) { + entity.isExplicitlyStatic = true + } entity.referenceDrawingSize = CGSize(width: itemSize * 4.0, height: itemSize * 4.0) entity.scale = scale entity.position = textPosition.offsetBy( diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift index d6dbd05029..79d1597354 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift @@ -477,16 +477,18 @@ public final class LegacyPaintEntityRenderer: NSObject, TGPhotoPaintEntityRender } func lcm(_ x: Int64, _ y: Int64) -> Int64 { + let x = max(x, 1) + let y = max(y, 1) return x / gcd(x, y) * y } - + return combineLatest(durations) |> map { durations in var result: Double let minDuration: Double = 3.0 if durations.count > 1 { let reduced = durations.reduce(1.0) { lhs, rhs -> Double in - return Double(lcm(Int64(lhs * 10.0), Int64(rhs * 10.0))) + return Double(lcm(Int64(lhs * 100.0), Int64(rhs * 100.0))) } result = min(6.0, Double(reduced) / 10.0) } else if let duration = durations.first { diff --git a/submodules/TelegramUI/Components/EmojiTextAttachmentView/Sources/EmojiTextAttachmentView.swift b/submodules/TelegramUI/Components/EmojiTextAttachmentView/Sources/EmojiTextAttachmentView.swift index aa7488a964..6442a231f7 100644 --- a/submodules/TelegramUI/Components/EmojiTextAttachmentView/Sources/EmojiTextAttachmentView.swift +++ b/submodules/TelegramUI/Components/EmojiTextAttachmentView/Sources/EmojiTextAttachmentView.swift @@ -776,7 +776,7 @@ public final class InlineStickerItemLayer: MultiAnimationRenderTarget { } public final class EmojiTextAttachmentView: UIView { - private let contentLayer: InlineStickerItemLayer + public let contentLayer: InlineStickerItemLayer public var isActive: Bool = true { didSet { @@ -826,7 +826,7 @@ public final class EmojiTextAttachmentView: UIView { public final class CustomEmojiContainerView: UIView { private let emojiViewProvider: (ChatTextInputTextCustomEmojiAttribute) -> UIView? - private var emojiLayers: [InlineStickerItemLayer.Key: UIView] = [:] + public private(set) var emojiLayers: [InlineStickerItemLayer.Key: UIView] = [:] public init(emojiViewProvider: @escaping (ChatTextInputTextCustomEmojiAttribute) -> UIView?) { self.emojiViewProvider = emojiViewProvider diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift index 02407f5e43..b07bd48a15 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift @@ -88,11 +88,15 @@ public final class DrawingTextEntity: DrawingEntity, Codable { return true } var isAnimated = false - self.text.enumerateAttributes(in: NSMakeRange(0, self.text.length), options: [], using: { attributes, range, _ in - if let _ = attributes[ChatTextInputAttributes.customEmoji] as? ChatTextInputTextCustomEmojiAttribute { - isAnimated = true + + if let renderSubEntities = self.renderSubEntities { + for entity in renderSubEntities { + if entity.isAnimated { + isAnimated = true + break + } } - }) + } return isAnimated } diff --git a/submodules/TelegramUI/Components/MultiAnimationRenderer/Sources/MultiAnimationRenderer.swift b/submodules/TelegramUI/Components/MultiAnimationRenderer/Sources/MultiAnimationRenderer.swift index 0d010bdde4..1f39885a99 100644 --- a/submodules/TelegramUI/Components/MultiAnimationRenderer/Sources/MultiAnimationRenderer.swift +++ b/submodules/TelegramUI/Components/MultiAnimationRenderer/Sources/MultiAnimationRenderer.swift @@ -17,6 +17,7 @@ private var nextRenderTargetId: Int64 = 1 open class MultiAnimationRenderTarget: SimpleLayer { public let id: Int64 + public var numFrames: Int? let deinitCallbacks = Bag<() -> Void>() let updateStateCallbacks = Bag<() -> Void>() @@ -545,6 +546,7 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer { } target.contents = loadedFrame.image.cgImage + target.numFrames = item.numFrames if let blurredRepresentationTarget = target.blurredRepresentationTarget { blurredRepresentationTarget.contents = loadedFrame.blurredRepresentation(color: target.blurredRepresentationBackgroundColor)?.cgImage @@ -580,6 +582,7 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer { completion(false, true) return } + target.numFrames = item.numFrames if let loadedFrame = loadedFrame { if let cgImage = loadedFrame.image.cgImage { if hadIntermediateUpdate {