Various improvements

This commit is contained in:
Ilya Laktyushin
2025-08-08 19:23:59 +04:00
parent 5c1952162b
commit 9146a42cfa
26 changed files with 1526 additions and 162 deletions

View File

@@ -64,6 +64,7 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
public let followContentSizeChanges: Bool
public let clipsContent: Bool
public let isScrollEnabled: Bool
public let hasDimView: Bool
public let externalState: ExternalState?
public let animateOut: ActionSlot<Action<()>>
public let onPan: () -> Void
@@ -75,6 +76,7 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
followContentSizeChanges: Bool = false,
clipsContent: Bool = false,
isScrollEnabled: Bool = true,
hasDimView: Bool = true,
externalState: ExternalState? = nil,
animateOut: ActionSlot<Action<()>>,
onPan: @escaping () -> Void = {},
@@ -85,6 +87,7 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
self.followContentSizeChanges = followContentSizeChanges
self.clipsContent = clipsContent
self.isScrollEnabled = isScrollEnabled
self.hasDimView = hasDimView
self.externalState = externalState
self.animateOut = animateOut
self.onPan = onPan
@@ -101,6 +104,12 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
if lhs.followContentSizeChanges != rhs.followContentSizeChanges {
return false
}
if lhs.isScrollEnabled != rhs.isScrollEnabled {
return false
}
if lhs.hasDimView != rhs.hasDimView {
return false
}
if lhs.animateOut != rhs.animateOut {
return false
}
@@ -414,6 +423,10 @@ public final class SheetComponent<ChildEnvironmentType: Sendable & Equatable>: C
self.currentAvailableSize = availableSize
if !component.hasDimView {
self.dimView.backgroundColor = .clear
}
if environment[SheetComponentEnvironment.self].value.isDisplaying, !self.previousIsDisplaying, let _ = transition.userData(ViewControllerComponentContainer.AnimateInTransition.self) {
self.animateIn()
} else if !environment[SheetComponentEnvironment.self].value.isDisplaying, self.previousIsDisplaying, let _ = transition.userData(ViewControllerComponentContainer.AnimateOutTransition.self) {

View File

@@ -134,9 +134,13 @@ open class ViewControllerComponentContainer: ViewController {
}
public final class AnimateInTransition {
public init() {
}
}
public final class AnimateOutTransition {
public init() {
}
}
public final class Node: ViewControllerTracingNode {
@@ -356,7 +360,7 @@ open class ViewControllerComponentContainer: ViewController {
}
if let layout = strongSelf.validLayout {
strongSelf.containerLayoutUpdated(layout, transition: .immediate)
strongSelf.containerLayoutUpdated(layout, transition: ContainedViewLayoutTransition.immediate)
}
}
}).strict()
@@ -412,6 +416,14 @@ open class ViewControllerComponentContainer: ViewController {
self.forceNextUpdate = false
}
public func requestLayout(forceUpdate: Bool, transition: ComponentTransition) {
self.forceNextUpdate = forceUpdate
if self.isViewLoaded, let validLayout = self.validLayout {
self.containerLayoutUpdated(validLayout, transition: transition)
}
self.forceNextUpdate = false
}
override open func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition)
@@ -421,6 +433,15 @@ open class ViewControllerComponentContainer: ViewController {
self.node.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: ComponentTransition(transition))
}
public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ComponentTransition) {
super.containerLayoutUpdated(layout, transition: transition.containedViewLayoutTransition)
let navigationHeight = self.navigationLayout(layout: layout).navigationFrame.maxY
self.validLayout = layout
self.node.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: transition)
}
public func updateComponent(component: AnyComponent<ViewControllerComponentContainer.Environment>, transition: ComponentTransition) {
self.component = component
self.node.updateComponent(component: component, transition: transition)