Various fixes

This commit is contained in:
Ilya Laktyushin 2024-08-02 18:25:02 +02:00
parent 6266e0302a
commit d86112541f
7 changed files with 41 additions and 13 deletions

View File

@ -653,7 +653,7 @@ public final class DefaultAnimatedStickerNodeImpl: ASDisplayNode, AnimatedSticke
strongSelf.frameUpdated(frame.index, frame.totalFrames) strongSelf.frameUpdated(frame.index, frame.totalFrames)
strongSelf.currentFrameIndex = frame.index strongSelf.currentFrameIndex = frame.index
strongSelf.currentFrameCount = frame.totalFrames; strongSelf.currentFrameCount = frame.totalFrames
strongSelf.currentFrameRate = frameRate strongSelf.currentFrameRate = frameRate
if frame.isLastFrame { if frame.isLastFrame {

View File

@ -1328,7 +1328,8 @@ public class BrowserScreen: ViewController, MinimizableController {
right: layout.safeInsets.right right: layout.safeInsets.right
), ),
navigationBarHeight: navigationBarHeight, 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 insets: UIEdgeInsets
let navigationBarHeight: CGFloat let navigationBarHeight: CGFloat
let scrollingPanelOffsetFraction: CGFloat let scrollingPanelOffsetFraction: CGFloat
let hasBottomPanel: Bool
init( init(
content: BrowserContent, content: BrowserContent,
insets: UIEdgeInsets, insets: UIEdgeInsets,
navigationBarHeight: CGFloat, navigationBarHeight: CGFloat,
scrollingPanelOffsetFraction: CGFloat scrollingPanelOffsetFraction: CGFloat,
hasBottomPanel: Bool
) { ) {
self.content = content self.content = content
self.insets = insets self.insets = insets
self.navigationBarHeight = navigationBarHeight self.navigationBarHeight = navigationBarHeight
self.scrollingPanelOffsetFraction = scrollingPanelOffsetFraction self.scrollingPanelOffsetFraction = scrollingPanelOffsetFraction
self.hasBottomPanel = hasBottomPanel
} }
static func ==(lhs: BrowserContentComponent, rhs: BrowserContentComponent) -> Bool { static func ==(lhs: BrowserContentComponent, rhs: BrowserContentComponent) -> Bool {
@ -1565,6 +1569,9 @@ private final class BrowserContentComponent: Component {
if lhs.scrollingPanelOffsetFraction != rhs.scrollingPanelOffsetFraction { if lhs.scrollingPanelOffsetFraction != rhs.scrollingPanelOffsetFraction {
return false return false
} }
if lhs.hasBottomPanel != rhs.hasBottomPanel {
return false
}
return true return true
} }
@ -1584,9 +1591,9 @@ private final class BrowserContentComponent: Component {
let collapsedHeight: CGFloat = 24.0 let collapsedHeight: CGFloat = 24.0
let topInset: CGFloat = component.navigationBarHeight * (1.0 - component.scrollingPanelOffsetFraction) + (component.insets.top + collapsedHeight) * component.scrollingPanelOffsetFraction 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 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) 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)) transition.setFrame(view: component.content, frame: CGRect(origin: .zero, size: availableSize))

View File

