mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 05:51:42 +00:00
Improved reordering
This commit is contained in:
parent
a2b69da52e
commit
29a7e6e0c8
@ -1820,6 +1820,13 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
|||||||
self.revealOptionSelected(ItemListRevealOption(key: action.key, title: "", icon: .none, color: .black, textColor: .white), animated: false)
|
self.revealOptionSelected(ItemListRevealOption(key: action.key, title: "", icon: .none, color: .black, textColor: .white), animated: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func snapshotForReordering() -> UIView? {
|
||||||
|
self.backgroundNode.alpha = 0.9
|
||||||
|
let result = self.view.snapshotContentTree()
|
||||||
|
self.backgroundNode.alpha = 1.0
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func foldLineBreaks(_ text: String) -> String {
|
private func foldLineBreaks(_ text: String) -> String {
|
||||||
|
|||||||
@ -425,6 +425,11 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
|
|||||||
self.addSubnode(reorderNode)
|
self.addSubnode(reorderNode)
|
||||||
}
|
}
|
||||||
itemNode.isHidden = true
|
itemNode.isHidden = true
|
||||||
|
|
||||||
|
if strongSelf.reorderFeedback == nil {
|
||||||
|
strongSelf.reorderFeedback = HapticFeedback()
|
||||||
|
}
|
||||||
|
strongSelf.reorderFeedback?.impact()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func endReordering() {
|
private func endReordering() {
|
||||||
|
|||||||
@ -562,4 +562,8 @@ open class ListViewItemNode: ASDisplayNode {
|
|||||||
|
|
||||||
open func applyAbsoluteOffset(value: CGFloat, animationCurve: ContainedViewLayoutTransitionCurve, duration: Double) {
|
open func applyAbsoluteOffset(value: CGFloat, animationCurve: ContainedViewLayoutTransitionCurve, duration: Double) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open func snapshotForReordering() -> UIView? {
|
||||||
|
return self.view.snapshotContentTree()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,47 +2,96 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
|
|
||||||
|
private func generateShadowImage(mirror: Bool) -> UIImage? {
|
||||||
|
return generateImage(CGSize(width: 30.0, height: 30.0), rotatedContext: { size, context in
|
||||||
|
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||||
|
|
||||||
|
if mirror {
|
||||||
|
context.translateBy(x: size.width / 2.0, y: size.height / 2.0)
|
||||||
|
context.scaleBy(x: 1.0, y: -1.0)
|
||||||
|
context.translateBy(x: -size.width / 2.0, y: -size.height / 2.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.setShadow(offset: CGSize(width: 0.0, height: 0.0), blur: 10.0, color: UIColor(white: 0.0, alpha: 0.4).cgColor)
|
||||||
|
context.setFillColor(UIColor(white: 0.0, alpha: 1.0).cgColor)
|
||||||
|
for _ in 0 ..< 1 {
|
||||||
|
context.fill(CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: size.width, height: 15.0)))
|
||||||
|
}
|
||||||
|
context.clear(CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: size.width, height: 15.0)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class CopyView: UIView {
|
||||||
|
let topShadow: UIImageView
|
||||||
|
let bottomShadow: UIImageView
|
||||||
|
|
||||||
|
override init(frame: CGRect) {
|
||||||
|
self.topShadow = UIImageView()
|
||||||
|
self.bottomShadow = UIImageView()
|
||||||
|
|
||||||
|
super.init(frame: frame)
|
||||||
|
|
||||||
|
self.topShadow.image = generateShadowImage(mirror: true)
|
||||||
|
self.bottomShadow.image = generateShadowImage(mirror: false)
|
||||||
|
|
||||||
|
self.addSubview(self.topShadow)
|
||||||
|
self.addSubview(self.bottomShadow)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final class ListViewReorderingItemNode: ASDisplayNode {
|
final class ListViewReorderingItemNode: ASDisplayNode {
|
||||||
weak var itemNode: ListViewItemNode?
|
weak var itemNode: ListViewItemNode?
|
||||||
|
|
||||||
var currentState: (Int, Int)?
|
var currentState: (Int, Int)?
|
||||||
|
|
||||||
private let copyView: UIView?
|
private let copyView: CopyView
|
||||||
private let initialLocation: CGPoint
|
private let initialLocation: CGPoint
|
||||||
|
|
||||||
init(itemNode: ListViewItemNode, initialLocation: CGPoint) {
|
init(itemNode: ListViewItemNode, initialLocation: CGPoint) {
|
||||||
self.itemNode = itemNode
|
self.itemNode = itemNode
|
||||||
self.copyView = itemNode.view.snapshotView(afterScreenUpdates: false)
|
self.copyView = CopyView(frame: CGRect())
|
||||||
|
let snapshotView = itemNode.snapshotForReordering()
|
||||||
self.initialLocation = initialLocation
|
self.initialLocation = initialLocation
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
if let copyView = self.copyView {
|
if let snapshotView = snapshotView {
|
||||||
self.view.addSubview(copyView)
|
snapshotView.frame = CGRect(origin: CGPoint(), size: itemNode.bounds.size)
|
||||||
copyView.frame = CGRect(origin: CGPoint(x: initialLocation.x, y: initialLocation.y), size: copyView.bounds.size)
|
snapshotView.bounds.origin = itemNode.bounds.origin
|
||||||
copyView.bounds = itemNode.bounds
|
self.copyView.addSubview(snapshotView)
|
||||||
}
|
}
|
||||||
|
self.view.addSubview(self.copyView)
|
||||||
|
self.copyView.frame = CGRect(origin: CGPoint(x: initialLocation.x, y: initialLocation.y), size: itemNode.bounds.size)
|
||||||
|
|
||||||
|
self.copyView.topShadow.frame = CGRect(origin: CGPoint(x: 0.0, y: -15.0), size: CGSize(width: copyView.bounds.size.width, height: 30.0))
|
||||||
|
|
||||||
|
self.copyView.bottomShadow.image = generateShadowImage(mirror: false)
|
||||||
|
self.copyView.bottomShadow.frame = CGRect(origin: CGPoint(x: 0.0, y: self.copyView.bounds.size.height - 15.0), size: CGSize(width: self.copyView.bounds.size.width, height: 30.0))
|
||||||
|
|
||||||
|
self.copyView.topShadow.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25)
|
||||||
|
self.copyView.bottomShadow.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateOffset(offset: CGFloat) {
|
func updateOffset(offset: CGFloat) {
|
||||||
if let copyView = self.copyView {
|
self.copyView.frame = CGRect(origin: CGPoint(x: initialLocation.x, y: initialLocation.y + offset), size: copyView.bounds.size)
|
||||||
copyView.frame = CGRect(origin: CGPoint(x: initialLocation.x, y: initialLocation.y + offset), size: copyView.bounds.size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentOffset() -> CGFloat? {
|
func currentOffset() -> CGFloat? {
|
||||||
if let copyView = self.copyView {
|
return self.copyView.center.y
|
||||||
return copyView.center.y
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func animateCompletion(completion: @escaping () -> Void) {
|
func animateCompletion(completion: @escaping () -> Void) {
|
||||||
if let copyView = self.copyView, let itemNode = self.itemNode {
|
if let itemNode = self.itemNode {
|
||||||
itemNode.isHidden = false
|
self.copyView.topShadow.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2)
|
||||||
itemNode.transitionOffset = itemNode.apparentFrame.midY - copyView.frame.midY
|
self.copyView.bottomShadow.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2)
|
||||||
itemNode.addTransitionOffsetAnimation(0.0, duration: 0.2, beginAt: CACurrentMediaTime())
|
self.copyView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: itemNode.apparentFrame.midY - copyView.frame.midY), duration: 0.2, removeOnCompletion: false, additive: true, force: true, completion: { [weak itemNode] _ in
|
||||||
completion()
|
itemNode?.isHidden = false
|
||||||
|
completion()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
completion()
|
completion()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -741,4 +741,11 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func snapshotForReordering() -> UIView? {
|
||||||
|
self.backgroundNode.alpha = 0.9
|
||||||
|
let result = self.view.snapshotContentTree()
|
||||||
|
self.backgroundNode.alpha = 1.0
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user