mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Add stickerpack strip expansion
This commit is contained in:
@@ -11,27 +11,29 @@ import TelegramPresentationData
|
||||
final class ChatMediaInputSettingsItem: ListViewItem {
|
||||
let inputNodeInteraction: ChatMediaInputNodeInteraction
|
||||
let selectedItem: () -> Void
|
||||
let expanded: Bool
|
||||
let theme: PresentationTheme
|
||||
|
||||
var selectable: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
init(inputNodeInteraction: ChatMediaInputNodeInteraction, theme: PresentationTheme, selected: @escaping () -> Void) {
|
||||
init(inputNodeInteraction: ChatMediaInputNodeInteraction, theme: PresentationTheme, expanded: Bool, selected: @escaping () -> Void) {
|
||||
self.inputNodeInteraction = inputNodeInteraction
|
||||
self.selectedItem = selected
|
||||
self.theme = theme
|
||||
self.expanded = expanded
|
||||
}
|
||||
|
||||
func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
|
||||
async {
|
||||
let node = ChatMediaInputSettingsItemNode()
|
||||
node.contentSize = CGSize(width: 41.0, height: 41.0)
|
||||
node.contentSize = self.expanded ? expandedBoundingSize : boundingSize
|
||||
node.insets = ChatMediaInputNode.setupPanelIconInsets(item: self, previousItem: previousItem, nextItem: nextItem)
|
||||
node.inputNodeInteraction = self.inputNodeInteraction
|
||||
node.updateTheme(theme: self.theme)
|
||||
node.updateAppearanceTransition(transition: .immediate)
|
||||
Queue.mainQueue().async {
|
||||
node.updateTheme(theme: self.theme, expanded: self.expanded)
|
||||
completion(node, {
|
||||
return (nil, { _ in })
|
||||
})
|
||||
@@ -41,8 +43,8 @@ final class ChatMediaInputSettingsItem: ListViewItem {
|
||||
|
||||
public func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: @escaping () -> ListViewItemNode, params: ListViewItemLayoutParams, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping (ListViewItemApply) -> Void) -> Void) {
|
||||
Queue.mainQueue().async {
|
||||
completion(ListViewItemNodeLayout(contentSize: node().contentSize, insets: ChatMediaInputNode.setupPanelIconInsets(item: self, previousItem: previousItem, nextItem: nextItem)), { _ in
|
||||
(node() as? ChatMediaInputSettingsItemNode)?.updateTheme(theme: self.theme)
|
||||
completion(ListViewItemNodeLayout(contentSize: self.expanded ? expandedBoundingSize : boundingSize, insets: ChatMediaInputNode.setupPanelIconInsets(item: self, previousItem: previousItem, nextItem: nextItem)), { _ in
|
||||
(node() as? ChatMediaInputSettingsItemNode)?.updateTheme(theme: self.theme, expanded: self.expanded)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -52,14 +54,19 @@ final class ChatMediaInputSettingsItem: ListViewItem {
|
||||
}
|
||||
}
|
||||
|
||||
private let boundingSize = CGSize(width: 41.0, height: 41.0)
|
||||
private let boundingImageSize = CGSize(width: 30.0, height: 30.0)
|
||||
private let highlightSize = CGSize(width: 35.0, height: 35.0)
|
||||
private let boundingSize = CGSize(width: 72.0, height: 41.0)
|
||||
private let expandedBoundingSize = CGSize(width: 72.0, height: 72.0)
|
||||
private let boundingImageScale: CGFloat = 0.625
|
||||
private let verticalOffset: CGFloat = 3.0 + UIScreenPixel
|
||||
|
||||
final class ChatMediaInputSettingsItemNode: ListViewItemNode {
|
||||
private let containerNode: ASDisplayNode
|
||||
private let scalingNode: ASDisplayNode
|
||||
private let buttonNode: HighlightableButtonNode
|
||||
private let imageNode: ASImageNode
|
||||
private let titleNode: ImmediateTextNode
|
||||
|
||||
private var currentExpanded = false
|
||||
|
||||
var currentCollectionId: ItemCollectionId?
|
||||
var inputNodeInteraction: ChatMediaInputNodeInteraction?
|
||||
@@ -67,37 +74,59 @@ final class ChatMediaInputSettingsItemNode: ListViewItemNode {
|
||||
var theme: PresentationTheme?
|
||||
|
||||
init() {
|
||||
self.containerNode = ASDisplayNode()
|
||||
self.containerNode.transform = CATransform3DMakeRotation(CGFloat.pi / 2.0, 0.0, 0.0, 1.0)
|
||||
|
||||
self.scalingNode = ASDisplayNode()
|
||||
|
||||
self.buttonNode = HighlightableButtonNode()
|
||||
|
||||
self.imageNode = ASImageNode()
|
||||
self.imageNode.isLayerBacked = true
|
||||
self.imageNode.contentMode = .center
|
||||
self.imageNode.contentsScale = UIScreenScale
|
||||
|
||||
self.buttonNode.frame = CGRect(origin: CGPoint(), size: boundingSize)
|
||||
|
||||
self.imageNode.transform = CATransform3DMakeRotation(CGFloat.pi / 2.0, 0.0, 0.0, 1.0)
|
||||
self.imageNode.contentMode = .center
|
||||
self.imageNode.contentsScale = UIScreenScale
|
||||
|
||||
self.titleNode = ImmediateTextNode()
|
||||
|
||||
super.init(layerBacked: false, dynamicBounce: false)
|
||||
|
||||
self.addSubnode(self.buttonNode)
|
||||
self.buttonNode.addSubnode(self.imageNode)
|
||||
self.addSubnode(self.containerNode)
|
||||
self.containerNode.addSubnode(self.scalingNode)
|
||||
|
||||
let imageSize = CGSize(width: 26.0, height: 26.0)
|
||||
self.imageNode.frame = CGRect(origin: CGPoint(x: floor((boundingSize.width - imageSize.width) / 2.0) + verticalOffset, y: floor((boundingSize.height - imageSize.height) / 2.0) + UIScreenPixel), size: imageSize)
|
||||
self.scalingNode.addSubnode(self.buttonNode)
|
||||
self.scalingNode.addSubnode(self.imageNode)
|
||||
}
|
||||
|
||||
deinit {
|
||||
}
|
||||
|
||||
func updateTheme(theme: PresentationTheme) {
|
||||
|
||||
func updateTheme(theme: PresentationTheme, expanded: Bool) {
|
||||
let imageSize = CGSize(width: 26.0 * 1.6, height: 26.0 * 1.6)
|
||||
self.imageNode.frame = CGRect(origin: CGPoint(x: floor((expandedBoundingSize.width - imageSize.width) / 2.0), y: floor((expandedBoundingSize.height - imageSize.height) / 2.0) + UIScreenPixel), size: imageSize)
|
||||
|
||||
if self.theme !== theme {
|
||||
self.theme = theme
|
||||
|
||||
self.imageNode.image = PresentationResourcesChat.chatInputMediaPanelSettingsIconImage(theme)
|
||||
|
||||
self.titleNode.attributedText = NSAttributedString(string: "Settings", font: Font.regular(11.0), textColor: theme.chat.inputPanel.primaryTextColor)
|
||||
}
|
||||
|
||||
self.containerNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: expandedBoundingSize)
|
||||
self.scalingNode.bounds = CGRect(origin: CGPoint(), size: expandedBoundingSize)
|
||||
self.buttonNode.frame = self.scalingNode.bounds
|
||||
|
||||
let boundsSize = expanded ? expandedBoundingSize : CGSize(width: boundingSize.height, height: boundingSize.height)
|
||||
let expandScale: CGFloat = expanded ? 1.0 : boundingImageScale
|
||||
let expandTransition: ContainedViewLayoutTransition = self.currentExpanded != expanded ? .animated(duration: 0.3, curve: .spring) : .immediate
|
||||
expandTransition.updateTransformScale(node: self.scalingNode, scale: expandScale)
|
||||
expandTransition.updatePosition(node: self.scalingNode, position: CGPoint(x: boundsSize.width / 2.0, y: boundsSize.height / 2.0 + (expanded ? -2.0 : 3.0)))
|
||||
|
||||
expandTransition.updateAlpha(node: self.titleNode, alpha: expanded ? 1.0 : 0.0)
|
||||
let titleSize = self.titleNode.updateLayout(CGSize(width: expandedBoundingSize.width - 8.0, height: expandedBoundingSize.height))
|
||||
|
||||
let titleFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((expandedBoundingSize.width - titleSize.width) / 2.0), y: expandedBoundingSize.height - titleSize.height + 2.0), size: titleSize)
|
||||
let displayTitleFrame = expanded ? titleFrame : CGRect(origin: CGPoint(x: titleFrame.minX, y: self.imageNode.position.y - titleFrame.size.height), size: titleFrame.size)
|
||||
expandTransition.updateFrameAsPositionAndBounds(node: self.titleNode, frame: displayTitleFrame)
|
||||
expandTransition.updateTransformScale(node: self.titleNode, scale: expanded ? 1.0 : 0.001)
|
||||
|
||||
self.currentExpanded = expanded
|
||||
|
||||
}
|
||||
|
||||
func updateAppearanceTransition(transition: ContainedViewLayoutTransition) {
|
||||
|
||||
Reference in New Issue
Block a user