mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
[WIP] Entity input panel
This commit is contained in:
@@ -53,7 +53,7 @@ private func makeSpringAnimation(keyPath: String) -> CASpringAnimation {
|
||||
}
|
||||
|
||||
private extension CALayer {
|
||||
func makeAnimation(from: AnyObject, to: AnyObject, keyPath: String, duration: Double, delay: Double, curve: Transition.Animation.Curve, removeOnCompletion: Bool, additive: Bool, completion: ((Bool) -> Void)? = nil) -> CAAnimation {
|
||||
func makeAnimation(from: AnyObject?, to: AnyObject, keyPath: String, duration: Double, delay: Double, curve: Transition.Animation.Curve, removeOnCompletion: Bool, additive: Bool, completion: ((Bool) -> Void)? = nil) -> CAAnimation {
|
||||
switch curve {
|
||||
case .spring:
|
||||
let animation = makeSpringAnimation(keyPath: keyPath)
|
||||
@@ -88,12 +88,14 @@ private extension CALayer {
|
||||
}
|
||||
|
||||
let animation = CABasicAnimation(keyPath: keyPath)
|
||||
animation.fromValue = from
|
||||
if let from = from {
|
||||
animation.fromValue = from
|
||||
}
|
||||
animation.toValue = to
|
||||
animation.duration = duration
|
||||
animation.timingFunction = curve.asTimingFunction()
|
||||
animation.isRemovedOnCompletion = removeOnCompletion
|
||||
animation.fillMode = .forwards
|
||||
animation.fillMode = .both
|
||||
animation.speed = speed
|
||||
animation.isAdditive = additive
|
||||
if let completion = completion {
|
||||
@@ -225,6 +227,36 @@ public struct Transition {
|
||||
}
|
||||
}
|
||||
|
||||
public func setFrame(layer: CALayer, frame: CGRect, completion: ((Bool) -> Void)? = nil) {
|
||||
if layer.frame == frame {
|
||||
completion?(true)
|
||||
return
|
||||
}
|
||||
switch self.animation {
|
||||
case .none:
|
||||
layer.frame = frame
|
||||
//view.bounds = CGRect(origin: view.bounds.origin, size: frame.size)
|
||||
//view.layer.position = CGPoint(x: frame.midX, y: frame.midY)
|
||||
layer.removeAnimation(forKey: "position")
|
||||
layer.removeAnimation(forKey: "bounds")
|
||||
completion?(true)
|
||||
case .curve:
|
||||
let previousFrame: CGRect
|
||||
if (layer.animation(forKey: "position") != nil || layer.animation(forKey: "bounds") != nil), let presentation = layer.presentation() {
|
||||
previousFrame = presentation.frame
|
||||
} else {
|
||||
previousFrame = layer.frame
|
||||
}
|
||||
|
||||
layer.frame = frame
|
||||
//view.bounds = CGRect(origin: previousBounds.origin, size: frame.size)
|
||||
//view.center = CGPoint(x: frame.midX, y: frame.midY)
|
||||
|
||||
self.animatePosition(layer: layer, from: CGPoint(x: previousFrame.midX, y: previousFrame.midY), to: CGPoint(x: frame.midX, y: frame.midY), completion: completion)
|
||||
self.animateBounds(layer: layer, from: CGRect(origin: layer.bounds.origin, size: previousFrame.size), to: CGRect(origin: layer.bounds.origin, size: frame.size))
|
||||
}
|
||||
}
|
||||
|
||||
public func setBounds(view: UIView, bounds: CGRect, completion: ((Bool) -> Void)? = nil) {
|
||||
if view.bounds == bounds {
|
||||
completion?(true)
|
||||
@@ -454,6 +486,10 @@ public struct Transition {
|
||||
self.animateBounds(layer: view.layer, from: fromValue, to: toValue, additive: additive, completion: completion)
|
||||
}
|
||||
|
||||
public func animateBoundsOrigin(view: UIView, from fromValue: CGPoint, to toValue: CGPoint, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
self.animateBoundsOrigin(layer: view.layer, from: fromValue, to: toValue, additive: additive, completion: completion)
|
||||
}
|
||||
|
||||
public func animatePosition(layer: CALayer, from fromValue: CGPoint, to toValue: CGPoint, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
switch self.animation {
|
||||
case .none:
|
||||
@@ -491,4 +527,102 @@ public struct Transition {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func animateBoundsOrigin(layer: CALayer, from fromValue: CGPoint, to toValue: CGPoint, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
switch self.animation {
|
||||
case .none:
|
||||
break
|
||||
case let .curve(duration, curve):
|
||||
layer.animate(
|
||||
from: NSValue(cgPoint: fromValue),
|
||||
to: NSValue(cgPoint: toValue),
|
||||
keyPath: "bounds.origin",
|
||||
duration: duration,
|
||||
delay: 0.0,
|
||||
curve: curve,
|
||||
removeOnCompletion: true,
|
||||
additive: additive,
|
||||
completion: completion
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func setCornerRadius(layer: CALayer, cornerRadius: CGFloat, completion: ((Bool) -> Void)? = nil) {
|
||||
if layer.cornerRadius == cornerRadius {
|
||||
return
|
||||
}
|
||||
switch self.animation {
|
||||
case .none:
|
||||
layer.cornerRadius = cornerRadius
|
||||
completion?(true)
|
||||
case let .curve(duration, curve):
|
||||
let fromValue: CGFloat
|
||||
if layer.animation(forKey: "cornerRadius") != nil, let presentation = layer.presentation() {
|
||||
fromValue = presentation.cornerRadius
|
||||
} else {
|
||||
fromValue = layer.cornerRadius
|
||||
}
|
||||
layer.cornerRadius = cornerRadius
|
||||
layer.animate(
|
||||
from: fromValue as NSNumber,
|
||||
to: cornerRadius as NSNumber,
|
||||
keyPath: "cornerRadius",
|
||||
duration: duration,
|
||||
delay: 0.0,
|
||||
curve: curve,
|
||||
removeOnCompletion: true,
|
||||
additive: false,
|
||||
completion: completion
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func setShapeLayerPath(layer: CAShapeLayer, path: CGPath, completion: ((Bool) -> Void)? = nil) {
|
||||
switch self.animation {
|
||||
case .none:
|
||||
layer.path = path
|
||||
case let .curve(duration, curve):
|
||||
if let previousPath = layer.path {
|
||||
layer.animate(
|
||||
from: previousPath,
|
||||
to: path,
|
||||
keyPath: "path",
|
||||
duration: duration,
|
||||
delay: 0.0,
|
||||
curve: curve,
|
||||
removeOnCompletion: true,
|
||||
additive: false,
|
||||
completion: completion
|
||||
)
|
||||
layer.path = path
|
||||
} else {
|
||||
layer.path = path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func setShapeLayerLineDashPattern(layer: CAShapeLayer, pattern: [NSNumber], completion: ((Bool) -> Void)? = nil) {
|
||||
switch self.animation {
|
||||
case .none:
|
||||
layer.lineDashPattern = pattern
|
||||
case let .curve(duration, curve):
|
||||
if let previousLineDashPattern = layer.lineDashPattern {
|
||||
layer.lineDashPattern = pattern
|
||||
|
||||
layer.animate(
|
||||
from: previousLineDashPattern as CFArray,
|
||||
to: pattern as CFArray,
|
||||
keyPath: "lineDashPattern",
|
||||
duration: duration,
|
||||
delay: 0.0,
|
||||
curve: curve,
|
||||
removeOnCompletion: true,
|
||||
additive: false,
|
||||
completion: completion
|
||||
)
|
||||
} else {
|
||||
layer.lineDashPattern = pattern
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user