From 742ab4c0424f5c6dfc2a4da591db209cec0b05e2 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 24 Mar 2023 01:22:13 +0400 Subject: [PATCH] Fix chat background transition --- submodules/Display/Source/ListView.swift | 4 ++++ .../TelegramUI/Sources/ChatControllerNode.swift | 13 ++++++++++++- .../TelegramUI/Sources/ChatHistoryListNode.swift | 15 ++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/submodules/Display/Source/ListView.swift b/submodules/Display/Source/ListView.swift index 0832ceeb75..ccc2979e2e 100644 --- a/submodules/Display/Source/ListView.swift +++ b/submodules/Display/Source/ListView.swift @@ -195,6 +195,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture private final var lastContentOffset: CGPoint = CGPoint() private final var lastContentOffsetTimestamp: CFAbsoluteTime = 0.0 private final var ignoreScrollingEvents: Bool = false + public final var globalIgnoreScrollingEvents: Bool = false private let infiniteScrollSize: CGFloat @@ -939,6 +940,9 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture if self.ignoreScrollingEvents || scroller !== self.scroller { return } + if self.globalIgnoreScrollingEvents { + return + } /*let timestamp = CACurrentMediaTime() if !self.previousDidScrollTimestamp.isZero { diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 0ef6fe43cb..b5e9f99835 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -3443,6 +3443,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { } final class SnapshotState { + let backgroundNode: WallpaperBackgroundNode fileprivate let historySnapshotState: ChatHistoryListNode.SnapshotState let titleViewSnapshotState: ChatTitleView.SnapshotState? let avatarSnapshotState: ChatAvatarNavigationNode.SnapshotState? @@ -3453,6 +3454,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { let inputPanelOverscrollNodeSnapshot: UIView? fileprivate init( + backgroundNode: WallpaperBackgroundNode, historySnapshotState: ChatHistoryListNode.SnapshotState, titleViewSnapshotState: ChatTitleView.SnapshotState?, avatarSnapshotState: ChatAvatarNavigationNode.SnapshotState?, @@ -3462,6 +3464,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { inputPanelNodeSnapshot: UIView?, inputPanelOverscrollNodeSnapshot: UIView? ) { + self.backgroundNode = backgroundNode self.historySnapshotState = historySnapshotState self.titleViewSnapshotState = titleViewSnapshotState self.avatarSnapshotState = avatarSnapshotState @@ -3493,6 +3496,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { inputPanelOverscrollNodeSnapshot = snapshot } return SnapshotState( + backgroundNode: self.backgroundNode, historySnapshotState: self.historyNode.prepareSnapshotState(), titleViewSnapshotState: titleViewSnapshotState, avatarSnapshotState: avatarSnapshotState, @@ -3505,7 +3509,14 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { } func animateFromSnapshot(_ snapshotState: SnapshotState, completion: @escaping () -> Void) { - self.historyNode.animateFromSnapshot(snapshotState.historySnapshotState, completion: completion) + let previousBackgroundNode = snapshotState.backgroundNode + self.backgroundNode.supernode?.insertSubnode(previousBackgroundNode, belowSubnode: self.backgroundNode) + + self.historyNode.animateFromSnapshot(snapshotState.historySnapshotState, completion: { [weak previousBackgroundNode] in + previousBackgroundNode?.removeFromSupernode() + + completion() + }) self.navigateButtons.animateFromSnapshot(snapshotState.navigationButtonsSnapshotState) if let titleAccessoryPanelSnapshot = snapshotState.titleAccessoryPanelSnapshot { diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index aedf32089e..d44e2ac7fd 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -3789,15 +3789,16 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { } } - let snapshotView = self.view.snapshotView(afterScreenUpdates: false)! + let snapshotView = self.view//.snapshotView(afterScreenUpdates: false)! + self.globalIgnoreScrollingEvents = true - snapshotView.frame = self.view.bounds - if let sublayers = self.layer.sublayers { + //snapshotView.frame = self.view.bounds + /*if let sublayers = self.layer.sublayers { for sublayer in sublayers { sublayer.isHidden = true } - } - self.view.addSubview(snapshotView) + }*/ + //self.view.addSubview(snapshotView) let overscrollView = self.overscrollView if let overscrollView = overscrollView { @@ -3835,6 +3836,10 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { snapshotParentView.frame = self.view.frame snapshotState.snapshotView.frame = snapshotParentView.bounds + + snapshotState.snapshotView.clipsToBounds = true + snapshotState.snapshotView.layer.sublayerTransform = CATransform3DMakeRotation(CGFloat.pi, 0.0, 0.0, 1.0) + self.view.superview?.insertSubview(snapshotParentView, belowSubview: self.view) snapshotParentView.layer.animatePosition(from: CGPoint(x: 0.0, y: 0.0), to: CGPoint(x: 0.0, y: -self.view.bounds.height - snapshotState.snapshotBottomInset - snapshotTopInset), duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: { [weak snapshotParentView] _ in