Refactoring

This commit is contained in:
Isaac
2024-06-12 23:04:04 +04:00
parent 1b1846dc63
commit 9a075fa39e
360 changed files with 1830 additions and 1713 deletions

View File

@@ -416,7 +416,7 @@ private final class BlurredGradientComponent: Component {
private var gradientMask = UIImageView()
private var gradientForeground = SimpleGradientLayer()
public func update(component: BlurredGradientComponent, availableSize: CGSize, transition: Transition) -> CGSize {
public func update(component: BlurredGradientComponent, availableSize: CGSize, transition: ComponentTransition) -> CGSize {
self.component = component
self.isUserInteractionEnabled = false
@@ -452,7 +452,7 @@ private final class BlurredGradientComponent: Component {
return View(color: nil, enableBlur: true)
}
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
return view.update(component: self, availableSize: availableSize, transition: transition)
}
}
@@ -1303,12 +1303,12 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(textSettings
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - environment.safeInsets.bottom - textSettings.size.height / 2.0 - 89.0 - additionalBottomInset))
.appear(Transition.Appear({ _, view, transition in
.appear(ComponentTransition.Appear({ _, view, transition in
if let view = view as? TextSettingsComponent.View, !transition.animation.isImmediate {
view.animateIn()
}
}))
.disappear(Transition.Disappear({ view, transition, completion in
.disappear(ComponentTransition.Disappear({ view, transition, completion in
if let view = view as? TextSettingsComponent.View, !transition.animation.isImmediate {
view.animateOut(completion: completion)
} else {
@@ -1353,11 +1353,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch1Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch1Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0)
transition.animateAlpha(view: view, from: 0.0, to: 1.0)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1381,11 +1381,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch2Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch2Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.025)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.025)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1409,11 +1409,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch3Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch3Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.05)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.05)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1437,11 +1437,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch4Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch4Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.075)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.075)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1465,11 +1465,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch5Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch5Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.1)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.1)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1494,11 +1494,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch6Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch6Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.125)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.125)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1522,11 +1522,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch7Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch7Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.15)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.15)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1550,11 +1550,11 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(swatch8Button
.position(CGPoint(x: offsetX, y: context.availableSize.height - environment.safeInsets.bottom - swatch7Button.size.height / 2.0 - 57.0 - additionalBottomInset))
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0, delay: 0.175)
transition.animateAlpha(view: view, from: 0.0, to: 1.0, delay: 0.175)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -1592,12 +1592,12 @@ private final class DrawingScreenComponent: CombinedComponent {
)
context.add(tools
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - environment.safeInsets.bottom - tools.size.height / 2.0 - 78.0 - additionalBottomInset))
.appear(Transition.Appear({ _, view, transition in
.appear(ComponentTransition.Appear({ _, view, transition in
if let view = view as? ToolsComponent.View, !transition.animation.isImmediate {
view.animateIn(completion: {})
}
}))
.disappear(Transition.Disappear({ view, transition, completion in
.disappear(ComponentTransition.Disappear({ view, transition, completion in
if let view = view as? ToolsComponent.View, !transition.animation.isImmediate {
view.animateOut(completion: completion)
} else {
@@ -2012,13 +2012,13 @@ private final class DrawingScreenComponent: CombinedComponent {
}
context.add(doneButton
.position(doneButtonPosition)
.appear(Transition.Appear { _, view, transition in
.appear(ComponentTransition.Appear { _, view, transition in
transition.animateScale(view: view, from: 0.1, to: 1.0)
transition.animateAlpha(view: view, from: 0.0, to: 1.0)
transition.animatePosition(view: view, from: CGPoint(x: 12.0, y: 0.0), to: CGPoint(), additive: true)
})
.disappear(Transition.Disappear { view, transition, completion in
.disappear(ComponentTransition.Disappear { view, transition, completion in
transition.setScale(view: view, scale: 0.1)
transition.setAlpha(view: view, alpha: 0.0, completion: { _ in
completion()
@@ -2614,13 +2614,13 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U
return result
}
func requestUpdate(transition: Transition = .immediate) {
func requestUpdate(transition: ComponentTransition = .immediate) {
if let (layout, orientation) = self.validLayout {
self.containerLayoutUpdated(layout: layout, orientation: orientation, transition: transition)
}
}
func containerLayoutUpdated(layout: ContainerViewLayout, orientation: UIInterfaceOrientation?, forceUpdate: Bool = false, animateOut: Bool = false, transition: Transition) {
func containerLayoutUpdated(layout: ContainerViewLayout, orientation: UIInterfaceOrientation?, forceUpdate: Bool = false, animateOut: Bool = false, transition: ComponentTransition) {
guard let controller = self.controller else {
return
}
@@ -2922,7 +2922,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition)
(self.displayNode as! Node).containerLayoutUpdated(layout: layout, orientation: self.orientation, transition: Transition(transition))
(self.displayNode as! Node).containerLayoutUpdated(layout: layout, orientation: self.orientation, transition: ComponentTransition(transition))
}
public func adapterContainerLayoutUpdatedSize(_ size: CGSize, intrinsicInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, statusBarHeight: CGFloat, inputHeight: CGFloat, orientation: UIInterfaceOrientation, isRegular: Bool, animated: Bool) {
@@ -3534,7 +3534,7 @@ public final class DrawingToolsInteraction {
}
}
public func containerLayoutUpdated(layout: ContainerViewLayout, transition: Transition) {
public func containerLayoutUpdated(layout: ContainerViewLayout, transition: ComponentTransition) {
self.validLayout = layout
guard self.isActive else {