mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[WIP] Video chats v2
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import ComponentFlow
|
||||
import BundleIconComponent
|
||||
import Display
|
||||
import MultilineTextComponent
|
||||
|
||||
public final class BackButtonComponent: Component {
|
||||
public let title: String
|
||||
@@ -30,22 +30,31 @@ public final class BackButtonComponent: Component {
|
||||
}
|
||||
|
||||
public final class View: HighlightTrackingButton {
|
||||
private let arrow = ComponentView<Empty>()
|
||||
private let arrowView: UIImageView
|
||||
private let title = ComponentView<Empty>()
|
||||
|
||||
private var component: BackButtonComponent?
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
self.arrowView = UIImageView()
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
self.addSubview(self.arrowView)
|
||||
|
||||
self.highligthedChanged = { [weak self] highlighted in
|
||||
if let self {
|
||||
let transition: ComponentTransition = highlighted ? .immediate : .easeInOut(duration: 0.2)
|
||||
if highlighted {
|
||||
self.layer.removeAnimation(forKey: "opacity")
|
||||
self.alpha = 0.65
|
||||
transition.setAlpha(view: self.arrowView, alpha: 0.65)
|
||||
if let titleView = self.title.view {
|
||||
transition.setAlpha(view: titleView, alpha: 0.65)
|
||||
}
|
||||
} else {
|
||||
self.alpha = 1.0
|
||||
self.layer.animateAlpha(from: 0.65, to: 1.0, duration: 0.2)
|
||||
transition.setAlpha(view: self.arrowView, alpha: 1.0)
|
||||
if let titleView = self.title.view {
|
||||
transition.setAlpha(view: titleView, alpha: 1.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,22 +73,44 @@ public final class BackButtonComponent: Component {
|
||||
}
|
||||
|
||||
override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
return super.hitTest(point, with: event)
|
||||
if self.isHidden || self.alpha.isZero || self.isUserInteractionEnabled == false {
|
||||
return nil
|
||||
}
|
||||
|
||||
if self.bounds.insetBy(dx: -8.0, dy: -8.0).contains(point) {
|
||||
return self
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func update(component: BackButtonComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
|
||||
let sideInset: CGFloat = 4.0
|
||||
self.component = component
|
||||
|
||||
if self.arrowView.image == nil {
|
||||
self.arrowView.image = NavigationBar.backArrowImage(color: .white)?.withRenderingMode(.alwaysTemplate)
|
||||
}
|
||||
self.arrowView.tintColor = component.color
|
||||
|
||||
let titleSize = self.title.update(
|
||||
transition: .immediate,
|
||||
component: AnyComponent(Text(text: component.title, font: Font.regular(17.0), color: component.color)),
|
||||
component: AnyComponent(MultilineTextComponent(
|
||||
text: .plain(NSAttributedString(string: component.title, font: Font.regular(17.0), textColor: component.color))
|
||||
)),
|
||||
environment: {},
|
||||
containerSize: CGSize(width: availableSize.width - 4.0, height: availableSize.height)
|
||||
)
|
||||
|
||||
let arrowInset: CGFloat = 15.0
|
||||
|
||||
let size = CGSize(width: sideInset * 2.0 + titleSize.width, height: availableSize.height)
|
||||
let size = CGSize(width: arrowInset + titleSize.width, height: titleSize.height)
|
||||
|
||||
if let arrowImage = self.arrowView.image {
|
||||
let arrowFrame = CGRect(origin: CGPoint(x: -4.0, y: floor((size.height - arrowImage.size.height) * 0.5)), size: arrowImage.size)
|
||||
transition.setFrame(view: self.arrowView, frame: arrowFrame)
|
||||
}
|
||||
|
||||
let titleFrame = titleSize.centered(in: CGRect(origin: CGPoint(), size: size))
|
||||
let titleFrame = CGRect(origin: CGPoint(x: arrowInset, y: floor((size.height - titleSize.height) * 0.5)), size: titleSize)
|
||||
if let titleView = self.title.view {
|
||||
if titleView.superview == nil {
|
||||
titleView.layer.anchorPoint = CGPoint()
|
||||
|
||||
Reference in New Issue
Block a user