Skip to content

Commit 724b4cc

Browse files
author
Isaac
committed
Various improvements
1 parent 29edd18 commit 724b4cc

File tree

3 files changed

+62
-44
lines changed

3 files changed

+62
-44
lines changed

submodules/TelegramUI/Components/Chat/ChatTextInputPanelNode/Sources/ChatTextInputPanelNode.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,9 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
19941994
if interfaceState.interfaceState.mediaDraftState != nil {
19951995
audioRecordingItemsAlpha = 0.0
19961996
}
1997+
1998+
transition.updateAlpha(layer: self.actionButtons.micButtonBackgroundView.layer, alpha: mediaRecordingState != nil ? 0.01 : 1.0)
1999+
19972000
if let mediaRecordingState {
19982001
audioRecordingItemsAlpha = 0.0
19992002

submodules/TelegramUI/Components/GlassBackgroundComponent/Sources/GlassBackgroundComponent.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public class GlassBackgroundView: UIView {
407407
context.clear(CGRect(origin: CGPoint(), size: size))
408408

409409
context.setFillColor(UIColor.black.cgColor)
410-
context.setShadow(offset: CGSize(width: 0.0, height: 1.0), blur: 40.0, color: UIColor(white: 0.0, alpha: 0.065).cgColor)
410+
context.setShadow(offset: CGSize(width: 0.0, height: 1.0), blur: 40.0, color: UIColor(white: 0.0, alpha: 0.04).cgColor)
411411
context.fillEllipse(in: CGRect(origin: CGPoint(x: shadowInset + shadowInnerInset, y: shadowInset + shadowInnerInset), size: CGSize(width: size.width - shadowInset * 2.0 - shadowInnerInset * 2.0, height: size.height - shadowInset * 2.0 - shadowInnerInset * 2.0)))
412412

413413
context.setFillColor(UIColor.clear.cgColor)
@@ -684,7 +684,8 @@ public extension GlassBackgroundView {
684684
}
685685
}
686686

687-
addShadow(context, true, CGPoint(), 6.0, 0.0, UIColor(white: 0.0, alpha: 0.08), .normal)
687+
addShadow(context, true, CGPoint(), 10.0, 0.0, UIColor(white: 0.0, alpha: 0.06), .normal)
688+
addShadow(context, true, CGPoint(), 20.0, 0.0, UIColor(white: 0.0, alpha: 0.06), .normal)
688689

689690
let innerImage = UIGraphicsImageRenderer(size: size).image { ctx in
690691
let context = ctx.cgContext
@@ -710,7 +711,7 @@ public extension GlassBackgroundView {
710711
addShadow(context, false, CGPoint(x: 0.64, y: 0.64), 0.8, 0.0, UIColor(white: 1.0, alpha: edgeAlpha), .normal)
711712
}
712713
} else if b >= 0.2 {
713-
let edgeAlpha: CGFloat = max(0.2, min(isDark ? 0.7 : 0.8, a * a * a))
714+
let edgeAlpha: CGFloat = max(0.2, min(isDark ? 0.7 : 0.7, a * a * a))
714715

715716
addShadow(context, false, CGPoint(x: -0.64, y: -0.64), 0.5, 0.0, UIColor(white: 1.0, alpha: edgeAlpha), .plusLighter)
716717
addShadow(context, false, CGPoint(x: 0.64, y: 0.64), 0.5, 0.0, UIColor(white: 1.0, alpha: edgeAlpha), .plusLighter)

submodules/TelegramUI/Sources/ChatUnblockInputPanelNode.swift

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import SwiftSignalKit
88
import TelegramPresentationData
99
import ChatPresentationInterfaceState
1010
import ChatInputPanelNode
11+
import GlassBackgroundComponent
12+
import ComponentFlow
13+
import ComponentDisplayAdapters
14+
import MultilineTextComponent
1115

1216
final class ChatUnblockInputPanelNode: ChatInputPanelNode {
13-
private let button: HighlightableButtonNode
14-
private let activityIndicator: UIActivityIndicatorView
17+
private let backgroundView: GlassBackgroundView
18+
private let title = ComponentView<Empty>()
19+
private let button: HighlightTrackingButton
1520

1621
private var statusDisposable: Disposable?
1722

@@ -23,15 +28,7 @@ final class ChatUnblockInputPanelNode: ChatInputPanelNode {
2328
if let startingBot = self.interfaceInteraction?.statuses?.unblockingPeer {
2429
self.statusDisposable = (startingBot |> deliverOnMainQueue).startStrict(next: { [weak self] value in
2530
if let strongSelf = self {
26-
if value != !strongSelf.activityIndicator.isHidden {
27-
if value {
28-
strongSelf.activityIndicator.isHidden = false
29-
strongSelf.activityIndicator.startAnimating()
30-
} else {
31-
strongSelf.activityIndicator.isHidden = true
32-
strongSelf.activityIndicator.stopAnimating()
33-
}
34-
}
31+
strongSelf.title.view?.alpha = value ? 0.7 : 1.0
3532
}
3633
})
3734
}
@@ -46,16 +43,29 @@ final class ChatUnblockInputPanelNode: ChatInputPanelNode {
4643
self.theme = theme
4744
self.strings = strings
4845

49-
self.button = HighlightableButtonNode()
50-
self.activityIndicator = UIActivityIndicatorView(style: .medium)
51-
self.activityIndicator.isHidden = true
46+
self.backgroundView = GlassBackgroundView()
47+
self.backgroundView.isUserInteractionEnabled = false
48+
49+
self.button = HighlightTrackingButton()
5250

5351
super.init()
5452

55-
self.addSubnode(self.button)
56-
self.view.addSubview(self.activityIndicator)
53+
self.view.addSubview(self.button)
54+
self.view.addSubview(self.backgroundView)
55+
56+
self.button.addTarget(self, action: #selector(self.buttonPressed), for: [.touchUpInside])
5757

58-
self.button.addTarget(self, action: #selector(self.buttonPressed), forControlEvents: [.touchUpInside])
58+
self.button.highligthedChanged = { [weak self] highlighted in
59+
guard let self else {
60+
return
61+
}
62+
if highlighted {
63+
self.backgroundView.contentView.alpha = 0.6
64+
} else {
65+
self.backgroundView.contentView.alpha = 1.0
66+
self.backgroundView.contentView.layer.animateAlpha(from: 0.6, to: 1.0, duration: 0.2)
67+
}
68+
}
5969
}
6070

6171
deinit {
@@ -66,14 +76,12 @@ final class ChatUnblockInputPanelNode: ChatInputPanelNode {
6676
if self.theme !== theme || self.strings !== strings {
6777
self.theme = theme
6878
self.strings = strings
69-
70-
self.button.setAttributedTitle(NSAttributedString(string: self.button.attributedTitle(for: [])?.string ?? "", font: Font.regular(17.0), textColor: theme.chat.inputPanel.panelControlAccentColor), for: [])
7179
}
7280
}
7381

7482
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
7583
if self.bounds.contains(point) {
76-
return self.button.view
84+
return self.button
7785
} else {
7886
return nil
7987
}
@@ -86,33 +94,39 @@ final class ChatUnblockInputPanelNode: ChatInputPanelNode {
8694
override func updateLayout(width: CGFloat, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, additionalSideInsets: UIEdgeInsets, maxHeight: CGFloat, maxOverlayHeight: CGFloat, isSecondary: Bool, transition: ContainedViewLayoutTransition, interfaceState: ChatPresentationInterfaceState, metrics: LayoutMetrics, isMediaInputExpanded: Bool) -> CGFloat {
8795
if self.presentationInterfaceState != interfaceState {
8896
self.presentationInterfaceState = interfaceState
89-
90-
91-
let string: NSAttributedString
92-
if let user = interfaceState.renderedPeer?.peer as? TelegramUser, user.botInfo != nil {
93-
string = NSAttributedString(string: strings.Bot_Unblock, font: Font.regular(17.0), textColor: theme.chat.inputPanel.panelControlAccentColor)
94-
} else {
95-
string = NSAttributedString(string: strings.Conversation_Unblock, font: Font.regular(17.0), textColor: theme.chat.inputPanel.panelControlAccentColor)
96-
}
97-
let updated: Bool
98-
if let current = self.button.attributedTitle(for: []) {
99-
updated = !current.isEqual(to: string)
100-
} else {
101-
updated = true
102-
}
103-
if updated {
104-
self.button.setAttributedTitle(string, for: [])
105-
}
10697
}
10798

108-
let buttonSize = self.button.measure(CGSize(width: width - leftInset - rightInset - 80.0, height: 100.0))
99+
let string: String
100+
if let user = interfaceState.renderedPeer?.peer as? TelegramUser, user.botInfo != nil {
101+
string = strings.Bot_Unblock
102+
} else {
103+
string = strings.Conversation_Unblock
104+
}
105+
106+
let titleSize = self.title.update(
107+
transition: .immediate,
108+
component: AnyComponent(MultilineTextComponent(
109+
text: .plain(NSAttributedString(string: string, font: Font.regular(17.0), textColor: theme.chat.inputPanel.panelControlColor))
110+
)),
111+
environment: {},
112+
containerSize: CGSize(width: width - leftInset - rightInset, height: 100.0)
113+
)
109114

110115
let panelHeight = defaultHeight(metrics: metrics)
111116

112-
self.button.frame = CGRect(origin: CGPoint(x: leftInset + floor((width - leftInset - rightInset - buttonSize.width) / 2.0), y: floor((panelHeight - buttonSize.height) / 2.0)), size: buttonSize)
117+
let buttonSize = CGSize(width: titleSize.width + 16.0 * 2.0, height: 40.0)
118+
let buttonFrame = CGRect(origin: CGPoint(x: floor((width - buttonSize.width) / 2.0), y: floor((panelHeight - buttonSize.height) * 0.5)), size: buttonSize)
119+
transition.updateFrame(view: self.button, frame: buttonFrame)
120+
transition.updateFrame(view: self.backgroundView, frame: buttonFrame)
121+
self.backgroundView.update(size: buttonFrame.size, cornerRadius: buttonFrame.height * 0.5, isDark: interfaceState.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: interfaceState.theme.chat.inputPanel.inputBackgroundColor.withMultipliedAlpha(0.7)), transition: ComponentTransition(transition))
113122

114-
let indicatorSize = self.activityIndicator.bounds.size
115-
self.activityIndicator.frame = CGRect(origin: CGPoint(x: width - rightInset - indicatorSize.width - 12.0, y: floor((panelHeight - indicatorSize.height) / 2.0)), size: indicatorSize)
123+
let titleFrame = CGRect(origin: CGPoint(x: floor((buttonFrame.width - titleSize.width) * 0.5), y: floor((buttonFrame.height - titleSize.height) * 0.5)), size: titleSize)
124+
if let titleView = self.title.view {
125+
if titleView.superview == nil {
126+
self.backgroundView.contentView.addSubview(titleView)
127+
}
128+
titleView.frame = titleFrame
129+
}
116130

117131
return panelHeight
118132
}

0 commit comments

Comments
 (0)