@@ -8,6 +8,7 @@ import ContextUI
88import ChatPresentationInterfaceState
99import ComponentFlow
1010import AccountContext
11+ import AnimatedCountLabelNode
1112
1213final class AttachmentTextInputActionButtonsNode : ASDisplayNode , ChatSendMessageActionSheetControllerSourceSendButtonNode {
1314 private let strings : PresentationStrings
@@ -17,7 +18,7 @@ final class AttachmentTextInputActionButtonsNode: ASDisplayNode, ChatSendMessage
1718 let sendButton : HighlightTrackingButtonNode
1819 var sendButtonHasApplyIcon = false
1920 var animatingSendButton = false
20- let textNode : ImmediateTextNode
21+ let textNode : ImmediateAnimatedCountLabelNode
2122
2223 private var theme : PresentationTheme
2324
@@ -46,8 +47,7 @@ final class AttachmentTextInputActionButtonsNode: ASDisplayNode, ChatSendMessage
4647 self . backgroundNode. clipsToBounds = true
4748 self . sendButton = HighlightTrackingButtonNode ( pointerStyle: nil )
4849
49- self . textNode = ImmediateTextNode ( )
50- self . textNode. attributedText = NSAttributedString ( string: self . strings. MediaPicker_Send, font: Font . semibold ( 17.0 ) , textColor: theme. chat. inputPanel. actionControlForegroundColor)
50+ self . textNode = ImmediateAnimatedCountLabelNode ( )
5151 self . textNode. isUserInteractionEnabled = false
5252
5353 super. init ( )
@@ -104,29 +104,51 @@ final class AttachmentTextInputActionButtonsNode: ASDisplayNode, ChatSendMessage
104104
105105 func updateTheme( theme: PresentationTheme , wallpaper: TelegramWallpaper ) {
106106 self . backgroundNode. backgroundColor = theme. chat. inputPanel. actionControlFillColor
107-
108- self . textNode. attributedText = NSAttributedString ( string: self . strings. MediaPicker_Send, font: Font . semibold ( 17.0 ) , textColor: theme. chat. inputPanel. actionControlForegroundColor)
109107 }
110108
111109 private var absoluteRect : ( CGRect , CGSize ) ?
112110 func updateAbsoluteRect( _ rect: CGRect , within containerSize: CGSize , transition: ContainedViewLayoutTransition ) {
113111 self . absoluteRect = ( rect, containerSize)
114112 }
115113
116- func updateLayout( size: CGSize , transition: ContainedViewLayoutTransition , minimized: Bool , interfaceState: ChatPresentationInterfaceState ) -> CGSize {
114+ func updateLayout( size: CGSize , transition: ContainedViewLayoutTransition , minimized: Bool , text : String , interfaceState: ChatPresentationInterfaceState ) -> CGSize {
117115 self . validLayout = size
118116
119117 let width : CGFloat
120- let textSize = self . textNode. updateLayout ( CGSize ( width: 100.0 , height: 100.0 ) )
118+
119+ var titleOffset : CGFloat = 0.0
120+ var segments : [ AnimatedCountLabelNode . Segment ] = [ ]
121+ var buttonInset : CGFloat = 18.0
122+ if text. hasPrefix ( " ⭐️ " ) {
123+ let font = Font . with ( size: 17.0 , design: . round, weight: . semibold, traits: . monospacedNumbers)
124+ let badgeString = NSMutableAttributedString ( string: " ⭐️ " , font: font, textColor: interfaceState. theme. chat. inputPanel. actionControlForegroundColor)
125+ if let range = badgeString. string. range ( of: " ⭐️ " ) {
126+ badgeString. addAttribute ( . attachment, value: PresentationResourcesChat . chatPlaceholderStarIcon ( interfaceState. theme) !, range: NSRange ( range, in: badgeString. string) )
127+ badgeString. addAttribute ( . baselineOffset, value: 1.0 , range: NSRange ( range, in: badgeString. string) )
128+ }
129+ segments. append ( . text( 0 , badgeString) )
130+ for char in text {
131+ if let intValue = Int ( String ( char) ) {
132+ segments. append ( . number( intValue, NSAttributedString ( string: String ( char) , font: font, textColor: interfaceState. theme. chat. inputPanel. actionControlForegroundColor) ) )
133+ }
134+ }
135+ titleOffset -= 2.0
136+ buttonInset = 14.0
137+ } else {
138+ segments. append ( . text( 0 , NSAttributedString ( string: text, font: Font . semibold ( 17.0 ) , textColor: interfaceState. theme. chat. inputPanel. actionControlForegroundColor) ) )
139+ }
140+ self . textNode. segments = segments
141+
142+ let textSize = self . textNode. updateLayout ( size: CGSize ( width: 100.0 , height: 100.0 ) , animated: transition. isAnimated)
121143 if minimized {
122144 width = 44.0
123145 } else {
124- width = textSize. width + 36 .0
146+ width = textSize. width + buttonInset * 2 .0
125147 }
126148
127149 let buttonSize = CGSize ( width: width, height: size. height)
128150
129- transition. updateFrame ( node: self . textNode, frame: CGRect ( origin: CGPoint ( x: floorToScreenPixels ( ( width - textSize. width) / 2.0 ) , y: floorToScreenPixels ( ( buttonSize. height - textSize. height) / 2.0 ) ) , size: textSize) )
151+ transition. updateFrame ( node: self . textNode, frame: CGRect ( origin: CGPoint ( x: floorToScreenPixels ( ( width - textSize. width) / 2.0 ) + titleOffset , y: floorToScreenPixels ( ( buttonSize. height - textSize. height) / 2.0 ) ) , size: textSize) )
130152 transition. updateAlpha ( node: self . textNode, alpha: minimized ? 0.0 : 1.0 )
131153 transition. updateAlpha ( node: self . sendButton. imageNode, alpha: minimized ? 1.0 : 0.0 )
132154
0 commit comments