Storage improvements

This commit is contained in:
Ali
2022-12-24 00:04:48 +04:00
parent dd06922e85
commit 808f5b80ff
25 changed files with 3384 additions and 655 deletions

View File

@@ -765,4 +765,36 @@ public struct Transition {
}
}
}
public func setBackgroundColor(view: UIView, color: UIColor, completion: ((Bool) -> Void)? = nil) {
self.setBackgroundColor(layer: view.layer, color: color, completion: completion)
}
public func setBackgroundColor(layer: CALayer, color: UIColor, completion: ((Bool) -> Void)? = nil) {
if let current = layer.backgroundColor, current == color.cgColor {
completion?(true)
return
}
switch self.animation {
case .none:
layer.backgroundColor = color.cgColor
completion?(true)
case let .curve(duration, curve):
let previousColor: CGColor = layer.backgroundColor ?? UIColor.clear.cgColor
layer.backgroundColor = color.cgColor
layer.animate(
from: previousColor,
to: color.cgColor,
keyPath: "backgroundColor",
duration: duration,
delay: 0.0,
curve: curve,
removeOnCompletion: true,
additive: false,
completion: completion
)
}
}
}

View File

@@ -155,6 +155,15 @@ public final class ComponentView<EnvironmentType> {
self.currentSize = size
return size
}
public func updateEnvironment(transition: Transition, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>) -> CGSize? {
guard let currentComponent = self.currentComponent, let currentContainerSize = self.currentContainerSize else {
return nil
}
let size = self._update(transition: transition, component: currentComponent, maybeEnvironment: environment, updateEnvironment: true, forceUpdate: false, containerSize: currentContainerSize)
self.currentSize = size
return size
}
private func _update(transition: Transition, component: AnyComponent<EnvironmentType>, maybeEnvironment: () -> Environment<EnvironmentType>, updateEnvironment: Bool, forceUpdate: Bool, containerSize: CGSize) -> CGSize {
precondition(!self.isUpdating)