mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Attachment menu improvements
This commit is contained in:
parent
83f5f81ab7
commit
c7c46e23b0
@ -805,7 +805,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
|
|||||||
var rects: [CGRect] = []
|
var rects: [CGRect] = []
|
||||||
for contentNode in self.contentNodes {
|
for contentNode in self.contentNodes {
|
||||||
if let contentNode = contentNode as? ChatMessageMediaBubbleContentNode {
|
if let contentNode = contentNode as? ChatMessageMediaBubbleContentNode {
|
||||||
rects.append(contentNode.frame.offsetBy(dx: -76.0, dy: 0.0))
|
rects.append(contentNode.frame.offsetBy(dx: -self.clippingNode.frame.minX, dy: 0.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rects
|
return rects
|
||||||
|
@ -574,83 +574,85 @@ public final class ChatMessageTransitionNode: ASDisplayNode {
|
|||||||
self.endAnimation()
|
self.endAnimation()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let itemNode = self.itemNode as? ChatMessageBubbleItemNode {
|
Queue.mainQueue().justDispatch {
|
||||||
itemNode.cancelInsertionAnimations()
|
|
||||||
|
|
||||||
self.contextSourceNode.isExtractedToContextPreview = true
|
|
||||||
self.contextSourceNode.isExtractedToContextPreviewUpdated?(true)
|
|
||||||
|
|
||||||
self.containerNode.addSubnode(self.contextSourceNode.contentNode)
|
|
||||||
|
|
||||||
let combinedTransition = CombinedTransition(horizontal: .animated(duration: horizontalDuration, curve: ChatMessageTransitionNode.horizontalAnimationCurve), vertical: .animated(duration: verticalDuration, curve: ChatMessageTransitionNode.verticalAnimationCurve))
|
|
||||||
|
|
||||||
var targetContentRects: [CGRect] = []
|
|
||||||
if let itemNode = self.itemNode as? ChatMessageBubbleItemNode {
|
if let itemNode = self.itemNode as? ChatMessageBubbleItemNode {
|
||||||
targetContentRects = itemNode.animateContentFromGroupedMediaInput(transition: combinedTransition)
|
itemNode.cancelInsertionAnimations()
|
||||||
}
|
|
||||||
|
|
||||||
let targetAbsoluteRect = self.contextSourceNode.view.convert(self.contextSourceNode.contentRect, to: self.view)
|
self.contextSourceNode.isExtractedToContextPreview = true
|
||||||
|
self.contextSourceNode.isExtractedToContextPreviewUpdated?(true)
|
||||||
|
|
||||||
func boundingRect(for views: [UIView]) -> CGRect {
|
self.containerNode.addSubnode(self.contextSourceNode.contentNode)
|
||||||
var minX: CGFloat = .greatestFiniteMagnitude
|
|
||||||
var minY: CGFloat = .greatestFiniteMagnitude
|
|
||||||
var maxX: CGFloat = .leastNonzeroMagnitude
|
|
||||||
var maxY: CGFloat = .leastNonzeroMagnitude
|
|
||||||
|
|
||||||
for view in views {
|
let combinedTransition = CombinedTransition(horizontal: .animated(duration: horizontalDuration, curve: ChatMessageTransitionNode.horizontalAnimationCurve), vertical: .animated(duration: verticalDuration, curve: ChatMessageTransitionNode.verticalAnimationCurve))
|
||||||
let rect = view.frame
|
|
||||||
if rect.minX < minX {
|
var targetContentRects: [CGRect] = []
|
||||||
minX = rect.minX
|
if let itemNode = self.itemNode as? ChatMessageBubbleItemNode {
|
||||||
}
|
targetContentRects = itemNode.animateContentFromGroupedMediaInput(transition: combinedTransition)
|
||||||
if rect.minY < minY {
|
|
||||||
minY = rect.minY
|
|
||||||
}
|
|
||||||
if rect.maxX > maxX {
|
|
||||||
maxX = rect.maxX
|
|
||||||
}
|
|
||||||
if rect.maxY > maxY {
|
|
||||||
maxY = rect.maxY
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return CGRect(origin: CGPoint(x: minX, y: minY), size: CGSize(width: maxX - minX, height: maxY - minY))
|
|
||||||
}
|
|
||||||
|
|
||||||
let sourceBackgroundAbsoluteRect = boundingRect(for: snapshotViews)
|
let targetAbsoluteRect = self.contextSourceNode.view.convert(self.contextSourceNode.contentRect, to: self.view)
|
||||||
let sourceAbsoluteRect = CGRect(origin: CGPoint(x: sourceBackgroundAbsoluteRect.midX - self.contextSourceNode.contentRect.size.width / 2.0, y: sourceBackgroundAbsoluteRect.midY - self.contextSourceNode.contentRect.size.height / 2.0), size: self.contextSourceNode.contentRect.size)
|
|
||||||
|
|
||||||
self.containerNode.frame = targetAbsoluteRect.offsetBy(dx: -self.contextSourceNode.contentRect.minX, dy: -self.contextSourceNode.contentRect.minY)
|
func boundingRect(for views: [UIView]) -> CGRect {
|
||||||
|
var minX: CGFloat = .greatestFiniteMagnitude
|
||||||
|
var minY: CGFloat = .greatestFiniteMagnitude
|
||||||
|
var maxX: CGFloat = .leastNonzeroMagnitude
|
||||||
|
var maxY: CGFloat = .leastNonzeroMagnitude
|
||||||
|
|
||||||
self.contextSourceNode.updateAbsoluteRect?(self.containerNode.frame, UIScreen.main.bounds.size)
|
for view in views {
|
||||||
|
let rect = view.frame
|
||||||
self.containerNode.layer.animatePosition(from: CGPoint(x: 0.0, y: sourceAbsoluteRect.midY - targetAbsoluteRect.midY), to: CGPoint(), duration: horizontalDuration, delay: delay, mediaTimingFunction: ChatMessageTransitionNode.horizontalAnimationCurve.mediaTimingFunction, additive: true, force: true)
|
if rect.minX < minX {
|
||||||
self.containerNode.layer.animatePosition(from: CGPoint(x: sourceAbsoluteRect.midX - targetAbsoluteRect.midX, y: 0.0), to: CGPoint(), duration: verticalDuration, delay: delay, mediaTimingFunction: ChatMessageTransitionNode.verticalAnimationCurve.mediaTimingFunction, additive: true, force: true, completion: { [weak self] _ in
|
minX = rect.minX
|
||||||
guard let strongSelf = self else {
|
}
|
||||||
return
|
if rect.minY < minY {
|
||||||
|
minY = rect.minY
|
||||||
|
}
|
||||||
|
if rect.maxX > maxX {
|
||||||
|
maxX = rect.maxX
|
||||||
|
}
|
||||||
|
if rect.maxY > maxY {
|
||||||
|
maxY = rect.maxY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CGRect(origin: CGPoint(x: minX, y: minY), size: CGSize(width: maxX - minX, height: maxY - minY))
|
||||||
}
|
}
|
||||||
strongSelf.endAnimation()
|
|
||||||
})
|
|
||||||
|
|
||||||
combinedTransition.horizontal.animateTransformScale(node: self.contextSourceNode.contentNode, from: CGPoint(x: sourceBackgroundAbsoluteRect.width / targetAbsoluteRect.width, y: sourceBackgroundAbsoluteRect.height / targetAbsoluteRect.height))
|
let sourceBackgroundAbsoluteRect = boundingRect(for: snapshotViews)
|
||||||
|
let sourceAbsoluteRect = CGRect(origin: CGPoint(x: sourceBackgroundAbsoluteRect.midX - self.contextSourceNode.contentRect.size.width / 2.0, y: sourceBackgroundAbsoluteRect.midY - self.contextSourceNode.contentRect.size.height / 2.0), size: self.contextSourceNode.contentRect.size)
|
||||||
|
|
||||||
var index = 0
|
self.containerNode.frame = targetAbsoluteRect.offsetBy(dx: -self.contextSourceNode.contentRect.minX, dy: -self.contextSourceNode.contentRect.minY)
|
||||||
for snapshotView in snapshotViews {
|
|
||||||
let targetContentRect = targetContentRects[index]
|
|
||||||
let targetAbsoluteContentRect = targetContentRect.offsetBy(dx: targetAbsoluteRect.minX, dy: targetAbsoluteRect.minY)
|
|
||||||
|
|
||||||
snapshotView.center = targetAbsoluteContentRect.center.offsetBy(dx: -self.containerNode.frame.minX, dy: -self.containerNode.frame.minY)
|
self.contextSourceNode.updateAbsoluteRect?(self.containerNode.frame, UIScreen.main.bounds.size)
|
||||||
self.containerNode.view.addSubview(snapshotView)
|
|
||||||
|
|
||||||
combinedTransition.horizontal.updateTransformScale(layer: snapshotView.layer, scale: CGPoint(x: 1.0 / (snapshotView.frame.width / targetContentRect.width), y: 1.0 / (snapshotView.frame.height / targetContentRect.height)))
|
self.containerNode.layer.animatePosition(from: CGPoint(x: 0.0, y: sourceAbsoluteRect.midY - targetAbsoluteRect.midY), to: CGPoint(), duration: horizontalDuration, delay: delay, mediaTimingFunction: ChatMessageTransitionNode.horizontalAnimationCurve.mediaTimingFunction, additive: true, force: true)
|
||||||
|
self.containerNode.layer.animatePosition(from: CGPoint(x: sourceAbsoluteRect.midX - targetAbsoluteRect.midX, y: 0.0), to: CGPoint(), duration: verticalDuration, delay: delay, mediaTimingFunction: ChatMessageTransitionNode.verticalAnimationCurve.mediaTimingFunction, additive: true, force: true, completion: { [weak self] _ in
|
||||||
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.12, removeOnCompletion: false, completion: { [weak snapshotView] _ in
|
guard let strongSelf = self else {
|
||||||
snapshotView?.removeFromSuperview()
|
return
|
||||||
|
}
|
||||||
|
strongSelf.endAnimation()
|
||||||
})
|
})
|
||||||
|
|
||||||
index += 1
|
combinedTransition.horizontal.animateTransformScale(node: self.contextSourceNode.contentNode, from: CGPoint(x: sourceBackgroundAbsoluteRect.width / targetAbsoluteRect.width, y: sourceBackgroundAbsoluteRect.height / targetAbsoluteRect.height))
|
||||||
}
|
|
||||||
|
|
||||||
self.contextSourceNode.applyAbsoluteOffset?(CGPoint(x: sourceAbsoluteRect.minX - targetAbsoluteRect.minX, y: 0.0), ChatMessageTransitionNode.horizontalAnimationCurve, horizontalDuration)
|
var index = 0
|
||||||
self.contextSourceNode.applyAbsoluteOffset?(CGPoint(x: 0.0, y: sourceAbsoluteRect.maxY - targetAbsoluteRect.maxY), ChatMessageTransitionNode.verticalAnimationCurve, verticalDuration)
|
for snapshotView in snapshotViews {
|
||||||
|
let targetContentRect = targetContentRects[index]
|
||||||
|
let targetAbsoluteContentRect = targetContentRect.offsetBy(dx: targetAbsoluteRect.minX, dy: targetAbsoluteRect.minY)
|
||||||
|
|
||||||
|
snapshotView.center = targetAbsoluteContentRect.center.offsetBy(dx: -self.containerNode.frame.minX, dy: -self.containerNode.frame.minY)
|
||||||
|
self.containerNode.view.addSubview(snapshotView)
|
||||||
|
|
||||||
|
combinedTransition.horizontal.updateTransformScale(layer: snapshotView.layer, scale: CGPoint(x: 1.0 / (snapshotView.frame.width / targetContentRect.width), y: 1.0 / (snapshotView.frame.height / targetContentRect.height)))
|
||||||
|
|
||||||
|
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.12, removeOnCompletion: false, completion: { [weak snapshotView] _ in
|
||||||
|
snapshotView?.removeFromSuperview()
|
||||||
|
})
|
||||||
|
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
self.contextSourceNode.applyAbsoluteOffset?(CGPoint(x: sourceAbsoluteRect.minX - targetAbsoluteRect.minX, y: 0.0), ChatMessageTransitionNode.horizontalAnimationCurve, horizontalDuration)
|
||||||
|
self.contextSourceNode.applyAbsoluteOffset?(CGPoint(x: 0.0, y: sourceAbsoluteRect.maxY - targetAbsoluteRect.maxY), ChatMessageTransitionNode.verticalAnimationCurve, verticalDuration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user