Update sticker pack add buttons

This commit is contained in:
Ilya Laktyushin 2021-11-26 22:11:09 +04:00
parent e00a658fcb
commit 7a0419ea78

View File

@ -162,7 +162,8 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
private let unreadNode: ASImageNode
private let titleNode: TextNode
private let statusNode: TextNode
private let installationActionImageNode: ASImageNode
private let installTextNode: TextNode
private let installationActionBackgroundNode: ASImageNode
private let installationActionNode: HighlightableButtonNode
private let selectionIconNode: ASImageNode
@ -234,12 +235,17 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
self.unreadNode.displaysAsynchronously = false
self.unreadNode.displayWithoutProcessing = true
self.installationActionImageNode = ASImageNode()
self.installationActionImageNode.displaysAsynchronously = false
self.installationActionImageNode.displayWithoutProcessing = true
self.installationActionImageNode.isLayerBacked = true
self.installationActionBackgroundNode = ASImageNode()
self.installationActionBackgroundNode.displaysAsynchronously = false
self.installationActionBackgroundNode.displayWithoutProcessing = true
self.installationActionBackgroundNode.isLayerBacked = true
self.installationActionNode = HighlightableButtonNode()
self.installTextNode = TextNode()
self.installTextNode.isUserInteractionEnabled = false
self.installTextNode.contentMode = .left
self.installTextNode.contentsScale = UIScreen.main.scale
self.selectionIconNode = ASImageNode()
self.selectionIconNode.displaysAsynchronously = false
self.selectionIconNode.displayWithoutProcessing = true
@ -262,7 +268,8 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
self.containerNode.addSubnode(self.titleNode)
self.containerNode.addSubnode(self.statusNode)
self.containerNode.addSubnode(self.unreadNode)
self.containerNode.addSubnode(self.installationActionImageNode)
self.containerNode.addSubnode(self.installationActionBackgroundNode)
self.containerNode.addSubnode(self.installTextNode)
self.containerNode.addSubnode(self.installationActionNode)
self.containerNode.addSubnode(self.selectionIconNode)
self.addSubnode(self.activateArea)
@ -271,11 +278,11 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
self.installationActionNode.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self {
if highlighted {
strongSelf.installationActionImageNode.layer.removeAnimation(forKey: "opacity")
strongSelf.installationActionImageNode.alpha = 0.4
strongSelf.installationActionBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.installationActionBackgroundNode.alpha = 0.4
} else {
strongSelf.installationActionImageNode.alpha = 1.0
strongSelf.installationActionImageNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
strongSelf.installationActionBackgroundNode.alpha = 1.0
strongSelf.installationActionBackgroundNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
}
}
}
@ -334,6 +341,7 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
let makeImageLayout = self.imageNode.asyncLayout()
let makeTitleLayout = TextNode.asyncLayout(self.titleNode)
let makeStatusLayout = TextNode.asyncLayout(self.statusNode)
let makeInstallLayout = TextNode.asyncLayout(self.installTextNode)
let editableControlLayout = ItemListEditableControlNode.asyncLayout(self.editableControlNode)
let reorderControlLayout = ItemListEditableReorderControlNode.asyncLayout(self.reorderControlNode)
let selectableControlLayout = ItemListSelectableControlNode.asyncLayout(self.selectableControlNode)
@ -365,17 +373,19 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
var rightInset: CGFloat = params.rightInset
var installationActionImage: UIImage?
var installationBackgroundImage: UIImage?
var installationText: String?
var checkImage: UIImage?
switch item.control {
case .none:
break
case let .installation(installed):
rightInset += 50.0
if installed {
installationActionImage = PresentationResourcesItemList.secondaryCheckIconImage(item.presentationData.theme)
installationBackgroundImage = PresentationResourcesChat.chatInputMediaPanelAddedPackButtonImage(item.presentationData.theme)
installationText = item.presentationData.strings.Stickers_Installed
} else {
installationActionImage = PresentationResourcesItemList.plusIconImage(item.presentationData.theme)
installationBackgroundImage = PresentationResourcesChat.chatInputMediaPanelAddPackButtonImage(item.presentationData.theme)
installationText = item.presentationData.strings.Stickers_Install
}
case .selection:
rightInset += 16.0
@ -428,9 +438,22 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
reorderInset = sizeAndApply.0
}
}
var installed = false
if case .installation(true) = item.control {
installed = true
}
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: titleAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - editingOffset - rightInset - 10.0 - reorderInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let (statusLayout, statusApply) = makeStatusLayout(TextNodeLayoutArguments(attributedString: statusAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - editingOffset - rightInset - reorderInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let (installLayout, installApply) = makeInstallLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: installationText ?? "", font: Font.semibold(13.0), textColor: installed ? item.presentationData.theme.list.itemCheckColors.fillColor : item.presentationData.theme.list.itemCheckColors.foregroundColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - params.leftInset - params.rightInset - leftInset - rightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let installWidth: CGFloat
if installLayout.size.width > 0.0 {
installWidth = installLayout.size.width + 32.0
} else {
installWidth = 0.0
}
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: titleAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - editingOffset - rightInset - 10.0 - reorderInset - installWidth, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let (statusLayout, statusApply) = makeStatusLayout(TextNodeLayoutArguments(attributedString: statusAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - editingOffset - rightInset - reorderInset - installWidth, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let contentSize = CGSize(width: params.width, height: verticalInset * 2.0 + titleLayout.size.height + titleSpacing + statusLayout.size.height)
let layout = ListViewItemNodeLayout(contentSize: contentSize, insets: insets)
@ -626,28 +649,32 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
let _ = titleApply()
let _ = statusApply()
let installationActionFrame = CGRect(origin: CGPoint(x: params.width - params.rightInset - 50.0, y: 0.0), size: CGSize(width: 50.0, height: layout.contentSize.height))
strongSelf.installationActionNode.frame = installationActionFrame
let _ = installApply()
switch item.control {
case .none:
strongSelf.installationActionNode.isHidden = true
strongSelf.installationActionImageNode.isHidden = true
strongSelf.installationActionBackgroundNode.isHidden = true
strongSelf.selectionIconNode.isHidden = true
case let .installation(installed):
strongSelf.installationActionImageNode.isHidden = false
strongSelf.installationActionBackgroundNode.isHidden = false
strongSelf.installationActionNode.isHidden = false
strongSelf.selectionIconNode.isHidden = true
strongSelf.installationActionNode.isUserInteractionEnabled = !installed
if let image = installationActionImage {
let imageSize = image.size
strongSelf.installationActionImageNode.image = image
strongSelf.installationActionImageNode.frame = CGRect(origin: CGPoint(x: installationActionFrame.minX + floor((installationActionFrame.size.width - imageSize.width) / 2.0), y: installationActionFrame.minY + floor((installationActionFrame.size.height - imageSize.height) / 2.0)), size: imageSize)
if let backgroundImage = installationBackgroundImage {
strongSelf.installationActionBackgroundNode.image = backgroundImage
}
let installationActionFrame = CGRect(origin: CGPoint(x: params.width - rightInset - installWidth - 16.0, y: 0.0), size: CGSize(width: 50.0, height: layout.contentSize.height))
strongSelf.installationActionNode.frame = installationActionFrame
let buttonFrame = CGRect(origin: CGPoint(x: params.width - rightInset - installWidth - 16.0, y: installationActionFrame.minY + floor((installationActionFrame.size.height - 28.0) / 2.0)), size: CGSize(width: installWidth, height: 28.0))
strongSelf.installationActionBackgroundNode.frame = buttonFrame
strongSelf.installTextNode.frame = CGRect(origin: CGPoint(x: buttonFrame.minX + floor((buttonFrame.width - installLayout.size.width) / 2.0), y: buttonFrame.minY + floor((buttonFrame.height - installLayout.size.height) / 2.0) + 1.0), size: installLayout.size)
case .selection:
strongSelf.installationActionNode.isHidden = true
strongSelf.installationActionImageNode.isHidden = true
strongSelf.installationActionBackgroundNode.isHidden = true
strongSelf.selectionIconNode.isHidden = false
if let image = checkImage {
strongSelf.selectionIconNode.image = image
@ -655,7 +682,7 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
}
case .check:
strongSelf.installationActionNode.isHidden = true
strongSelf.installationActionImageNode.isHidden = true
strongSelf.installationActionBackgroundNode.isHidden = true
strongSelf.selectionIconNode.isHidden = true
}