mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Refactoring
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public extension Transition.Appear {
|
||||
static func `default`(scale: Bool = false, alpha: Bool = false) -> Transition.Appear {
|
||||
return Transition.Appear { component, view, transition in
|
||||
public extension ComponentTransition.Appear {
|
||||
static func `default`(scale: Bool = false, alpha: Bool = false) -> ComponentTransition.Appear {
|
||||
return ComponentTransition.Appear { component, view, transition in
|
||||
if scale {
|
||||
transition.animateScale(view: view, from: 0.01, to: 1.0)
|
||||
}
|
||||
@@ -13,16 +13,16 @@ public extension Transition.Appear {
|
||||
}
|
||||
}
|
||||
|
||||
static func scaleIn() -> Transition.Appear {
|
||||
return Transition.Appear { component, view, transition in
|
||||
static func scaleIn() -> ComponentTransition.Appear {
|
||||
return ComponentTransition.Appear { component, view, transition in
|
||||
transition.animateScale(view: view, from: 0.01, to: 1.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Transition.AppearWithGuide {
|
||||
static func `default`(scale: Bool = false, alpha: Bool = false) -> Transition.AppearWithGuide {
|
||||
return Transition.AppearWithGuide { component, view, guide, transition in
|
||||
public extension ComponentTransition.AppearWithGuide {
|
||||
static func `default`(scale: Bool = false, alpha: Bool = false) -> ComponentTransition.AppearWithGuide {
|
||||
return ComponentTransition.AppearWithGuide { component, view, guide, transition in
|
||||
if scale {
|
||||
transition.animateScale(view: view, from: 0.01, to: 1.0)
|
||||
}
|
||||
@@ -34,9 +34,9 @@ public extension Transition.AppearWithGuide {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Transition.Disappear {
|
||||
static func `default`(scale: Bool = false, alpha: Bool = true) -> Transition.Disappear {
|
||||
return Transition.Disappear { view, transition, completion in
|
||||
public extension ComponentTransition.Disappear {
|
||||
static func `default`(scale: Bool = false, alpha: Bool = true) -> ComponentTransition.Disappear {
|
||||
return ComponentTransition.Disappear { view, transition, completion in
|
||||
if scale {
|
||||
transition.setScale(view: view, scale: 0.01, completion: { _ in
|
||||
if !alpha {
|
||||
@@ -56,9 +56,9 @@ public extension Transition.Disappear {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Transition.DisappearWithGuide {
|
||||
static func `default`(alpha: Bool = true) -> Transition.DisappearWithGuide {
|
||||
return Transition.DisappearWithGuide { stage, view, guide, transition, completion in
|
||||
public extension ComponentTransition.DisappearWithGuide {
|
||||
static func `default`(alpha: Bool = true) -> ComponentTransition.DisappearWithGuide {
|
||||
return ComponentTransition.DisappearWithGuide { stage, view, guide, transition, completion in
|
||||
switch stage {
|
||||
case .begin:
|
||||
if alpha {
|
||||
@@ -78,8 +78,8 @@ public extension Transition.DisappearWithGuide {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Transition.Update {
|
||||
static let `default` = Transition.Update { component, view, transition in
|
||||
public extension ComponentTransition.Update {
|
||||
static let `default` = ComponentTransition.Update { component, view, transition in
|
||||
let frame = component.size.centered(around: component._position ?? CGPoint())
|
||||
if let scale = component._scale {
|
||||
transition.setBounds(view: view, bounds: CGRect(origin: CGPoint(), size: frame.size))
|
||||
|
||||
@@ -6,7 +6,7 @@ private func updateChildAnyComponent<EnvironmentType>(
|
||||
component: AnyComponent<EnvironmentType>,
|
||||
view: UIView,
|
||||
availableSize: CGSize,
|
||||
transition: Transition
|
||||
transition: ComponentTransition
|
||||
) -> _UpdatedChildComponent {
|
||||
let parentContext = _AnyCombinedComponentContext.current
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class _ConcreteChildComponent<ComponentType: Component>: _AnyChildC
|
||||
return .direct(self.directId)
|
||||
}
|
||||
|
||||
public func update(component: ComponentType, @EnvironmentBuilder environment: () -> Environment<ComponentType.EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent {
|
||||
public func update(component: ComponentType, @EnvironmentBuilder environment: () -> Environment<ComponentType.EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent {
|
||||
let parentContext = _AnyCombinedComponentContext.current
|
||||
if !parentContext.updateContext.configuredViews.insert(self.id).inserted {
|
||||
preconditionFailure("Child component can only be configured once")
|
||||
@@ -119,7 +119,7 @@ public final class _ConcreteChildComponent<ComponentType: Component>: _AnyChildC
|
||||
}
|
||||
|
||||
public extension _ConcreteChildComponent where ComponentType.EnvironmentType == Empty {
|
||||
func update(component: ComponentType, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent {
|
||||
func update(component: ComponentType, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent {
|
||||
return self.update(component: component, environment: {}, availableSize: availableSize, transition: transition)
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public final class _ChildComponentGuide {
|
||||
return .direct(self.directId)
|
||||
}
|
||||
|
||||
public func update(position: CGPoint, transition: Transition) -> _UpdatedChildComponentGuide {
|
||||
public func update(position: CGPoint, transition: ComponentTransition) -> _UpdatedChildComponentGuide {
|
||||
let parentContext = _AnyCombinedComponentContext.current
|
||||
|
||||
let previousPosition = parentContext.guides[self.id]
|
||||
@@ -182,11 +182,11 @@ public final class _UpdatedChildComponent {
|
||||
var _clipsToBounds: Bool?
|
||||
var _shadow: Shadow?
|
||||
|
||||
fileprivate var transitionAppear: Transition.Appear?
|
||||
fileprivate var transitionAppearWithGuide: (Transition.AppearWithGuide, _AnyChildComponent.Id)?
|
||||
fileprivate var transitionDisappear: Transition.Disappear?
|
||||
fileprivate var transitionDisappearWithGuide: (Transition.DisappearWithGuide, _AnyChildComponent.Id)?
|
||||
fileprivate var transitionUpdate: Transition.Update?
|
||||
fileprivate var transitionAppear: ComponentTransition.Appear?
|
||||
fileprivate var transitionAppearWithGuide: (ComponentTransition.AppearWithGuide, _AnyChildComponent.Id)?
|
||||
fileprivate var transitionDisappear: ComponentTransition.Disappear?
|
||||
fileprivate var transitionDisappearWithGuide: (ComponentTransition.DisappearWithGuide, _AnyChildComponent.Id)?
|
||||
fileprivate var transitionUpdate: ComponentTransition.Update?
|
||||
fileprivate var gestures: [Gesture] = []
|
||||
|
||||
fileprivate init(
|
||||
@@ -203,31 +203,31 @@ public final class _UpdatedChildComponent {
|
||||
self.size = size
|
||||
}
|
||||
|
||||
@discardableResult public func appear(_ transition: Transition.Appear) -> _UpdatedChildComponent {
|
||||
@discardableResult public func appear(_ transition: ComponentTransition.Appear) -> _UpdatedChildComponent {
|
||||
self.transitionAppear = transition
|
||||
self.transitionAppearWithGuide = nil
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult public func appear(_ transition: Transition.AppearWithGuide, guide: _UpdatedChildComponentGuide) -> _UpdatedChildComponent {
|
||||
@discardableResult public func appear(_ transition: ComponentTransition.AppearWithGuide, guide: _UpdatedChildComponentGuide) -> _UpdatedChildComponent {
|
||||
self.transitionAppear = nil
|
||||
self.transitionAppearWithGuide = (transition, guide.instance.id)
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult public func disappear(_ transition: Transition.Disappear) -> _UpdatedChildComponent {
|
||||
@discardableResult public func disappear(_ transition: ComponentTransition.Disappear) -> _UpdatedChildComponent {
|
||||
self.transitionDisappear = transition
|
||||
self.transitionDisappearWithGuide = nil
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult public func disappear(_ transition: Transition.DisappearWithGuide, guide: _UpdatedChildComponentGuide) -> _UpdatedChildComponent {
|
||||
@discardableResult public func disappear(_ transition: ComponentTransition.DisappearWithGuide, guide: _UpdatedChildComponentGuide) -> _UpdatedChildComponent {
|
||||
self.transitionDisappear = nil
|
||||
self.transitionDisappearWithGuide = (transition, guide.instance.id)
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult public func update(_ transition: Transition.Update) -> _UpdatedChildComponent {
|
||||
@discardableResult public func update(_ transition: ComponentTransition.Update) -> _UpdatedChildComponent {
|
||||
self.transitionUpdate = transition
|
||||
return self
|
||||
}
|
||||
@@ -278,7 +278,7 @@ public final class _EnvironmentChildComponent<EnvironmentType>: _AnyChildCompone
|
||||
return .direct(self.directId)
|
||||
}
|
||||
|
||||
func update(component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent {
|
||||
func update(component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent {
|
||||
let parentContext = _AnyCombinedComponentContext.current
|
||||
if !parentContext.updateContext.configuredViews.insert(self.id).inserted {
|
||||
preconditionFailure("Child component can only be configured once")
|
||||
@@ -312,17 +312,17 @@ public final class _EnvironmentChildComponent<EnvironmentType>: _AnyChildCompone
|
||||
}
|
||||
|
||||
public extension _EnvironmentChildComponent where EnvironmentType == Empty {
|
||||
func update(component: AnyComponent<EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent {
|
||||
func update(component: AnyComponent<EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent {
|
||||
return self.update(component: component, environment: {}, availableSize: availableSize, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
public extension _EnvironmentChildComponent {
|
||||
func update<ComponentType: Component>(_ component: ComponentType, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent where ComponentType.EnvironmentType == EnvironmentType {
|
||||
func update<ComponentType: Component>(_ component: ComponentType, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent where ComponentType.EnvironmentType == EnvironmentType {
|
||||
return self.update(component: AnyComponent(component), environment: environment, availableSize: availableSize, transition: transition)
|
||||
}
|
||||
|
||||
func update<ComponentType: Component>(_ component: ComponentType, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent where ComponentType.EnvironmentType == EnvironmentType, EnvironmentType == Empty {
|
||||
func update<ComponentType: Component>(_ component: ComponentType, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent where ComponentType.EnvironmentType == EnvironmentType, EnvironmentType == Empty {
|
||||
return self.update(component: AnyComponent(component), environment: {}, availableSize: availableSize, transition: transition)
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public final class _EnvironmentChildComponentFromMap<EnvironmentType>: _AnyChild
|
||||
self.id = id
|
||||
}
|
||||
|
||||
public func update(component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent {
|
||||
public func update(component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent {
|
||||
let parentContext = _AnyCombinedComponentContext.current
|
||||
if !parentContext.updateContext.configuredViews.insert(self.id).inserted {
|
||||
preconditionFailure("Child component can only be configured once")
|
||||
@@ -368,7 +368,7 @@ public final class _EnvironmentChildComponentFromMap<EnvironmentType>: _AnyChild
|
||||
}
|
||||
|
||||
public extension _EnvironmentChildComponentFromMap where EnvironmentType == Empty {
|
||||
func update(component: AnyComponent<EnvironmentType>, availableSize: CGSize, transition: Transition) -> _UpdatedChildComponent {
|
||||
func update(component: AnyComponent<EnvironmentType>, availableSize: CGSize, transition: ComponentTransition) -> _UpdatedChildComponent {
|
||||
return self.update(component: component, environment: {}, availableSize: availableSize, transition: transition)
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ public final class CombinedComponentContext<ComponentType: Component> {
|
||||
|
||||
public let component: ComponentType
|
||||
public let availableSize: CGSize
|
||||
public let transition: Transition
|
||||
public let transition: ComponentTransition
|
||||
private let addImpl: (_ updatedComponent: _UpdatedChildComponent) -> Void
|
||||
|
||||
public var environment: Environment<ComponentType.EnvironmentType> {
|
||||
@@ -408,7 +408,7 @@ public final class CombinedComponentContext<ComponentType: Component> {
|
||||
view: UIView,
|
||||
component: ComponentType,
|
||||
availableSize: CGSize,
|
||||
transition: Transition,
|
||||
transition: ComponentTransition,
|
||||
add: @escaping (_ updatedComponent: _UpdatedChildComponent) -> Void
|
||||
) {
|
||||
self.context = context
|
||||
@@ -467,8 +467,8 @@ private class _AnyCombinedComponentContext {
|
||||
class ChildView {
|
||||
let view: UIView
|
||||
var index: Int
|
||||
var transition: Transition.Disappear?
|
||||
var transitionWithGuide: (Transition.DisappearWithGuide, _AnyChildComponent.Id)?
|
||||
var transition: ComponentTransition.Disappear?
|
||||
var transitionWithGuide: (ComponentTransition.DisappearWithGuide, _AnyChildComponent.Id)?
|
||||
|
||||
var gestures: [UInt: UIGestureRecognizer] = [:]
|
||||
|
||||
@@ -507,15 +507,15 @@ private class _AnyCombinedComponentContext {
|
||||
class DisappearingChildView {
|
||||
let view: UIView
|
||||
let guideId: _AnyChildComponent.Id?
|
||||
let transition: Transition.Disappear?
|
||||
let transitionWithGuide: Transition.DisappearWithGuide?
|
||||
let transition: ComponentTransition.Disappear?
|
||||
let transitionWithGuide: ComponentTransition.DisappearWithGuide?
|
||||
let completion: () -> Void
|
||||
|
||||
init(
|
||||
view: UIView,
|
||||
guideId: _AnyChildComponent.Id?,
|
||||
transition: Transition.Disappear?,
|
||||
transitionWithGuide: Transition.DisappearWithGuide?,
|
||||
transition: ComponentTransition.Disappear?,
|
||||
transitionWithGuide: ComponentTransition.DisappearWithGuide?,
|
||||
completion: @escaping () -> Void
|
||||
) {
|
||||
self.view = view
|
||||
@@ -555,39 +555,39 @@ private extension UIView {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Transition {
|
||||
public extension ComponentTransition {
|
||||
final class Appear {
|
||||
private let f: (_UpdatedChildComponent, UIView, Transition) -> Void
|
||||
private let f: (_UpdatedChildComponent, UIView, ComponentTransition) -> Void
|
||||
|
||||
public init(_ f: @escaping (_UpdatedChildComponent, UIView, Transition) -> Void) {
|
||||
public init(_ f: @escaping (_UpdatedChildComponent, UIView, ComponentTransition) -> Void) {
|
||||
self.f = f
|
||||
}
|
||||
|
||||
public func callAsFunction(component: _UpdatedChildComponent, view: UIView, transition: Transition) {
|
||||
public func callAsFunction(component: _UpdatedChildComponent, view: UIView, transition: ComponentTransition) {
|
||||
self.f(component, view, transition)
|
||||
}
|
||||
}
|
||||
|
||||
final class AppearWithGuide {
|
||||
private let f: (_UpdatedChildComponent, UIView, CGPoint, Transition) -> Void
|
||||
private let f: (_UpdatedChildComponent, UIView, CGPoint, ComponentTransition) -> Void
|
||||
|
||||
public init(_ f: @escaping (_UpdatedChildComponent, UIView, CGPoint, Transition) -> Void) {
|
||||
public init(_ f: @escaping (_UpdatedChildComponent, UIView, CGPoint, ComponentTransition) -> Void) {
|
||||
self.f = f
|
||||
}
|
||||
|
||||
public func callAsFunction(component: _UpdatedChildComponent, view: UIView, guide: CGPoint, transition: Transition) {
|
||||
public func callAsFunction(component: _UpdatedChildComponent, view: UIView, guide: CGPoint, transition: ComponentTransition) {
|
||||
self.f(component, view, guide, transition)
|
||||
}
|
||||
}
|
||||
|
||||
final class Disappear {
|
||||
private let f: (UIView, Transition, @escaping () -> Void) -> Void
|
||||
private let f: (UIView, ComponentTransition, @escaping () -> Void) -> Void
|
||||
|
||||
public init(_ f: @escaping (UIView, Transition, @escaping () -> Void) -> Void) {
|
||||
public init(_ f: @escaping (UIView, ComponentTransition, @escaping () -> Void) -> Void) {
|
||||
self.f = f
|
||||
}
|
||||
|
||||
public func callAsFunction(view: UIView, transition: Transition, completion: @escaping () -> Void) {
|
||||
public func callAsFunction(view: UIView, transition: ComponentTransition, completion: @escaping () -> Void) {
|
||||
self.f(view, transition, completion)
|
||||
}
|
||||
}
|
||||
@@ -598,26 +598,26 @@ public extension Transition {
|
||||
case update
|
||||
}
|
||||
|
||||
private let f: (Stage, UIView, CGPoint, Transition, @escaping () -> Void) -> Void
|
||||
private let f: (Stage, UIView, CGPoint, ComponentTransition, @escaping () -> Void) -> Void
|
||||
|
||||
public init(_ f: @escaping (Stage, UIView, CGPoint, Transition, @escaping () -> Void) -> Void
|
||||
public init(_ f: @escaping (Stage, UIView, CGPoint, ComponentTransition, @escaping () -> Void) -> Void
|
||||
) {
|
||||
self.f = f
|
||||
}
|
||||
|
||||
public func callAsFunction(stage: Stage, view: UIView, guide: CGPoint, transition: Transition, completion: @escaping () -> Void) {
|
||||
public func callAsFunction(stage: Stage, view: UIView, guide: CGPoint, transition: ComponentTransition, completion: @escaping () -> Void) {
|
||||
self.f(stage, view, guide, transition, completion)
|
||||
}
|
||||
}
|
||||
|
||||
final class Update {
|
||||
private let f: (_UpdatedChildComponent, UIView, Transition) -> Void
|
||||
private let f: (_UpdatedChildComponent, UIView, ComponentTransition) -> Void
|
||||
|
||||
public init(_ f: @escaping (_UpdatedChildComponent, UIView, Transition) -> Void) {
|
||||
public init(_ f: @escaping (_UpdatedChildComponent, UIView, ComponentTransition) -> Void) {
|
||||
self.f = f
|
||||
}
|
||||
|
||||
public func callAsFunction(component: _UpdatedChildComponent, view: UIView, transition: Transition) {
|
||||
public func callAsFunction(component: _UpdatedChildComponent, view: UIView, transition: ComponentTransition) {
|
||||
self.f(component, view, transition)
|
||||
}
|
||||
}
|
||||
@@ -628,7 +628,7 @@ public extension CombinedComponent {
|
||||
return UIView()
|
||||
}
|
||||
|
||||
func update(view: View, availableSize: CGSize, state: State, environment: Environment<EnvironmentType>, transition: Transition) -> CGSize {
|
||||
func update(view: View, availableSize: CGSize, state: State, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize {
|
||||
let context = view.getCombinedComponentContext(Self.self)
|
||||
|
||||
let storedBody: Body
|
||||
@@ -683,7 +683,7 @@ public extension CombinedComponent {
|
||||
previousView.transition = updatedChild.transitionDisappear
|
||||
previousView.transitionWithGuide = updatedChild.transitionDisappearWithGuide
|
||||
|
||||
(updatedChild.transitionUpdate ?? Transition.Update.default)(component: updatedChild, view: updatedChild.view, transition: transition)
|
||||
(updatedChild.transitionUpdate ?? ComponentTransition.Update.default)(component: updatedChild, view: updatedChild.view, transition: transition)
|
||||
} else {
|
||||
for i in index ..< context.childViewIndices.count {
|
||||
if let moveView = context.childViews[context.childViewIndices[i]] {
|
||||
|
||||
@@ -89,13 +89,13 @@ extension UIView {
|
||||
}
|
||||
|
||||
open class ComponentState {
|
||||
open var _updated: ((Transition, Bool) -> Void)?
|
||||
open var _updated: ((ComponentTransition, Bool) -> Void)?
|
||||
var isUpdated: Bool = false
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
public final func updated(transition: Transition = .immediate, isLocal: Bool = false) {
|
||||
public final func updated(transition: ComponentTransition = .immediate, isLocal: Bool = false) {
|
||||
self.isUpdated = true
|
||||
self._updated?(transition, isLocal)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public final class EmptyComponentState: ComponentState {
|
||||
public protocol _TypeErasedComponent {
|
||||
func _makeView() -> UIView
|
||||
func _makeContext() -> _TypeErasedComponentContext
|
||||
func _update(view: UIView, availableSize: CGSize, environment: Any, transition: Transition) -> CGSize
|
||||
func _update(view: UIView, availableSize: CGSize, environment: Any, transition: ComponentTransition) -> CGSize
|
||||
func _isEqual(to other: _TypeErasedComponent) -> Bool
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public protocol Component: _TypeErasedComponent, Equatable {
|
||||
|
||||
func makeView() -> View
|
||||
func makeState() -> State
|
||||
func update(view: View, availableSize: CGSize, state: State, environment: Environment<EnvironmentType>, transition: Transition) -> CGSize
|
||||
func update(view: View, availableSize: CGSize, state: State, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize
|
||||
}
|
||||
|
||||
public extension Component {
|
||||
@@ -139,7 +139,7 @@ public extension Component {
|
||||
return ComponentContext<Self>(component: self, environment: Environment<EnvironmentType>(), state: self.makeState())
|
||||
}
|
||||
|
||||
func _update(view: UIView, availableSize: CGSize, environment: Any, transition: Transition) -> CGSize {
|
||||
func _update(view: UIView, availableSize: CGSize, environment: Any, transition: ComponentTransition) -> CGSize {
|
||||
let view = view as! Self.View
|
||||
|
||||
return self.update(view: view, availableSize: availableSize, state: view.context(component: self).state, environment: environment as! Environment<EnvironmentType>, transition: transition)
|
||||
@@ -191,7 +191,7 @@ public class AnyComponent<EnvironmentType>: _TypeErasedComponent, Equatable {
|
||||
return self.wrapped._makeContext()
|
||||
}
|
||||
|
||||
public func _update(view: UIView, availableSize: CGSize, environment: Any, transition: Transition) -> CGSize {
|
||||
public func _update(view: UIView, availableSize: CGSize, environment: Any, transition: ComponentTransition) -> CGSize {
|
||||
return self.wrapped._update(view: view, availableSize: availableSize, environment: environment as! Environment<EnvironmentType>, transition: transition)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public extension UIView {
|
||||
}
|
||||
|
||||
private extension CALayer {
|
||||
func animate(from: AnyObject, to: AnyObject, keyPath: String, duration: Double, delay: Double, curve: Transition.Animation.Curve, removeOnCompletion: Bool, additive: Bool, completion: ((Bool) -> Void)? = nil) {
|
||||
func animate(from: AnyObject, to: AnyObject, keyPath: String, duration: Double, delay: Double, curve: ComponentTransition.Animation.Curve, removeOnCompletion: Bool, additive: Bool, completion: ((Bool) -> Void)? = nil) {
|
||||
let timingFunction: String
|
||||
let mediaTimingFunction: CAMediaTimingFunction?
|
||||
switch curve {
|
||||
@@ -44,7 +44,7 @@ private extension CALayer {
|
||||
}
|
||||
}
|
||||
|
||||
private extension Transition.Animation.Curve {
|
||||
private extension ComponentTransition.Animation.Curve {
|
||||
func asTimingFunction() -> CAMediaTimingFunction {
|
||||
switch self {
|
||||
case .easeInOut:
|
||||
@@ -59,7 +59,7 @@ private extension Transition.Animation.Curve {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Transition.Animation {
|
||||
public extension ComponentTransition.Animation {
|
||||
var isImmediate: Bool {
|
||||
if case .none = self {
|
||||
return true
|
||||
@@ -69,7 +69,7 @@ public extension Transition.Animation {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Transition {
|
||||
public struct ComponentTransition {
|
||||
public enum Animation {
|
||||
public enum Curve {
|
||||
case easeInOut
|
||||
@@ -111,19 +111,19 @@ public struct Transition {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func withUserData(_ userData: Any) -> Transition {
|
||||
public func withUserData(_ userData: Any) -> ComponentTransition {
|
||||
var result = self
|
||||
result._userData.append(userData)
|
||||
return result
|
||||
}
|
||||
|
||||
public func withAnimation(_ animation: Animation) -> Transition {
|
||||
public func withAnimation(_ animation: Animation) -> ComponentTransition {
|
||||
var result = self
|
||||
result.animation = animation
|
||||
return result
|
||||
}
|
||||
|
||||
public func withAnimationIfAnimated(_ animation: Animation) -> Transition {
|
||||
public func withAnimationIfAnimated(_ animation: Animation) -> ComponentTransition {
|
||||
switch self.animation {
|
||||
case .none:
|
||||
return self
|
||||
@@ -134,14 +134,14 @@ public struct Transition {
|
||||
}
|
||||
}
|
||||
|
||||
public static var immediate: Transition = Transition(animation: .none)
|
||||
public static var immediate: ComponentTransition = ComponentTransition(animation: .none)
|
||||
|
||||
public static func easeInOut(duration: Double) -> Transition {
|
||||
return Transition(animation: .curve(duration: duration, curve: .easeInOut))
|
||||
public static func easeInOut(duration: Double) -> ComponentTransition {
|
||||
return ComponentTransition(animation: .curve(duration: duration, curve: .easeInOut))
|
||||
}
|
||||
|
||||
public static func spring(duration: Double) -> Transition {
|
||||
return Transition(animation: .curve(duration: duration, curve: .spring))
|
||||
public static func spring(duration: Double) -> ComponentTransition {
|
||||
return ComponentTransition(animation: .curve(duration: duration, curve: .spring))
|
||||
}
|
||||
|
||||
public init(animation: Animation) {
|
||||
@@ -1184,7 +1184,7 @@ public struct Transition {
|
||||
}
|
||||
}
|
||||
|
||||
public func animateContentsImage(layer: CALayer, from fromImage: CGImage, to toImage: CGImage, duration: Double, curve: Transition.Animation.Curve, completion: ((Bool) -> Void)? = nil) {
|
||||
public func animateContentsImage(layer: CALayer, from fromImage: CGImage, to toImage: CGImage, duration: Double, curve: ComponentTransition.Animation.Curve, completion: ((Bool) -> Void)? = nil) {
|
||||
layer.animate(
|
||||
from: fromImage,
|
||||
to: toImage,
|
||||
|
||||
@@ -154,7 +154,7 @@ public final class Button: Component {
|
||||
}
|
||||
}
|
||||
|
||||
private func updateAlpha(transition: Transition) {
|
||||
private func updateAlpha(transition: ComponentTransition) {
|
||||
guard let component = self.component else {
|
||||
return
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public final class Button: Component {
|
||||
super.cancelTracking(with: event)
|
||||
}
|
||||
|
||||
func update(component: Button, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
||||
func update(component: Button, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
|
||||
let contentSize = self.contentView.update(
|
||||
transition: transition,
|
||||
component: component.content,
|
||||
@@ -301,7 +301,7 @@ public final class Button: Component {
|
||||
return View(frame: CGRect())
|
||||
}
|
||||
|
||||
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 {
|
||||
view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class Circle: Component {
|
||||
var component: Circle?
|
||||
var currentSize: CGSize?
|
||||
|
||||
func update(component: Circle, availableSize: CGSize, transition: Transition) -> CGSize {
|
||||
func update(component: Circle, availableSize: CGSize, transition: ComponentTransition) -> CGSize {
|
||||
let size = CGSize(width: min(availableSize.width, component.size.width), height: min(availableSize.height, component.size.height))
|
||||
|
||||
if self.currentSize != size || self.component != component {
|
||||
@@ -63,7 +63,7 @@ public final class Circle: Component {
|
||||
return View()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class Image: Component {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
func update(component: Image, availableSize: CGSize, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
||||
func update(component: Image, availableSize: CGSize, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
|
||||
self.image = component.image
|
||||
self.contentMode = component.contentMode
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class Image: Component {
|
||||
return View()
|
||||
}
|
||||
|
||||
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, environment: environment, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ public final class List<ChildEnvironment: Equatable>: CombinedComponent {
|
||||
private let items: [AnyComponentWithIdentity<ChildEnvironment>]
|
||||
private let direction: Direction
|
||||
private let centerAlignment: Bool
|
||||
private let appear: Transition.Appear
|
||||
private let appear: ComponentTransition.Appear
|
||||
|
||||
public init(_ items: [AnyComponentWithIdentity<ChildEnvironment>], direction: Direction = .vertical, centerAlignment: Bool = false, appear: Transition.Appear = .default()) {
|
||||
public init(_ items: [AnyComponentWithIdentity<ChildEnvironment>], direction: Direction = .vertical, centerAlignment: Bool = false, appear: ComponentTransition.Appear = .default()) {
|
||||
self.items = items
|
||||
self.direction = direction
|
||||
self.centerAlignment = centerAlignment
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class Rectangle: Component {
|
||||
return View(frame: CGRect())
|
||||
}
|
||||
|
||||
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 {
|
||||
var size = availableSize
|
||||
if let width = self.width {
|
||||
size.width = min(size.width, width)
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class RoundedRectangle: Component {
|
||||
public final class View: UIImageView {
|
||||
var component: RoundedRectangle?
|
||||
|
||||
func update(component: RoundedRectangle, availableSize: CGSize, transition: Transition) -> CGSize {
|
||||
func update(component: RoundedRectangle, availableSize: CGSize, transition: ComponentTransition) -> CGSize {
|
||||
if self.component != component {
|
||||
let cornerRadius = component.cornerRadius ?? min(availableSize.width, availableSize.height) * 0.5
|
||||
|
||||
@@ -113,7 +113,7 @@ public final class RoundedRectangle: Component {
|
||||
return View()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public final class Text: Component {
|
||||
return View()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ public final class ComponentHostView<EnvironmentType>: UIView {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public func update(transition: Transition, component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, forceUpdate: Bool = false, containerSize: CGSize) -> CGSize {
|
||||
public func update(transition: ComponentTransition, component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, forceUpdate: Bool = false, containerSize: CGSize) -> CGSize {
|
||||
let size = self._update(transition: transition, component: component, maybeEnvironment: environment, updateEnvironment: true, forceUpdate: forceUpdate, containerSize: containerSize)
|
||||
self.currentSize = size
|
||||
return size
|
||||
}
|
||||
|
||||
private func _update(transition: Transition, component: AnyComponent<EnvironmentType>, maybeEnvironment: () -> Environment<EnvironmentType>, updateEnvironment: Bool, forceUpdate: Bool, containerSize: CGSize) -> CGSize {
|
||||
private func _update(transition: ComponentTransition, component: AnyComponent<EnvironmentType>, maybeEnvironment: () -> Environment<EnvironmentType>, updateEnvironment: Bool, forceUpdate: Bool, containerSize: CGSize) -> CGSize {
|
||||
precondition(!self.isUpdating)
|
||||
self.isUpdating = true
|
||||
|
||||
@@ -150,13 +150,13 @@ public final class ComponentView<EnvironmentType> {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public func update(transition: Transition, component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, forceUpdate: Bool = false, containerSize: CGSize) -> CGSize {
|
||||
public func update(transition: ComponentTransition, component: AnyComponent<EnvironmentType>, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>, forceUpdate: Bool = false, containerSize: CGSize) -> CGSize {
|
||||
let size = self._update(transition: transition, component: component, maybeEnvironment: environment, updateEnvironment: true, forceUpdate: forceUpdate, containerSize: containerSize)
|
||||
self.currentSize = size
|
||||
return size
|
||||
}
|
||||
|
||||
public func updateEnvironment(transition: Transition, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>) -> CGSize? {
|
||||
public func updateEnvironment(transition: ComponentTransition, @EnvironmentBuilder environment: () -> Environment<EnvironmentType>) -> CGSize? {
|
||||
guard let currentComponent = self.currentComponent, let currentContainerSize = self.currentContainerSize else {
|
||||
return nil
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public final class ComponentView<EnvironmentType> {
|
||||
return size
|
||||
}
|
||||
|
||||
private func _update(transition: Transition, component: AnyComponent<EnvironmentType>, maybeEnvironment: () -> Environment<EnvironmentType>, updateEnvironment: Bool, forceUpdate: Bool, containerSize: CGSize) -> CGSize {
|
||||
private func _update(transition: ComponentTransition, component: AnyComponent<EnvironmentType>, maybeEnvironment: () -> Environment<EnvironmentType>, updateEnvironment: Bool, forceUpdate: Bool, containerSize: CGSize) -> CGSize {
|
||||
precondition(!self.isUpdating)
|
||||
self.isUpdating = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user