mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Various improvements
This commit is contained in:
@@ -765,6 +765,7 @@ private class ChatQrCodeScreenNode: ViewControllerTracingNode, ASScrollViewDeleg
|
||||
private let contentNode: ContentNode
|
||||
|
||||
private let wrappingScrollNode: ASScrollNode
|
||||
private let scrollNodeContentNode: ASDisplayNode
|
||||
private let contentContainerNode: ASDisplayNode
|
||||
private let topContentContainerNode: SparseNode
|
||||
private let shadowNode: ASImageNode
|
||||
@@ -824,6 +825,9 @@ private class ChatQrCodeScreenNode: ViewControllerTracingNode, ASScrollViewDeleg
|
||||
self.wrappingScrollNode.view.delaysContentTouches = false
|
||||
self.wrappingScrollNode.view.canCancelContentTouches = true
|
||||
|
||||
self.scrollNodeContentNode = ASDisplayNode()
|
||||
self.scrollNodeContentNode.clipsToBounds = true
|
||||
|
||||
switch controller.subject {
|
||||
case let .peer(peer, threadId, temporary):
|
||||
self.contentNode = QrContentNode(context: context, peer: peer, threadId: threadId, isStatic: false, temporary: temporary)
|
||||
@@ -909,12 +913,14 @@ private class ChatQrCodeScreenNode: ViewControllerTracingNode, ASScrollViewDeleg
|
||||
|
||||
self.addSubnode(self.wrappingScrollNode)
|
||||
|
||||
self.wrappingScrollNode.addSubnode(self.contentNode)
|
||||
self.wrappingScrollNode.addSubnode(self.scrollNodeContentNode)
|
||||
|
||||
self.wrappingScrollNode.addSubnode(self.shadowNode)
|
||||
self.wrappingScrollNode.addSubnode(self.backgroundNode)
|
||||
self.wrappingScrollNode.addSubnode(self.contentContainerNode)
|
||||
self.wrappingScrollNode.addSubnode(self.topContentContainerNode)
|
||||
self.scrollNodeContentNode.addSubnode(self.contentNode)
|
||||
|
||||
self.scrollNodeContentNode.addSubnode(self.shadowNode)
|
||||
self.scrollNodeContentNode.addSubnode(self.backgroundNode)
|
||||
self.scrollNodeContentNode.addSubnode(self.contentContainerNode)
|
||||
self.scrollNodeContentNode.addSubnode(self.topContentContainerNode)
|
||||
|
||||
self.backgroundNode.addSubnode(self.effectNode)
|
||||
self.backgroundNode.addSubnode(self.contentBackgroundNode)
|
||||
@@ -1401,32 +1407,60 @@ private class ChatQrCodeScreenNode: ViewControllerTracingNode, ASScrollViewDeleg
|
||||
public func animateIn() {
|
||||
let offset = self.bounds.size.height - self.contentBackgroundNode.frame.minY
|
||||
|
||||
if let (layout, _) = self.containerLayout {
|
||||
self.scrollNodeContentNode.cornerRadius = layout.deviceMetrics.screenCornerRadius
|
||||
}
|
||||
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.4, curve: .spring)
|
||||
let targetBounds = self.bounds
|
||||
self.bounds = self.bounds.offsetBy(dx: 0.0, dy: -offset)
|
||||
transition.animateView({
|
||||
self.bounds = targetBounds
|
||||
}, completion: { _ in
|
||||
self.scrollNodeContentNode.cornerRadius = 0.0
|
||||
})
|
||||
}
|
||||
|
||||
public func animateOut(completion: (() -> Void)? = nil) {
|
||||
public func animateOut(velocity: Double? = nil, completion: (() -> Void)? = nil) {
|
||||
self.animatedOut = true
|
||||
|
||||
let offset = self.bounds.size.height - self.contentBackgroundNode.frame.minY
|
||||
self.wrappingScrollNode.layer.animateBoundsOriginYAdditive(from: 0.0, to: -offset, duration: 0.3, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false, completion: { _ in
|
||||
completion?()
|
||||
})
|
||||
self.wrappingScrollNode.view.isScrollEnabled = false
|
||||
|
||||
let distance = self.bounds.size.height - self.contentBackgroundNode.frame.minY
|
||||
if let velocity {
|
||||
let initialVelocity: CGFloat = distance.isZero ? 0.0 : abs(velocity / distance)
|
||||
self.wrappingScrollNode.layer.animateSpring(from: 0.0 as NSNumber, to: -distance as NSNumber, keyPath: "bounds.origin.y", duration: 0.45, delay: 0.0, initialVelocity: initialVelocity, damping: 124.0, removeOnCompletion: false, additive: true, completion: { _ in
|
||||
completion?()
|
||||
})
|
||||
} else {
|
||||
self.wrappingScrollNode.layer.animateBoundsOriginYAdditive(from: 0.0, to: -distance, duration: 0.3, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false, completion: { _ in
|
||||
completion?()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
|
||||
|
||||
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
|
||||
let contentOffset = scrollView.contentOffset
|
||||
let additionalTopHeight = max(0.0, -contentOffset.y)
|
||||
|
||||
if additionalTopHeight >= 30.0 {
|
||||
self.cancelButtonPressed()
|
||||
self.animateOut(velocity: velocity.y, completion: {
|
||||
self.controller?.dismiss(animated: false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
||||
guard let (layout, _) = self.containerLayout else {
|
||||
return
|
||||
}
|
||||
self.scrollNodeContentNode.cornerRadius = layout.deviceMetrics.screenCornerRadius
|
||||
}
|
||||
|
||||
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
|
||||
self.scrollNodeContentNode.cornerRadius = 0.0
|
||||
}
|
||||
|
||||
public func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {
|
||||
self.containerLayout = (layout, navigationBarHeight)
|
||||
|
||||
@@ -1455,6 +1489,7 @@ private class ChatQrCodeScreenNode: ViewControllerTracingNode, ASScrollViewDeleg
|
||||
transition.updateFrame(node: self.effectNode, frame: CGRect(origin: CGPoint(), size: backgroundFrame.size))
|
||||
transition.updateFrame(node: self.contentBackgroundNode, frame: CGRect(origin: CGPoint(), size: backgroundFrame.size))
|
||||
transition.updateFrame(node: self.wrappingScrollNode, frame: CGRect(origin: CGPoint(), size: layout.size))
|
||||
transition.updateFrame(node: self.scrollNodeContentNode, frame: CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: layout.size.height + 2000.0)))
|
||||
|
||||
let titleSize = self.titleNode.measure(CGSize(width: width - 90.0, height: titleHeight))
|
||||
let titleFrame = CGRect(origin: CGPoint(x: floor((contentFrame.width - titleSize.width) / 2.0), y: 19.0 + UIScreenPixel), size: titleSize)
|
||||
|
||||
Reference in New Issue
Block a user