mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Voice Chat UI improvements
This commit is contained in:
@@ -391,12 +391,17 @@ open class NavigationController: UINavigationController, ContainableController,
|
||||
}
|
||||
|
||||
if let inCallStatusBar = self.inCallStatusBar {
|
||||
let inCallStatusBarFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(layout.statusBarHeight ?? 0.0, max(40.0, layout.safeInsets.top))))
|
||||
var inCallStatusBarFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(layout.statusBarHeight ?? 0.0, max(40.0, layout.safeInsets.top))))
|
||||
if layout.deviceMetrics.hasTopNotch {
|
||||
inCallStatusBarFrame.size.height += 12.0
|
||||
}
|
||||
if inCallStatusBar.frame.isEmpty {
|
||||
inCallStatusBar.frame = inCallStatusBarFrame
|
||||
} else {
|
||||
transition.updateFrame(node: inCallStatusBar, frame: inCallStatusBarFrame)
|
||||
}
|
||||
inCallStatusBar.callStatusBarNode?.update(size: inCallStatusBarFrame.size)
|
||||
inCallStatusBar.callStatusBarNode?.frame = inCallStatusBarFrame
|
||||
layout.statusBarHeight = inCallStatusBarFrame.height
|
||||
self.inCallStatusBar?.frame = inCallStatusBarFrame
|
||||
}
|
||||
@@ -1339,13 +1344,14 @@ open class NavigationController: UINavigationController, ContainableController,
|
||||
}
|
||||
}
|
||||
|
||||
public func setForceInCallStatusBar(_ forceInCallStatusBarText: String?, transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut)) {
|
||||
if let forceInCallStatusBarText = forceInCallStatusBarText {
|
||||
public func setForceInCallStatusBar(_ forceInCallStatusBar: CallStatusBarNode?, transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut)) {
|
||||
if let forceInCallStatusBar = forceInCallStatusBar {
|
||||
let inCallStatusBar: StatusBar
|
||||
if let current = self.inCallStatusBar {
|
||||
inCallStatusBar = current
|
||||
} else {
|
||||
inCallStatusBar = StatusBar()
|
||||
inCallStatusBar.clipsToBounds = false
|
||||
inCallStatusBar.inCallNavigate = { [weak self] in
|
||||
self?.scrollToTop(.master)
|
||||
}
|
||||
@@ -1371,7 +1377,7 @@ open class NavigationController: UINavigationController, ContainableController,
|
||||
}
|
||||
if let layout = self.validLayout {
|
||||
self.containerLayoutUpdated(layout, transition: transition)
|
||||
inCallStatusBar.updateState(statusBar: nil, withSafeInsets: !layout.safeInsets.top.isZero, inCallText: forceInCallStatusBarText, animated: false)
|
||||
inCallStatusBar.updateState(statusBar: nil, withSafeInsets: !layout.safeInsets.top.isZero, inCallNode: forceInCallStatusBar, animated: false)
|
||||
}
|
||||
} else if let inCallStatusBar = self.inCallStatusBar {
|
||||
self.inCallStatusBar = nil
|
||||
|
||||
@@ -269,7 +269,7 @@ open class NavigationBar: ASDisplayNode {
|
||||
private var title: String? {
|
||||
didSet {
|
||||
if let title = self.title {
|
||||
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.bold(17.0), textColor: self.presentationData.theme.primaryTextColor)
|
||||
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.semibold(17.0), textColor: self.presentationData.theme.primaryTextColor)
|
||||
self.titleNode.accessibilityLabel = title
|
||||
if self.titleNode.supernode == nil {
|
||||
self.buttonsContainerNode.addSubnode(self.titleNode)
|
||||
|
||||
@@ -25,7 +25,11 @@ public class StatusBarSurface {
|
||||
}
|
||||
}
|
||||
|
||||
private let inCallBackgroundColor = UIColor(rgb: 0x43d551)
|
||||
open class CallStatusBarNode: ASDisplayNode {
|
||||
open func update(size: CGSize) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private func addInCallAnimation(_ layer: CALayer) {
|
||||
let animation = CAKeyframeAnimation(keyPath: "opacity")
|
||||
@@ -92,10 +96,7 @@ public final class StatusBar: ASDisplayNode {
|
||||
private var removeProxyNodeScheduled = false
|
||||
|
||||
let offsetNode = ASDisplayNode()
|
||||
private let inCallBackgroundNode = ASDisplayNode()
|
||||
private let inCallLabel: StatusBarLabelNode
|
||||
|
||||
private var inCallText: String? = nil
|
||||
var callStatusBarNode: CallStatusBarNode? = nil
|
||||
|
||||
public var verticalOffset: CGFloat = 0.0 {
|
||||
didSet {
|
||||
@@ -113,14 +114,8 @@ public final class StatusBar: ASDisplayNode {
|
||||
}
|
||||
|
||||
public override init() {
|
||||
self.inCallLabel = StatusBarLabelNode()
|
||||
self.inCallLabel.isUserInteractionEnabled = false
|
||||
|
||||
self.offsetNode.isUserInteractionEnabled = false
|
||||
|
||||
let labelSize = self.inCallLabel.updateLayout(CGSize(width: 300.0, height: 300.0))
|
||||
self.inCallLabel.frame = CGRect(origin: CGPoint(x: 10.0, y: 20.0 + 4.0), size: labelSize)
|
||||
|
||||
super.init()
|
||||
|
||||
self.setViewBlock({
|
||||
@@ -130,18 +125,17 @@ public final class StatusBar: ASDisplayNode {
|
||||
(self.view as! StatusBarView).node = self
|
||||
|
||||
self.addSubnode(self.offsetNode)
|
||||
self.addSubnode(self.inCallBackgroundNode)
|
||||
|
||||
self.clipsToBounds = true
|
||||
|
||||
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:))))
|
||||
}
|
||||
|
||||
func updateState(statusBar: UIView?, withSafeInsets: Bool, inCallText: String?, animated: Bool) {
|
||||
func updateState(statusBar: UIView?, withSafeInsets: Bool, inCallNode: CallStatusBarNode?, animated: Bool) {
|
||||
if let statusBar = statusBar {
|
||||
self.removeProxyNodeScheduled = false
|
||||
let resolvedStyle: StatusBarStyle
|
||||
if inCallText != nil && !self.ignoreInCall {
|
||||
if inCallNode != nil && !self.ignoreInCall {
|
||||
resolvedStyle = .White
|
||||
} else {
|
||||
resolvedStyle = self.statusBarStyle
|
||||
@@ -176,46 +170,35 @@ public final class StatusBar: ASDisplayNode {
|
||||
ignoreInCall = true
|
||||
}
|
||||
|
||||
var resolvedInCallText: String? = inCallText
|
||||
var resolvedCallStatusBarNode: CallStatusBarNode? = inCallNode
|
||||
if ignoreInCall {
|
||||
resolvedInCallText = nil
|
||||
resolvedCallStatusBarNode = nil
|
||||
}
|
||||
|
||||
if (resolvedInCallText != nil) != (self.inCallText != nil) {
|
||||
if let _ = resolvedInCallText {
|
||||
if !withSafeInsets {
|
||||
self.addSubnode(self.inCallLabel)
|
||||
}
|
||||
addInCallAnimation(self.inCallLabel.layer)
|
||||
|
||||
self.inCallBackgroundNode.layer.backgroundColor = inCallBackgroundColor.cgColor
|
||||
if (resolvedCallStatusBarNode != nil) != (self.callStatusBarNode != nil) {
|
||||
if let resolvedCallStatusBarNode = resolvedCallStatusBarNode {
|
||||
self.addSubnode(resolvedCallStatusBarNode)
|
||||
if animated {
|
||||
self.inCallBackgroundNode.layer.animate(from: UIColor.clear.cgColor, to: inCallBackgroundColor.cgColor, keyPath: "backgroundColor", timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, duration: 0.3)
|
||||
resolvedCallStatusBarNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3)
|
||||
}
|
||||
} else {
|
||||
self.inCallLabel.removeFromSupernode()
|
||||
} else if let callStatusBarNode = self.callStatusBarNode {
|
||||
self.callStatusBarNode = nil
|
||||
|
||||
self.inCallBackgroundNode.layer.backgroundColor = UIColor.clear.cgColor
|
||||
if animated {
|
||||
self.inCallBackgroundNode.layer.animate(from: inCallBackgroundColor.cgColor, to: UIColor.clear.cgColor, keyPath: "backgroundColor", timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, duration: 0.3)
|
||||
callStatusBarNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, completion: { [weak callStatusBarNode] _ in
|
||||
callStatusBarNode?.removeFromSupernode()
|
||||
})
|
||||
} else {
|
||||
callStatusBarNode.removeFromSupernode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let resolvedInCallText = resolvedInCallText {
|
||||
if self.inCallText != resolvedInCallText {
|
||||
self.inCallLabel.attributedText = NSAttributedString(string: resolvedInCallText, font: Font.regular(14.0), textColor: .white)
|
||||
}
|
||||
|
||||
self.layoutInCallLabel()
|
||||
}
|
||||
|
||||
self.inCallText = resolvedInCallText
|
||||
self.callStatusBarNode = resolvedCallStatusBarNode
|
||||
}
|
||||
|
||||
override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
if self.bounds.contains(point) && self.inCallText != nil {
|
||||
if self.bounds.contains(point) && self.callStatusBarNode != nil {
|
||||
return self.view
|
||||
} else {
|
||||
return nil
|
||||
@@ -223,42 +206,8 @@ public final class StatusBar: ASDisplayNode {
|
||||
}
|
||||
|
||||
@objc func tapGesture(_ recognizer: UITapGestureRecognizer) {
|
||||
if case .ended = recognizer.state, self.inCallText != nil {
|
||||
if case .ended = recognizer.state, self.callStatusBarNode != nil {
|
||||
self.inCallNavigate?()
|
||||
}
|
||||
}
|
||||
|
||||
override public func layout() {
|
||||
super.layout()
|
||||
|
||||
self.layoutInCallLabel()
|
||||
}
|
||||
|
||||
override public var frame: CGRect {
|
||||
didSet {
|
||||
if oldValue.size != self.frame.size {
|
||||
let bounds = self.bounds
|
||||
self.inCallBackgroundNode.frame = CGRect(origin: CGPoint(), size: bounds.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public var bounds: CGRect {
|
||||
didSet {
|
||||
if oldValue.size != self.bounds.size {
|
||||
let bounds = self.bounds
|
||||
self.inCallBackgroundNode.frame = CGRect(origin: CGPoint(), size: bounds.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func layoutInCallLabel() {
|
||||
if self.inCallLabel.supernode != nil {
|
||||
let size = self.bounds.size
|
||||
if !size.width.isZero && !size.height.isZero {
|
||||
let labelSize = self.inCallLabel.updateLayout(size)
|
||||
self.inCallLabel.frame = CGRect(origin: CGPoint(x: floor((size.width - labelSize.width) / 2.0), y: 20.0 + floor((20.0 - labelSize.height) / 2.0)), size: labelSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user