Update Invite Contacts UI

This commit is contained in:
Ilya Laktyushin 2019-12-04 19:31:55 +04:00
parent 2e12321d82
commit 47ee5eaacd
6 changed files with 3871 additions and 3898 deletions

View File

@ -5164,3 +5164,10 @@ Any member of this group will be able to see messages in the channel.";
"MediaPlayer.UnknownArtist" = "Unknown Artist";
"MediaPlayer.UnknownTrack" = "Unknown Track";
"Contacts.InviteContacts_1" = "Invite %@ Contact";
"Contacts.InviteContacts_2" = "Invite %@ Contacts";
"Contacts.InviteContacts_3_10" = "Invite %@ Contacts";
"Contacts.InviteContacts_any" = "Invite %@ Contacts";
"Contacts.InviteContacts_many" = "Invite %@ Contacts";
"Contacts.InviteContacts_0" = "Invite %@ Contacts";

View File

@ -29,6 +29,7 @@ static_library(
"//submodules/AppBundle:AppBundle",
"//submodules/OverlayStatusController:OverlayStatusController",
"//submodules/PhoneNumberFormat:PhoneNumberFormat",
"//submodules/SolidRoundedButtonNode:SolidRoundedButtonNode",
],
frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework",

View File

@ -247,7 +247,7 @@ final class InviteContactsControllerNode: ASDisplayNode {
didSet {
if self.selectionState != oldValue {
self.selectionStatePromise.set(.single(self.selectionState))
self.countPanelNode.badge = "\(self.selectionState.selectedContactIndices.count)"
self.countPanelNode.count = self.selectionState.selectedContactIndices.count
if oldValue.selectedContactIndices.isEmpty != self.selectionState.selectedContactIndices.isEmpty {
if let (layout, navigationHeight, actualNavigationHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationBarHeight: navigationHeight, actualNavigationBarHeight: actualNavigationHeight, transition: .animated(duration: 0.3, curve: .spring))

View File

@ -3,25 +3,21 @@ import UIKit
import AsyncDisplayKit
import Display
import TelegramPresentationData
import SolidRoundedButtonNode
final class InviteContactsCountPanelNode: ASDisplayNode {
private let theme: PresentationTheme
private let action: () -> Void
private let strings: PresentationStrings
private let separatorNode: ASDisplayNode
private let labelNode: ImmediateTextNode
private let badgeLabel: ImmediateTextNode
private let badgeBackground: ASImageNode
private let buttonNode: HighlightableButtonNode
private let button: SolidRoundedButtonNode
private var validLayout: (CGFloat, CGFloat)?
var badge: String? {
var count: Int = 0 {
didSet {
if self.badge != oldValue {
if let badge = self.badge {
self.badgeLabel.attributedText = NSAttributedString(string: badge, font: Font.regular(14.0), textColor: self.theme.rootController.navigationBar.badgeTextColor, paragraphAlignment: .center)
}
if self.count != oldValue && self.count > 0 {
self.button.title = self.strings.Contacts_InviteContacts(Int32(self.count))
if let (width, bottomInset) = self.validLayout {
let _ = self.updateLayout(width: width, bottomInset: bottomInset, transition: .immediate)
@ -32,74 +28,38 @@ final class InviteContactsCountPanelNode: ASDisplayNode {
init(theme: PresentationTheme, strings: PresentationStrings, action: @escaping () -> Void) {
self.theme = theme
self.action = action
self.strings = strings
self.separatorNode = ASDisplayNode()
self.separatorNode.backgroundColor = theme.rootController.navigationBar.separatorColor
self.labelNode = ImmediateTextNode()
self.badgeLabel = ImmediateTextNode()
self.badgeBackground = ASImageNode()
self.badgeBackground.isLayerBacked = true
self.badgeBackground.displaysAsynchronously = false
self.badgeBackground.displayWithoutProcessing = true
self.badgeBackground.image = generateStretchableFilledCircleImage(diameter: 22.0, color: theme.rootController.navigationBar.accentTextColor)
self.buttonNode = HighlightableButtonNode()
self.button = SolidRoundedButtonNode(theme: SolidRoundedButtonTheme(theme: theme), height: 48.0, cornerRadius: 10.0)
super.init()
self.backgroundColor = theme.rootController.navigationBar.backgroundColor
self.addSubnode(self.labelNode)
self.labelNode.attributedText = NSAttributedString(string: strings.Contacts_InviteToTelegram, font: Font.regular(17.0), textColor: theme.rootController.navigationBar.accentTextColor)
self.addSubnode(self.badgeBackground)
self.addSubnode(self.badgeLabel)
self.addSubnode(self.button)
self.addSubnode(self.separatorNode)
self.addSubnode(self.buttonNode)
self.buttonNode.addTarget(self, action: #selector(self.buttonPressed), forControlEvents: .touchUpInside)
self.buttonNode.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self {
if highlighted {
strongSelf.labelNode.layer.removeAnimation(forKey: "opacity")
strongSelf.labelNode.alpha = 0.4
} else {
strongSelf.labelNode.alpha = 1.0
strongSelf.labelNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
}
}
self.button.pressed = {
action()
}
}
func updateLayout(width: CGFloat, bottomInset: CGFloat, transition: ContainedViewLayoutTransition) -> CGFloat {
self.validLayout = (width, bottomInset)
let topInset: CGFloat = 9.0
var bottomInset = bottomInset
bottomInset += topInset - (bottomInset.isZero ? 0.0 : 4.0)
let panelHeight: CGFloat = bottomInset + 44.0
let titleSize = self.labelNode.updateLayout(CGSize(width: width, height: 100.0))
let titleFrame = CGRect(origin: CGPoint(x: floor((width - titleSize.width) / 2.0), y: floor((44.0 - titleSize.height) / 2.0)), size: titleSize)
transition.updateFrame(node: self.labelNode, frame: titleFrame)
let badgeSize = self.badgeLabel.updateLayout(CGSize(width: 100.0, height: 100.0))
let backgroundSize = CGSize(width: max(22.0, badgeSize.width + 10.0 + 1.0), height: 22.0)
let backgroundFrame = CGRect(origin: CGPoint(x: titleFrame.maxX + 6.0, y: 11.0), size: backgroundSize)
self.badgeBackground.frame = backgroundFrame
self.badgeLabel.frame = CGRect(origin: CGPoint(x: floorToScreenPixels(backgroundFrame.midX - badgeSize.width / 2.0), y: backgroundFrame.minY + 3.0), size: badgeSize)
let buttonInset: CGFloat = 16.0
let buttonWidth = width - buttonInset * 2.0
let buttonHeight = self.button.updateLayout(width: buttonWidth, transition: transition)
transition.updateFrame(node: self.button, frame: CGRect(x: buttonInset, y: topInset, width: buttonWidth, height: buttonHeight))
transition.updateFrame(node: self.separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: width, height: UIScreenPixel)))
self.buttonNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: width, height: 44.0))
return panelHeight
}
@objc func buttonPressed() {
self.action()
return topInset + buttonHeight + bottomInset
}
}