mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Optimize autoscrolling
This commit is contained in:
parent
768608fc88
commit
f9ddb6ade8
@ -378,6 +378,20 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
let fromOffset: CGPoint = self.scrollView.contentOffset
|
||||
let fromBounds = CGRect(origin: fromOffset, size: self.scrollView.bounds.size)
|
||||
self.applyingContentOffset = true
|
||||
self.scrollView.setContentOffset(toOffset, animated: false)
|
||||
self.applyingContentOffset = false
|
||||
let toBounds = self.scrollView.bounds
|
||||
let animation = self.scrollView.layer.makeAnimation(from: NSValue(cgRect: fromBounds), to: NSValue(cgRect: toBounds), keyPath: "bounds", timingFunction: kCAMediaTimingFunctionSpring, duration: duration)
|
||||
self.scrollView.layer.add(animation, forKey: "autoscroll")
|
||||
|
||||
let transition: ContainedViewLayoutTransition = .animated(duration: duration, curve: .spring)
|
||||
|
||||
self.applyPresentationLayoutTransition(self.generatePresentationLayoutTransition(layoutTransactionOffset: 0.0, customTransition: transition), removedNodes: [], updateLayoutTransition: nil, customScrollToItem: false, itemTransition: .immediate, synchronousLoads: false, updatingLayout: false, completion: { _ in })
|
||||
self.updateVisibleContentOffset()
|
||||
|
||||
/*let fromOffset: CGPoint = self.scrollView.contentOffset
|
||||
|
||||
self.autoscrollingAnimator = DisplayLinkAnimator(duration: duration, from: 0.0, to: 1.0, update: { [weak self] t in
|
||||
guard let strongSelf = self else {
|
||||
@ -392,7 +406,7 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
|
||||
}
|
||||
strongSelf.autoscrollingAnimator?.invalidate()
|
||||
strongSelf.autoscrollingAnimator = nil
|
||||
})
|
||||
})*/
|
||||
}
|
||||
|
||||
public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
||||
@ -401,6 +415,13 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
|
||||
autoscrollingAnimator.invalidate()
|
||||
}
|
||||
|
||||
if let _ = self.scrollView.layer.animation(forKey: "autoscroll") {
|
||||
if let presentationLayer = self.scrollView.layer.presentation() {
|
||||
self.scrollView.bounds = presentationLayer.bounds
|
||||
}
|
||||
self.scrollView.layer.removeAnimation(forKey: "autoscroll")
|
||||
}
|
||||
|
||||
self.updateItemNodeVisibilititesAndScrolling()
|
||||
self.updateVisibleContentOffset()
|
||||
self.scrollingInitiated?()
|
||||
@ -627,10 +648,10 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private func generatePresentationLayoutTransition(stationaryItems: GridNodeStationaryItems = .none, layoutTransactionOffset: CGFloat, scrollToItem: GridNodeScrollToItem? = nil) -> GridNodePresentationLayoutTransition {
|
||||
private func generatePresentationLayoutTransition(stationaryItems: GridNodeStationaryItems = .none, layoutTransactionOffset: CGFloat, scrollToItem: GridNodeScrollToItem? = nil, customTransition: ContainedViewLayoutTransition? = nil) -> GridNodePresentationLayoutTransition {
|
||||
if CGFloat(0.0).isLess(than: self.gridLayout.size.width) && CGFloat(0.0).isLess(than: self.gridLayout.size.height) {
|
||||
var transitionDirectionHint: GridNodePreviousItemsTransitionDirectionHint = .up
|
||||
var transition: ContainedViewLayoutTransition = .immediate
|
||||
var transition: ContainedViewLayoutTransition = customTransition ?? .immediate
|
||||
let contentOffset: CGPoint
|
||||
var updatedStationaryItems = stationaryItems
|
||||
if let scrollToItem = scrollToItem {
|
||||
|
@ -605,6 +605,12 @@ private final class StickerPackContainer: ASDisplayNode {
|
||||
self.expandProgressUpdated(self, expandProgressTransition)
|
||||
}
|
||||
|
||||
if !transition.isAnimated {
|
||||
self.backgroundNode.layer.removeAllAnimations()
|
||||
self.titleContainer.layer.removeAllAnimations()
|
||||
self.titleSeparatorNode.layer.removeAllAnimations()
|
||||
}
|
||||
|
||||
let backgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: max(minBackgroundY, unclippedBackgroundY)), size: CGSize(width: layout.size.width, height: layout.size.height))
|
||||
transition.updateFrame(node: self.backgroundNode, frame: backgroundFrame)
|
||||
transition.updateFrame(node: self.titleContainer, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX + floor((backgroundFrame.width) / 2.0), y: backgroundFrame.minY + floor((50.0) / 2.0)), size: CGSize()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user