Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
@@ -0,0 +1,23 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "SwitchComponent",
module_name = "SwitchComponent",
srcs = glob([
"Sources/**/*.swift",
]),
copts = [
"-warnings-as-errors",
],
deps = [
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/AsyncDisplayKit:AsyncDisplayKit",
"//submodules/Display:Display",
"//submodules/ContextUI:ContextUI",
"//submodules/TelegramPresentationData:TelegramPresentationData",
"//submodules/ComponentFlow:ComponentFlow",
],
visibility = [
"//visibility:public",
],
)
@@ -0,0 +1,78 @@
import Foundation
import UIKit
import Display
import AsyncDisplayKit
import ComponentFlow
import TelegramPresentationData
public final class SwitchComponent: Component {
public typealias EnvironmentType = Empty
let tintColor: UIColor?
let value: Bool
let valueUpdated: (Bool) -> Void
public init(
tintColor: UIColor? = nil,
value: Bool,
valueUpdated: @escaping (Bool) -> Void
) {
self.tintColor = tintColor
self.value = value
self.valueUpdated = valueUpdated
}
public static func ==(lhs: SwitchComponent, rhs: SwitchComponent) -> Bool {
if lhs.tintColor != rhs.tintColor {
return false
}
if lhs.value != rhs.value {
return false
}
return true
}
public final class View: UIView {
private let switchView: UISwitch
private var component: SwitchComponent?
override init(frame: CGRect) {
self.switchView = UISwitch()
super.init(frame: frame)
self.addSubview(self.switchView)
self.switchView.addTarget(self, action: #selector(self.valueChanged(_:)), for: .valueChanged)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func valueChanged(_ sender: Any) {
self.component?.valueUpdated(self.switchView.isOn)
}
func update(component: SwitchComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize {
self.component = component
self.switchView.tintColor = component.tintColor
self.switchView.setOn(component.value, animated: !transition.animation.isImmediate)
self.switchView.sizeToFit()
self.switchView.frame = CGRect(origin: .zero, size: self.switchView.frame.size)
return self.switchView.frame.size
}
}
public func makeView() -> View {
return View(frame: CGRect())
}
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize {
return view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
}
}