[WIP] Reaction UI improvements

This commit is contained in:
Ali
2022-09-14 00:03:32 +04:00
parent 8fe1e77376
commit ab76f8b02a
40 changed files with 1321 additions and 298 deletions

View File

@@ -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