Fix snapshotting

This commit is contained in:
Ali 2023-11-11 17:48:00 +04:00
parent c2c0584dc9
commit 770cadf544
8 changed files with 40 additions and 10 deletions

View File

@ -2028,12 +2028,11 @@ xcodeproj(
"Debug": { "Debug": {
"//command_line_option:compilation_mode": "dbg", "//command_line_option:compilation_mode": "dbg",
}, },
#"Release": { "Release": {
# "//command_line_option:compilation_mode": "opt", "//command_line_option:compilation_mode": "opt",
#}, },
}, },
default_xcode_configuration = "Debug" default_xcode_configuration = "Debug"
) )
# Temporary targets used to simplify webrtc build tests # Temporary targets used to simplify webrtc build tests

View File

@ -2435,17 +2435,22 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
} }
if node.index == nil { if node.index == nil {
var duration = insertionAnimationDuration
if let value = self.customItemDeleteAnimationDuration(itemNode: node) {
duration = value
}
if node.animationForKey("height") == nil || !(node is ListViewTempItemNode) { if node.animationForKey("height") == nil || !(node is ListViewTempItemNode) {
node.addHeightAnimation(0.0, duration: insertionAnimationDuration * UIView.animationDurationFactor(), beginAt: timestamp) node.addHeightAnimation(0.0, duration: duration * UIView.animationDurationFactor(), beginAt: timestamp)
} }
if node.animationForKey("apparentHeight") == nil || !(node is ListViewTempItemNode) { if node.animationForKey("apparentHeight") == nil || !(node is ListViewTempItemNode) {
node.addApparentHeightAnimation(0.0, duration: insertionAnimationDuration * UIView.animationDurationFactor(), beginAt: timestamp, update: { [weak node] progress, currentValue in node.addApparentHeightAnimation(0.0, duration: duration * UIView.animationDurationFactor(), beginAt: timestamp, update: { [weak node] progress, currentValue in
if let node = node { if let node = node {
node.animateFrameTransition(progress, currentValue) node.animateFrameTransition(progress, currentValue)
} }
}) })
} }
node.animateRemoved(timestamp, duration: insertionAnimationDuration * UIView.animationDurationFactor()) node.animateRemoved(timestamp, duration: duration * UIView.animationDurationFactor())
} else if animated { } else if animated {
if takenAnimation { if takenAnimation {
if let previousFrame = previousFrame { if let previousFrame = previousFrame {
@ -5041,6 +5046,10 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
} }
return self.scrollWithDirection(scrollDirection, distance: distance) return self.scrollWithDirection(scrollDirection, distance: distance)
} }
open func customItemDeleteAnimationDuration(itemNode: ListViewItemNode) -> Double? {
return nil
}
} }
private func findAccessibilityFocus(_ node: ASDisplayNode) -> Bool { private func findAccessibilityFocus(_ node: ASDisplayNode) -> Bool {

View File

@ -954,6 +954,7 @@ public final class MetalEngine {
} }
} }
#if DEBUG
#if targetEnvironment(simulator) #if targetEnvironment(simulator)
if #available(iOS 13.0, *) { if #available(iOS 13.0, *) {
if let drawable = self.layer.nextDrawable() { if let drawable = self.layer.nextDrawable() {
@ -965,6 +966,7 @@ public final class MetalEngine {
commandBuffer.present(drawable) commandBuffer.present(drawable)
} }
#endif #endif
#endif
commandBuffer.commit() commandBuffer.commit()
commandBuffer.waitUntilScheduled() commandBuffer.waitUntilScheduled()

View File

@ -80,6 +80,7 @@ swift_library(
"//submodules/TelegramUI/Components/Chat/ChatMessageGiftBubbleContentNode", "//submodules/TelegramUI/Components/Chat/ChatMessageGiftBubbleContentNode",
"//submodules/TelegramUI/Components/Chat/ChatMessageGiveawayBubbleContentNode", "//submodules/TelegramUI/Components/Chat/ChatMessageGiveawayBubbleContentNode",
"//submodules/TelegramUI/Components/Chat/ChatMessageJoinedChannelBubbleContentNode", "//submodules/TelegramUI/Components/Chat/ChatMessageJoinedChannelBubbleContentNode",
"//submodules/UIKitRuntimeUtils",
], ],
visibility = [ visibility = [
"//visibility:public", "//visibility:public",

View File

@ -70,6 +70,7 @@ import ChatMessageWallpaperBubbleContentNode
import ChatMessageGiftBubbleContentNode import ChatMessageGiftBubbleContentNode
import ChatMessageGiveawayBubbleContentNode import ChatMessageGiveawayBubbleContentNode
import ChatMessageJoinedChannelBubbleContentNode import ChatMessageJoinedChannelBubbleContentNode
import UIKitRuntimeUtils
private struct BubbleItemAttributes { private struct BubbleItemAttributes {
var isAttachment: Bool var isAttachment: Bool
@ -5387,9 +5388,8 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
UIGraphicsBeginImageContextWithOptions(self.backgroundNode.view.bounds.size, false, 0.0) UIGraphicsBeginImageContextWithOptions(self.backgroundNode.view.bounds.size, false, 0.0)
let context = UIGraphicsGetCurrentContext()! let context = UIGraphicsGetCurrentContext()!
context.translateBy(x: -self.backgroundNode.frame.minX, y: -self.insets.top - self.backgroundNode.frame.minY) context.translateBy(x: -self.backgroundNode.frame.minX, y: -self.backgroundNode.frame.minY)
self.view.layer.render(in: context)
self.view.drawHierarchy(in: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: self.view.bounds.size), afterScreenUpdates: false)
let image = UIGraphicsGetImageFromCurrentImageContext() let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext() UIGraphicsEndImageContext()

View File

@ -4018,4 +4018,17 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
self.view.layer.animatePosition(from: CGPoint(x: 0.0, y: self.view.bounds.height + snapshotTopInset), to: CGPoint(), duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: true, additive: true) self.view.layer.animatePosition(from: CGPoint(x: 0.0, y: self.view.bounds.height + snapshotTopInset), to: CGPoint(), duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: true, additive: true)
} }
override public func customItemDeleteAnimationDuration(itemNode: ListViewItemNode) -> Double? {
if let currentDeleteAnimationCorrelationIds = self.currentDeleteAnimationCorrelationIds {
if let itemNode = itemNode as? ChatMessageItemView, let item = itemNode.item {
for (message, _) in item.content {
if currentDeleteAnimationCorrelationIds.contains(message.id) {
return 1.5
}
}
}
}
return nil
}
} }

View File

@ -55,3 +55,5 @@ void applyKeyboardAutocorrection(UITextView * _Nonnull textView);
- (void)fixScrollDisplayLink; - (void)fixScrollDisplayLink;
@end @end
void snapshotViewByDrawingInContext(UIView * _Nonnull view);

View File

@ -483,3 +483,7 @@ void applyKeyboardAutocorrection(UITextView * _Nonnull textView) {
} }
@end @end
void snapshotViewByDrawingInContext(UIView * _Nonnull view) {
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:false];
}