mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
UI Improvements
This commit is contained in:
@@ -9,10 +9,11 @@ public final class ContextControllerSourceNode: ASDisplayNode {
|
||||
self.contextGesture?.isEnabled = self.isGestureEnabled
|
||||
}
|
||||
}
|
||||
public var activated: ((ContextGesture) -> Void)?
|
||||
public var activated: ((ContextGesture, CGPoint) -> Void)?
|
||||
public var shouldBegin: ((CGPoint) -> Bool)?
|
||||
public var customActivationProgress: ((CGFloat, ContextGestureTransition) -> Void)?
|
||||
public var targetNodeForActivationProgress: ASDisplayNode?
|
||||
public var targetNodeForActivationProgressContentRect: CGRect?
|
||||
|
||||
public func cancelGesture() {
|
||||
self.contextGesture?.cancel()
|
||||
@@ -41,25 +42,53 @@ public final class ContextControllerSourceNode: ASDisplayNode {
|
||||
if let customActivationProgress = strongSelf.customActivationProgress {
|
||||
customActivationProgress(progress, update)
|
||||
} else {
|
||||
let targetNode = strongSelf.targetNodeForActivationProgress ?? strongSelf
|
||||
let targetNode: ASDisplayNode
|
||||
let targetContentRect: CGRect
|
||||
if let targetNodeForActivationProgress = strongSelf.targetNodeForActivationProgress {
|
||||
targetNode = targetNodeForActivationProgress
|
||||
if let targetNodeForActivationProgressContentRect = strongSelf.targetNodeForActivationProgressContentRect {
|
||||
targetContentRect = targetNodeForActivationProgressContentRect
|
||||
} else {
|
||||
targetContentRect = CGRect(origin: CGPoint(), size: targetNode.bounds.size)
|
||||
}
|
||||
} else {
|
||||
targetNode = strongSelf
|
||||
targetContentRect = CGRect(origin: CGPoint(), size: targetNode.bounds.size)
|
||||
}
|
||||
|
||||
let minScale: CGFloat = (strongSelf.bounds.width - 10.0) / strongSelf.bounds.width
|
||||
let minScale: CGFloat = (targetContentRect.width - 10.0) / targetContentRect.width
|
||||
let currentScale = 1.0 * (1.0 - progress) + minScale * progress
|
||||
|
||||
let originalCenterOffsetX: CGFloat = targetNode.bounds.width / 2.0 - targetContentRect.midX
|
||||
let scaledCaneterOffsetX: CGFloat = originalCenterOffsetX * currentScale
|
||||
|
||||
let originalCenterOffsetY: CGFloat = targetNode.bounds.height / 2.0 - targetContentRect.midY
|
||||
let scaledCaneterOffsetY: CGFloat = originalCenterOffsetY * currentScale
|
||||
|
||||
let scaleMidX: CGFloat = scaledCaneterOffsetX - originalCenterOffsetX
|
||||
let scaleMidY: CGFloat = scaledCaneterOffsetY - originalCenterOffsetY
|
||||
|
||||
switch update {
|
||||
case .update:
|
||||
targetNode.layer.sublayerTransform = CATransform3DMakeScale(currentScale, currentScale, 1.0)
|
||||
let sublayerTransform = CATransform3DTranslate(CATransform3DScale(CATransform3DIdentity, currentScale, currentScale, 1.0), scaleMidX, scaleMidY, 0.0)
|
||||
targetNode.layer.sublayerTransform = sublayerTransform
|
||||
case .begin:
|
||||
targetNode.layer.sublayerTransform = CATransform3DMakeScale(currentScale, currentScale, 1.0)
|
||||
case let .ended(previousProgress):
|
||||
let previousScale = 1.0 * (1.0 - previousProgress) + minScale * previousProgress
|
||||
targetNode.layer.sublayerTransform = CATransform3DMakeScale(currentScale, currentScale, 1.0)
|
||||
targetNode.layer.animateSpring(from: previousScale as NSNumber, to: currentScale as NSNumber, keyPath: "sublayerTransform.scale", duration: 0.5, delay: 0.0, initialVelocity: 0.0, damping: 90.0)
|
||||
let sublayerTransform = CATransform3DTranslate(CATransform3DScale(CATransform3DIdentity, currentScale, currentScale, 1.0), scaleMidX, scaleMidY, 0.0)
|
||||
targetNode.layer.sublayerTransform = sublayerTransform
|
||||
case .ended:
|
||||
let sublayerTransform = CATransform3DTranslate(CATransform3DScale(CATransform3DIdentity, currentScale, currentScale, 1.0), scaleMidX, scaleMidY, 0.0)
|
||||
let previousTransform = targetNode.layer.sublayerTransform
|
||||
targetNode.layer.sublayerTransform = sublayerTransform
|
||||
|
||||
targetNode.layer.animate(from: NSValue(caTransform3D: previousTransform), to: NSValue(caTransform3D: sublayerTransform), keyPath: "sublayerTransform", timingFunction: CAMediaTimingFunctionName.easeOut.rawValue, duration: 0.2)
|
||||
|
||||
//targetNode.layer.animateSpring(from: previousScale as NSNumber, to: currentScale as NSNumber, keyPath: "sublayerTransform.scale", duration: 0.5, delay: 0.0, initialVelocity: 0.0, damping: 90.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
contextGesture.activated = { [weak self] gesture in
|
||||
contextGesture.activated = { [weak self] gesture, location in
|
||||
if let activated = self?.activated {
|
||||
activated(gesture)
|
||||
activated(gesture, location)
|
||||
} else {
|
||||
gesture.cancel()
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class ContextGesture: UIGestureRecognizer, UIGestureRecognizerDeleg
|
||||
|
||||
public var shouldBegin: ((CGPoint) -> Bool)?
|
||||
public var activationProgress: ((CGFloat, ContextGestureTransition) -> Void)?
|
||||
public var activated: ((ContextGesture) -> Void)?
|
||||
public var activated: ((ContextGesture, CGPoint) -> Void)?
|
||||
public var externalUpdated: ((UIView?, CGPoint) -> Void)?
|
||||
public var externalEnded: (((UIView?, CGPoint)?) -> Void)?
|
||||
|
||||
@@ -95,9 +95,10 @@ public final class ContextGesture: UIGestureRecognizer, UIGestureRecognizerDeleg
|
||||
guard let touch = touches.first else {
|
||||
return
|
||||
}
|
||||
let location = touch.location(in: self.view)
|
||||
|
||||
if let shouldBegin = self.shouldBegin {
|
||||
if !shouldBegin(touch.location(in: self.view)) {
|
||||
if !shouldBegin(location) {
|
||||
self.state = .failed
|
||||
return
|
||||
}
|
||||
@@ -132,7 +133,7 @@ public final class ContextGesture: UIGestureRecognizer, UIGestureRecognizerDeleg
|
||||
case .possible:
|
||||
strongSelf.delayTimer?.invalidate()
|
||||
strongSelf.animator?.invalidate()
|
||||
strongSelf.activated?(strongSelf)
|
||||
strongSelf.activated?(strongSelf, location)
|
||||
if let view = strongSelf.view?.superview {
|
||||
if let window = view.window {
|
||||
cancelOtherGestures(gesture: strongSelf, view: window)
|
||||
@@ -167,7 +168,7 @@ public final class ContextGesture: UIGestureRecognizer, UIGestureRecognizerDeleg
|
||||
case .possible:
|
||||
self.delayTimer?.invalidate()
|
||||
self.animator?.invalidate()
|
||||
self.activated?(self)
|
||||
self.activated?(self, touch.location(in: self.view))
|
||||
if let view = self.view?.superview {
|
||||
if let window = view.window {
|
||||
cancelOtherGestures(gesture: self, view: window)
|
||||
|
||||
@@ -248,7 +248,7 @@ private final class TabBarNodeContainer {
|
||||
updateSelectedImage(value)
|
||||
}
|
||||
|
||||
imageNode.containerNode.activated = { [weak self] gesture in
|
||||
imageNode.containerNode.activated = { [weak self] gesture, _ in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user