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

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