Attachment menu improvements

This commit is contained in:
Ilya Laktyushin
2022-03-08 22:14:45 +04:00
parent 8f44a8fee6
commit 871fe3d8ab
5 changed files with 46 additions and 23 deletions

View File

@@ -279,9 +279,6 @@ public class AttachmentController: ViewController {
}
func switchToController(_ type: AttachmentButtonType, _ ascending: Bool) -> Bool {
guard !self.animating else {
return false
}
guard self.currentType != type else {
if let controller = self.currentControllers.last {
controller.scrollToTopWithTabBar?()
@@ -347,6 +344,7 @@ public class AttachmentController: ViewController {
snapshotView.frame = self.container.container.frame
self.container.clipNode.view.addSubview(snapshotView)
let alreadyAnimating = self.animating
self.animating = true
let _ = (controller.ready.get()
@@ -360,20 +358,24 @@ public class AttachmentController: ViewController {
}
if case .compact = layout.metrics.widthClass {
let offset = strongSelf.container.isExpanded ? 10.0 : 24.0
strongSelf.container.clipNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.18, removeOnCompletion: false, additive: true, completion: { [weak self] _ in
if let strongSelf = self {
strongSelf.container.clipNode.layer.animateSpring(from: NSValue(cgPoint: CGPoint(x: 0.0, y: 0.0)), to: NSValue(cgPoint: CGPoint(x: 0.0, y: -offset)), keyPath: "position", duration: 0.55, delay: 0.0, initialVelocity: 0.0, damping: 70.0, removeOnCompletion: false, additive: true, completion: { [weak self] _ in
self?.container.clipNode.layer.removeAllAnimations()
self?.animating = false
})
}
})
if !alreadyAnimating {
let offset = 25.0
strongSelf.container.clipNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.15, removeOnCompletion: false, additive: true, completion: { [weak self] finished in
if let strongSelf = self, finished {
strongSelf.container.clipNode.layer.animateSpring(from: NSValue(cgPoint: CGPoint(x: 0.0, y: 0.0)), to: NSValue(cgPoint: CGPoint(x: 0.0, y: -offset)), keyPath: "position", duration: 0.45, delay: 0.0, initialVelocity: 0.0, damping: 70.0, removeOnCompletion: false, additive: true, completion: { [weak self] finished in
if finished {
self?.container.clipNode.layer.removeAllAnimations()
self?.animating = false
}
})
}
})
}
} else {
strongSelf.animating = false
}
snapshotView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false, completion: { [weak snapshotView] _ in
snapshotView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.23, removeOnCompletion: false, completion: { [weak snapshotView] _ in
snapshotView?.removeFromSuperview()
previousController?.resetForReuse()
})