mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-12 06:19:22 +00:00

git-subtree-dir: submodules/Display git-subtree-mainline: 9bc996374ffdad37aef175427db72731c9551dcf git-subtree-split: 7bd11013ea936e3d49d937550d599f5816d32560
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import AsyncDisplayKit
|
|
|
|
final class ListViewReorderingItemNode: ASDisplayNode {
|
|
weak var itemNode: ListViewItemNode?
|
|
|
|
var currentState: (Int, Int)?
|
|
|
|
private let copyView: UIView?
|
|
private let initialLocation: CGPoint
|
|
|
|
init(itemNode: ListViewItemNode, initialLocation: CGPoint) {
|
|
self.itemNode = itemNode
|
|
self.copyView = itemNode.view.snapshotView(afterScreenUpdates: false)
|
|
self.initialLocation = initialLocation
|
|
|
|
super.init()
|
|
|
|
if let copyView = self.copyView {
|
|
self.view.addSubview(copyView)
|
|
copyView.frame = CGRect(origin: CGPoint(x: initialLocation.x, y: initialLocation.y), size: copyView.bounds.size)
|
|
copyView.bounds = itemNode.bounds
|
|
}
|
|
}
|
|
|
|
func updateOffset(offset: CGFloat) {
|
|
if let copyView = self.copyView {
|
|
copyView.frame = CGRect(origin: CGPoint(x: initialLocation.x, y: initialLocation.y + offset), size: copyView.bounds.size)
|
|
}
|
|
}
|
|
|
|
func currentOffset() -> CGFloat? {
|
|
if let copyView = self.copyView {
|
|
return copyView.center.y
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func animateCompletion(completion: @escaping () -> Void) {
|
|
if let copyView = self.copyView, let itemNode = self.itemNode {
|
|
itemNode.isHidden = false
|
|
itemNode.transitionOffset = itemNode.apparentFrame.midY - copyView.frame.midY
|
|
itemNode.addTransitionOffsetAnimation(0.0, duration: 0.2, beginAt: CACurrentMediaTime())
|
|
completion()
|
|
} else {
|
|
completion()
|
|
}
|
|
}
|
|
}
|