Storage calculation

This commit is contained in:
Ali
2022-12-20 21:26:55 +04:00
parent 34909d0de9
commit 45ff6ba714
23 changed files with 2778 additions and 60 deletions

View File

@@ -605,7 +605,7 @@ public struct Transition {
public func animateBounds(layer: CALayer, from fromValue: CGRect, to toValue: CGRect, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
switch self.animation {
case .none:
break
completion?(true)
case let .curve(duration, curve):
layer.animate(
from: NSValue(cgRect: fromValue),
@@ -624,7 +624,7 @@ 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
completion?(true)
case let .curve(duration, curve):
layer.animate(
from: NSValue(cgPoint: fromValue),
@@ -643,7 +643,7 @@ 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
completion?(true)
case let .curve(duration, curve):
layer.animate(
from: NSValue(cgSize: fromValue),
@@ -661,6 +661,7 @@ public struct Transition {
public func setCornerRadius(layer: CALayer, cornerRadius: CGFloat, completion: ((Bool) -> Void)? = nil) {
if layer.cornerRadius == cornerRadius {
completion?(true)
return
}
switch self.animation {
@@ -693,8 +694,9 @@ public struct Transition {
switch self.animation {
case .none:
layer.path = path
completion?(true)
case let .curve(duration, curve):
if let previousPath = layer.path {
if let previousPath = layer.path, previousPath != path {
layer.animate(
from: previousPath,
to: path,
@@ -709,6 +711,7 @@ public struct Transition {
layer.path = path
} else {
layer.path = path
completion?(true)
}
}
}
@@ -717,6 +720,7 @@ public struct Transition {
switch self.animation {
case .none:
layer.lineWidth = lineWidth
completion?(true)
case let .curve(duration, curve):
let previousLineWidth = layer.lineWidth
layer.lineWidth = lineWidth
@@ -739,6 +743,7 @@ public struct Transition {
switch self.animation {
case .none:
layer.lineDashPattern = pattern
completion?(true)
case let .curve(duration, curve):
if let previousLineDashPattern = layer.lineDashPattern {
layer.lineDashPattern = pattern
@@ -756,6 +761,7 @@ public struct Transition {
)
} else {
layer.lineDashPattern = pattern
completion?(true)
}
}
}

View File

@@ -141,6 +141,7 @@ public final class ComponentView<EnvironmentType> {
private var currentSize: CGSize?
public private(set) var view: UIView?
private(set) var isUpdating: Bool = false
public weak var parentState: ComponentState?
public init() {
}
@@ -181,10 +182,15 @@ public final class ComponentView<EnvironmentType> {
context.erasedEnvironment = environmentResult
}
let isEnvironmentUpdated = context.erasedEnvironment.calculateIsUpdated()
var isStateUpdated = false
if componentState.isUpdated {
isStateUpdated = true
componentState.isUpdated = false
}
if !forceUpdate, !isEnvironmentUpdated, let currentComponent = self.currentComponent, let currentContainerSize = self.currentContainerSize, let currentSize = self.currentSize {
let isEnvironmentUpdated = context.erasedEnvironment.calculateIsUpdated()
if !forceUpdate, !isEnvironmentUpdated, !isStateUpdated, let currentComponent = self.currentComponent, let currentContainerSize = self.currentContainerSize, let currentSize = self.currentSize {
if currentContainerSize == containerSize && currentComponent == component {
self.isUpdating = false
return currentSize
@@ -197,9 +203,13 @@ public final class ComponentView<EnvironmentType> {
guard let strongSelf = self else {
return
}
let _ = strongSelf._update(transition: transition, component: component, maybeEnvironment: {
preconditionFailure()
} as () -> Environment<EnvironmentType>, updateEnvironment: false, forceUpdate: true, containerSize: containerSize)
if let parentState = strongSelf.parentState {
parentState.updated(transition: transition)
} else {
let _ = strongSelf._update(transition: transition, component: component, maybeEnvironment: {
preconditionFailure()
} as () -> Environment<EnvironmentType>, updateEnvironment: false, forceUpdate: true, containerSize: containerSize)
}
}
let updatedSize = component._update(view: componentView, availableSize: containerSize, environment: context.erasedEnvironment, transition: transition)
@@ -207,6 +217,9 @@ public final class ComponentView<EnvironmentType> {
if isEnvironmentUpdated {
context.erasedEnvironment._isUpdated = false
}
if isStateUpdated {
context.erasedState.isUpdated = false
}
self.isUpdating = false