Merge commit 'f4ceb40d22ea3021d8d31db18dcc46213473716d'

This commit is contained in:
Ali 2022-10-20 02:44:37 +04:00
commit 83636d5a4d
9 changed files with 76 additions and 54 deletions

View File

@ -692,7 +692,7 @@ public extension ContainedViewLayoutTransition {
}
}
func updateFrame(layer: CALayer, frame: CGRect, beginWithCurrentState: Bool = false, completion: ((Bool) -> Void)? = nil) {
func updateFrame(layer: CALayer, frame: CGRect, beginWithCurrentState: Bool = false, delay: Double = 0.0, completion: ((Bool) -> Void)? = nil) {
if layer.frame.equalTo(frame) {
completion?(true)
} else {
@ -712,7 +712,7 @@ public extension ContainedViewLayoutTransition {
previousFrame = layer.frame
}
layer.frame = frame
layer.animateFrame(from: previousFrame, to: frame, duration: duration, timingFunction: curve.timingFunction, mediaTimingFunction: curve.mediaTimingFunction, completion: { result in
layer.animateFrame(from: previousFrame, to: frame, duration: duration, delay: delay, timingFunction: curve.timingFunction, mediaTimingFunction: curve.mediaTimingFunction, completion: { result in
if let completion = completion {
completion(result)
}
@ -1572,7 +1572,7 @@ public struct CombinedTransition {
}
public extension ContainedViewLayoutTransition {
func animateView(allowUserInteraction: Bool = false, _ f: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
func animateView(allowUserInteraction: Bool = false, delay: Double = 0.0, _ f: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
switch self {
case .immediate:
f()
@ -1582,7 +1582,7 @@ public extension ContainedViewLayoutTransition {
if allowUserInteraction {
options.insert(.allowUserInteraction)
}
UIView.animate(withDuration: duration, delay: 0.0, options: options, animations: {
UIView.animate(withDuration: duration, delay: delay, options: options, animations: {
f()
}, completion: completion)
}

View File

@ -250,7 +250,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
public final var snapToBottomInsetUntilFirstInteraction: Bool = false
public final var updateFloatingHeaderOffset: ((CGFloat, ContainedViewLayoutTransition) -> Void)?
public final var didScrollWithOffset: ((CGFloat, ContainedViewLayoutTransition, ListViewItemNode?) -> Void)?
public final var didScrollWithOffset: ((CGFloat, ContainedViewLayoutTransition, ListViewItemNode?, Bool) -> Void)?
public final var addContentOffset: ((CGFloat, ListViewItemNode?) -> Void)?
public final var updateScrollingIndicator: ((ScrollingIndicatorState?, ContainedViewLayoutTransition) -> Void)?
@ -287,6 +287,10 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
public private(set) var isDragging = false
public private(set) var isDeceleratingAfterTracking = false
private var isTrackingOrDecelerating: Bool {
return self.isTracking || self.isDragging || self.isDeceleratingAfterTracking
}
private final var transactionQueue: ListViewTransactionQueue
private final var transactionOffset: CGFloat = 0.0
@ -953,7 +957,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
anchor = 0.0
}
self.didScrollWithOffset?(deltaY, .immediate, nil)
self.didScrollWithOffset?(deltaY, .immediate, nil, self.isTrackingOrDecelerating)
for itemNode in self.itemNodes {
itemNode.updateFrame(itemNode.frame.offsetBy(dx: 0.0, dy: -deltaY), within: self.visibleSize)
@ -1244,7 +1248,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
}
if abs(offset) > CGFloat.ulpOfOne {
self.didScrollWithOffset?(-offset, .immediate, nil)
self.didScrollWithOffset?(-offset, .immediate, nil, self.isTrackingOrDecelerating)
for itemNode in self.itemNodes {
var frame = itemNode.frame
@ -2284,7 +2288,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
offsetHeight = 0.0
nextNode.updateFrame(nextNode.frame.offsetBy(dx: 0.0, dy: nextHeight), within: self.visibleSize)
self.didScrollWithOffset?(nextHeight, .immediate, nextNode)
self.didScrollWithOffset?(nextHeight, .immediate, nextNode, self.isTrackingOrDecelerating)
nextNode.apparentHeight = 0.0
@ -2394,7 +2398,6 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
var frame = self.itemNodes[i].frame
frame.origin.y -= offsetHeight
self.itemNodes[i].updateFrame(frame, within: self.visibleSize)
//self.didScrollWithOffset?(offsetHeight, .immediate, self.itemNodes[i])
if let accessoryItemNode = self.itemNodes[i].accessoryItemNode {
self.itemNodes[i].layoutAccessoryItemNode(accessoryItemNode, leftInset: listInsets.left, rightInset: listInsets.right)
}
@ -2406,7 +2409,6 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
var frame = self.itemNodes[i].frame
frame.origin.y += offsetHeight
self.itemNodes[i].updateFrame(frame, within: self.visibleSize)
//self.didScrollWithOffset?(-offsetHeight, .immediate, self.itemNodes[i])
if let accessoryItemNode = self.itemNodes[i].accessoryItemNode {
self.itemNodes[i].layoutAccessoryItemNode(accessoryItemNode, leftInset: listInsets.left, rightInset: listInsets.right)
}
@ -2848,7 +2850,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
var frame = itemNode.frame
frame.origin.y += offset
itemNode.updateFrame(frame, within: self.visibleSize)
self.didScrollWithOffset?(-offset, .immediate, itemNode)
self.didScrollWithOffset?(-offset, .immediate, itemNode, self.isTrackingOrDecelerating)
if let accessoryItemNode = itemNode.accessoryItemNode {
itemNode.layoutAccessoryItemNode(accessoryItemNode, leftInset: listInsets.left, rightInset: listInsets.right)
}
@ -3003,10 +3005,10 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
for itemNode in self.itemNodes {
itemNode.applyAbsoluteOffset(value: CGPoint(x: 0.0, y: -completeOffset), animationCurve: animationCurve, duration: animationDuration)
}
self.didScrollWithOffset?(-completeOffset, ContainedViewLayoutTransition.animated(duration: animationDuration, curve: animationCurve), nil)
self.didScrollWithOffset?(-completeOffset, ContainedViewLayoutTransition.animated(duration: animationDuration, curve: animationCurve), nil, self.isTrackingOrDecelerating)
}
} else {
self.didScrollWithOffset?(-completeOffset, .immediate, nil)
self.didScrollWithOffset?(-completeOffset, .immediate, nil, self.isTrackingOrDecelerating)
}
} else {
self.visibleSize = updateSizeAndInsets.size
@ -3049,7 +3051,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
for itemNode in self.itemNodes {
itemNode.applyAbsoluteOffset(value: CGPoint(x: 0.0, y: -completeOffset), animationCurve: .spring, duration: duration)
}
self.didScrollWithOffset?(-completeOffset, .animated(duration: duration, curve: .spring), nil)
self.didScrollWithOffset?(-completeOffset, .animated(duration: duration, curve: .spring), nil, self.isTrackingOrDecelerating)
}
} else {
if let snapshotView = snapshotView {
@ -3072,7 +3074,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
let (snappedTopInset, snapToBoundsOffset) = self.snapToBounds(snapTopItem: scrollToItem != nil && scrollToItem?.directionHint != .Down, stackFromBottom: self.stackFromBottom, updateSizeAndInsets: updateSizeAndInsets, scrollToItem: scrollToItem, insetDeltaOffsetFix: 0.0)
if !snappedTopInset.isZero && previousApparentFrames.isEmpty {
self.didScrollWithOffset?(-snappedTopInset, .immediate, nil)
self.didScrollWithOffset?(-snappedTopInset, .immediate, nil, self.isTrackingOrDecelerating)
for itemNode in self.itemNodes {
itemNode.updateFrame(itemNode.frame.offsetBy(dx: 0.0, dy: snappedTopInset), within: self.visibleSize)
@ -3380,7 +3382,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
for itemNode in temporaryPreviousNodes {
itemNode.applyAbsoluteOffset(value: CGPoint(x: 0.0, y: -offset), animationCurve: animationCurve, duration: animationDuration)
}
self.didScrollWithOffset?(-offset, .animated(duration: animationDuration, curve: animationCurve), nil)
self.didScrollWithOffset?(-offset, .animated(duration: animationDuration, curve: animationCurve), nil, self.isTrackingOrDecelerating)
if let verticalScrollIndicator = self.verticalScrollIndicator {
verticalScrollIndicator.layer.add(reverseAnimation, forKey: nil)
}
@ -4315,7 +4317,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
let offset = offsetRanges.offsetForIndex(index)
if offset != 0.0 {
itemNode.updateFrame(itemNode.frame.offsetBy(dx: 0.0, dy: offset), within: self.visibleSize)
self.didScrollWithOffset?(-offset, .immediate, itemNode)
self.didScrollWithOffset?(-offset, .immediate, itemNode, self.isTrackingOrDecelerating)
}
index += 1

View File

@ -213,7 +213,7 @@ open class ItemListController: ViewController, KeyShortcutResponder, Presentable
}
}
public var didScrollWithOffset: ((CGFloat, ContainedViewLayoutTransition, ListViewItemNode?) -> Void)? {
public var didScrollWithOffset: ((CGFloat, ContainedViewLayoutTransition, ListViewItemNode?, Bool) -> Void)? {
didSet {
if self.isNodeLoaded {
(self.displayNode as! ItemListControllerNode).listNode.didScrollWithOffset = self.didScrollWithOffset

View File

@ -283,7 +283,7 @@ public func quickReactionSetupController(
let controller = ItemListController(context: context, state: signal)
controller.didScrollWithOffset = { [weak controller] offset, transition, _ in
controller.didScrollWithOffset = { [weak controller] offset, transition, _, _ in
guard let controller = controller else {
return
}

View File

@ -5844,7 +5844,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
self.chatDisplayNode.historyNode.voicePlaylistItemChanged(nil, currentItem)
}
self.chatDisplayNode.historyNode.didScrollWithOffset = { [weak self] offset, transition, itemNode in
self.chatDisplayNode.historyNode.didScrollWithOffset = { [weak self] offset, transition, itemNode, isTracking in
guard let strongSelf = self else {
return
}
@ -5870,7 +5870,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
}
strongSelf.chatDisplayNode.loadingPlaceholderNode?.addContentOffset(offset: offset, transition: transition)
if isTracking {
strongSelf.chatDisplayNode.loadingPlaceholderNode?.addContentOffset(offset: offset, transition: transition)
}
strongSelf.chatDisplayNode.messageTransitionNode.addExternalOffset(offset: offset, transition: transition, itemNode: itemNode)
}

View File

@ -576,14 +576,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
self.contentContainerNode.addSubnode(navigationBar)
}
// Queue.mainQueue().after(0.2) {
// self.updateIsLoading(isLoading: true, animated: false)
// }
//
// Queue.mainQueue().after(3.0) {
// self.updateIsLoading(isLoading: false, animated: true)
// }
self.inputPanelContainerNode.expansionUpdated = { [weak self] transition in
guard let strongSelf = self else {
return
@ -1736,10 +1728,21 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
}
if let inputPanelBackgroundContent = self.inputPanelBackgroundContent {
var apparentInputBackgroundFrame = apparentInputBackgroundFrame
apparentInputBackgroundFrame.size.height += 34.0
transition.updateFrame(node: inputPanelBackgroundContent, frame: CGRect(origin: .zero, size: apparentInputBackgroundFrame.size), beginWithCurrentState: true)
inputPanelBackgroundContent.update(rect: apparentInputBackgroundFrame, within: layout.size, transition: transition)
var extensionValue: CGFloat = 0.0
if let inputNode = self.inputNode {
extensionValue = inputNode.topBackgroundExtension
}
let apparentInputBackgroundFrame = CGRect(origin: .zero, size: CGSize(width: apparentInputBackgroundFrame.width, height: apparentInputBackgroundFrame.height + extensionValue))
var transition = transition
var delay: Double = 0.0
if apparentInputBackgroundFrame.height > inputPanelBackgroundContent.frame.height {
transition = .immediate
} else if case let .animated(_, curve) = transition, case .spring = curve {
delay = 0.3
}
transition.updateFrame(node: inputPanelBackgroundContent, frame: CGRect(origin: .zero, size: apparentInputBackgroundFrame.size), beginWithCurrentState: true, delay: delay)
inputPanelBackgroundContent.update(rect: apparentInputBackgroundFrame, within: layout.size, delay: delay, transition: transition)
}
transition.updateFrame(node: self.contentDimNode, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: apparentInputBackgroundFrame.origin.y)))

View File

@ -328,12 +328,7 @@ final class ChatLoadingPlaceholderNode: ASDisplayNode {
}
}
private var ignoreFirstContentOffset = true
func addContentOffset(offset: CGFloat, transition: ContainedViewLayoutTransition) {
guard !self.ignoreFirstContentOffset else {
self.ignoreFirstContentOffset = false
return
}
self.scrollingContainer.bounds = self.scrollingContainer.bounds.offsetBy(dx: 0.0, dy: -offset)
transition.animateOffsetAdditive(node: self.scrollingContainer, offset: offset)
if let (rect, containerSize) = self.absolutePosition {
@ -388,8 +383,8 @@ final class ChatLoadingPlaceholderNode: ASDisplayNode {
self.effectNode.updateAbsoluteRect(bounds, within: bounds.size)
self.borderEffectNode.updateAbsoluteRect(bounds, within: bounds.size)
self.effectNode.update(backgroundColor: .clear, foregroundColor: UIColor(rgb: 0xffffff, alpha: 0.15), horizontal: true, effectSize: 280.0, globalTimeOffset: false, duration: 1.6)
self.borderEffectNode.update(backgroundColor: .clear, foregroundColor: UIColor(rgb: 0xffffff, alpha: 0.45), horizontal: true, effectSize: 320.0, globalTimeOffset: false, duration: 1.6)
self.effectNode.update(backgroundColor: .clear, foregroundColor: UIColor(rgb: 0xffffff, alpha: 0.14), horizontal: true, effectSize: 280.0, globalTimeOffset: false, duration: 1.6)
self.borderEffectNode.update(backgroundColor: .clear, foregroundColor: UIColor(rgb: 0xffffff, alpha: 0.35), horizontal: true, effectSize: 320.0, globalTimeOffset: false, duration: 1.6)
let shortHeight: CGFloat = 71.0
let tallHeight: CGFloat = 93.0

View File

@ -353,12 +353,15 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
self.containerNode = ContextControllerSourceNode()
}
private var absoluteRect: (CGRect, CGSize)?
fileprivate var absoluteRect: (CGRect, CGSize)?
fileprivate func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
self.absoluteRect = (rect, containerSize)
guard let backgroundWallpaperNode = self.backgroundWallpaperNode else {
return
}
guard !self.sourceNode.isExtractedToContextPreview else {
return
}
let mappedRect = CGRect(origin: CGPoint(x: rect.minX + backgroundWallpaperNode.frame.minX, y: rect.minY + backgroundWallpaperNode.frame.minY), size: rect.size)
backgroundWallpaperNode.update(rect: mappedRect, within: containerSize)
}
@ -2711,8 +2714,8 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
container?.isExtractedToContextPreviewUpdated(isExtractedToContextPreview)
if !isExtractedToContextPreview, let (rect, size) = strongSelf.absoluteRect {
container?.updateAbsoluteRect(relativeFrame.offsetBy(dx: rect.minX, dy: rect.minY), within: size)
if !isExtractedToContextPreview, let (rect, size) = container?.absoluteRect {
container?.updateAbsoluteRect(rect, within: size)
}
for contentNode in strongSelf.contentNodes {
@ -4009,11 +4012,12 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
override func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
self.absoluteRect = (rect, containerSize)
if !self.mainContextSourceNode.isExtractedToContextPreview {
var rect = rect
rect.origin.y = containerSize.height - rect.maxY + self.insets.top
self.updateAbsoluteRectInternal(rect, within: containerSize)
guard !self.mainContextSourceNode.isExtractedToContextPreview else {
return
}
var rect = rect
rect.origin.y = containerSize.height - rect.maxY + self.insets.top
self.updateAbsoluteRectInternal(rect, within: containerSize)
}
private func updateAbsoluteRectInternal(_ rect: CGRect, within containerSize: CGSize) {
@ -4025,6 +4029,13 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
contentNode.updateAbsoluteRect(CGRect(origin: CGPoint(x: rect.minX + contentNode.frame.minX, y: rect.minY + contentNode.frame.minY), size: rect.size), within: containerSize)
}
for container in self.contentContainers {
var containerFrame = self.mainContainerNode.frame
containerFrame.origin.x += rect.minX
containerFrame.origin.y += rect.minY
container.updateAbsoluteRect(containerFrame, within: containerSize)
}
if let shareButtonNode = self.shareButtonNode {
var shareButtonNodeFrame = shareButtonNode.frame
shareButtonNodeFrame.origin.x += rect.minX

View File

@ -45,6 +45,7 @@ public protocol WallpaperBubbleBackgroundNode: ASDisplayNode {
var implicitContentUpdate: Bool { get set }
func update(rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition)
func update(rect: CGRect, within containerSize: CGSize, delay: Double, transition: ContainedViewLayoutTransition)
func update(rect: CGRect, within containerSize: CGSize, transition: CombinedTransition)
func update(rect: CGRect, within containerSize: CGSize, animator: ControlledTransitionAnimator)
func offset(value: CGPoint, animationCurve: ContainedViewLayoutTransitionCurve, duration: Double)
@ -474,25 +475,29 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
self.update(rect: rect, within: containerSize)
}
}
func update(rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition = .immediate) {
self.update(rect: rect, within: containerSize, delay: 0.0, transition: transition)
}
func update(rect: CGRect, within containerSize: CGSize, delay: Double = 0.0, transition: ContainedViewLayoutTransition = .immediate) {
self.currentLayout = (rect, containerSize)
let shiftedContentsRect = CGRect(origin: CGPoint(x: rect.minX / containerSize.width, y: rect.minY / containerSize.height), size: CGSize(width: rect.width / containerSize.width, height: rect.height / containerSize.height))
transition.updateFrame(layer: self.contentNode.layer, frame: self.bounds)
transition.animateView {
transition.updateFrame(layer: self.contentNode.layer, frame: self.bounds, delay: delay)
transition.animateView(delay: delay) {
self.contentNode.layer.contentsRect = shiftedContentsRect
}
if let cleanWallpaperNode = self.cleanWallpaperNode {
transition.updateFrame(layer: cleanWallpaperNode.layer, frame: self.bounds)
transition.animateView {
transition.updateFrame(layer: cleanWallpaperNode.layer, frame: self.bounds, delay: delay)
transition.animateView(delay: delay) {
cleanWallpaperNode.layer.contentsRect = shiftedContentsRect
}
}
if let gradientWallpaperNode = self.gradientWallpaperNode {
transition.updateFrame(layer: gradientWallpaperNode.layer, frame: self.bounds)
transition.animateView {
transition.updateFrame(layer: gradientWallpaperNode.layer, frame: self.bounds, delay: delay)
transition.animateView(delay: delay) {
gradientWallpaperNode.layer.contentsRect = shiftedContentsRect
}
}
@ -1421,6 +1426,10 @@ final class WallpaperBackgroundNodeMergedImpl: ASDisplayNode, WallpaperBackgroun
}
func update(rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition = .immediate) {
self.update(rect: rect, within: containerSize, delay: 0.0, transition: transition)
}
func update(rect: CGRect, within containerSize: CGSize, delay: Double, transition: ContainedViewLayoutTransition = .immediate) {
self.currentLayout = (rect, containerSize)
let shiftedContentsRect = CGRect(origin: CGPoint(x: rect.minX / containerSize.width, y: rect.minY / containerSize.height), size: CGSize(width: rect.width / containerSize.width, height: rect.height / containerSize.height))