@@ -8,10 +8,15 @@ import SwiftSignalKit
88import TelegramPresentationData
99import ChatPresentationInterfaceState
1010import ChatInputPanelNode
11+ import GlassBackgroundComponent
12+ import ComponentFlow
13+ import ComponentDisplayAdapters
14+ import MultilineTextComponent
1115
1216final 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