mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
[WIP] Reaction UI improvements
This commit is contained in:
@@ -280,6 +280,29 @@ public struct Transition {
|
||||
}
|
||||
}
|
||||
|
||||
public func setBoundsSize(view: UIView, size: CGSize, completion: ((Bool) -> Void)? = nil) {
|
||||
if view.bounds.size == size {
|
||||
completion?(true)
|
||||
return
|
||||
}
|
||||
switch self.animation {
|
||||
case .none:
|
||||
view.bounds.size = size
|
||||
view.layer.removeAnimation(forKey: "bounds.size")
|
||||
completion?(true)
|
||||
case .curve:
|
||||
let previousBounds: CGRect
|
||||
if view.layer.animation(forKey: "bounds.size") != nil, let presentation = view.layer.presentation() {
|
||||
previousBounds = presentation.bounds
|
||||
} else {
|
||||
previousBounds = view.layer.bounds
|
||||
}
|
||||
view.bounds = CGRect(origin: view.bounds.origin, size: size)
|
||||
|
||||
self.animateBoundsSize(view: view, from: previousBounds.size, to: size, completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
public func setPosition(view: UIView, position: CGPoint, completion: ((Bool) -> Void)? = nil) {
|
||||
if view.center == position {
|
||||
completion?(true)
|
||||
@@ -552,6 +575,10 @@ public struct Transition {
|
||||
self.animateBoundsOrigin(layer: view.layer, from: fromValue, to: toValue, additive: additive, completion: completion)
|
||||
}
|
||||
|
||||
public func animateBoundsSize(view: UIView, from fromValue: CGSize, to toValue: CGSize, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
self.animateBoundsSize(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:
|
||||
@@ -609,6 +636,25 @@ public struct Transition {
|
||||
}
|
||||
}
|
||||
|
||||
public func animateBoundsSize(layer: CALayer, from fromValue: CGSize, to toValue: CGSize, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
switch self.animation {
|
||||
case .none:
|
||||
break
|
||||
case let .curve(duration, curve):
|
||||
layer.animate(
|
||||
from: NSValue(cgSize: fromValue),
|
||||
to: NSValue(cgSize: toValue),
|
||||
keyPath: "bounds.size",
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user