@ -624,6 +624,15 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
} }
func getRenderSubEntities() -> [DrawingEntity] { func getRenderSubEntities() -> [DrawingEntity] {
var explicitlyStaticStickers = Set<Int64>()
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 textSize = self.textView.bounds.size
let textPosition = self.textEntity.position let textPosition = self.textEntity.position
let scale = self.textEntity.scale 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 emojiTextPosition = emojiRect.center.offsetBy(dx: -textSize.width / 2.0, dy: -textSize.height / 2.0)
let entity = DrawingStickerEntity(content: .file(.standalone(media: file), .sticker)) 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.referenceDrawingSize = CGSize(width: itemSize * 4.0, height: itemSize * 4.0)
entity.scale = scale entity.scale = scale
entity.position = textPosition.offsetBy( entity.position = textPosition.offsetBy(

View File

@ -477,16 +477,18 @@ public final class LegacyPaintEntityRenderer: NSObject, TGPhotoPaintEntityRender
} }
func lcm(_ x: Int64, _ y: Int64) -> Int64 { func lcm(_ x: Int64, _ y: Int64) -> Int64 {
let x = max(x, 1)
let y = max(y, 1)
return x / gcd(x, y) * y return x / gcd(x, y) * y
} }
return combineLatest(durations) return combineLatest(durations)
|> map { durations in |> map { durations in
var result: Double var result: Double
let minDuration: Double = 3.0 let minDuration: Double = 3.0
if durations.count > 1 { if durations.count > 1 {
let reduced = durations.reduce(1.0) { lhs, rhs -> Double in 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) result = min(6.0, Double(reduced) / 10.0)
} else if let duration = durations.first { } else if let duration = durations.first {

View File

@ -776,7 +776,7 @@ public final class InlineStickerItemLayer: MultiAnimationRenderTarget {
} }
public final class EmojiTextAttachmentView: UIView { public final class EmojiTextAttachmentView: UIView {
private let contentLayer: InlineStickerItemLayer public let contentLayer: InlineStickerItemLayer
public var isActive: Bool = true { public var isActive: Bool = true {
didSet { didSet {
@ -826,7 +826,7 @@ public final class EmojiTextAttachmentView: UIView {
public final class CustomEmojiContainerView: UIView { public final class CustomEmojiContainerView: UIView {
private let emojiViewProvider: (ChatTextInputTextCustomEmojiAttribute) -> 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?) { public init(emojiViewProvider: @escaping (ChatTextInputTextCustomEmojiAttribute) -> UIView?) {
self.emojiViewProvider = emojiViewProvider self.emojiViewProvider = emojiViewProvider

View File

@ -88,11 +88,15 @@ public final class DrawingTextEntity: DrawingEntity, Codable {
return true return true
} }
var isAnimated = false var isAnimated = false
self.text.enumerateAttributes(in: NSMakeRange(0, self.text.length), options: [], using: { attributes, range, _ in
if let _ = attributes[ChatTextInputAttributes.customEmoji] as? ChatTextInputTextCustomEmojiAttribute { if let renderSubEntities = self.renderSubEntities {
isAnimated = true for entity in renderSubEntities {
if entity.isAnimated {
isAnimated = true
break
}
} }
}) }
return isAnimated return isAnimated
} }

View File

@ -17,6 +17,7 @@ private var nextRenderTargetId: Int64 = 1
open class MultiAnimationRenderTarget: SimpleLayer { open class MultiAnimationRenderTarget: SimpleLayer {
public let id: Int64 public let id: Int64
public var numFrames: Int?
let deinitCallbacks = Bag<() -> Void>() let deinitCallbacks = Bag<() -> Void>()
let updateStateCallbacks = Bag<() -> Void>() let updateStateCallbacks = Bag<() -> Void>()
@ -545,6 +546,7 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer {
} }
target.contents = loadedFrame.image.cgImage target.contents = loadedFrame.image.cgImage
target.numFrames = item.numFrames
if let blurredRepresentationTarget = target.blurredRepresentationTarget { if let blurredRepresentationTarget = target.blurredRepresentationTarget {
blurredRepresentationTarget.contents = loadedFrame.blurredRepresentation(color: target.blurredRepresentationBackgroundColor)?.cgImage blurredRepresentationTarget.contents = loadedFrame.blurredRepresentation(color: target.blurredRepresentationBackgroundColor)?.cgImage
@ -580,6 +582,7 @@ public final class MultiAnimationRendererImpl: MultiAnimationRenderer {
completion(false, true) completion(false, true)
return return
} }
target.numFrames = item.numFrames
if let loadedFrame = loadedFrame { if let loadedFrame = loadedFrame {
if let cgImage = loadedFrame.image.cgImage { if let cgImage = loadedFrame.image.cgImage {
if hadIntermediateUpdate { if hadIntermediateUpdate {