Various Improvements

This commit is contained in:
Ilya Laktyushin
2021-09-17 21:25:13 +03:00
parent 151a472294
commit 1f285271b2
22 changed files with 407 additions and 91 deletions

View File

@@ -25,6 +25,7 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
private let context: AccountContext
private var theme: PresentationTheme
private var strings: PresentationStrings
private let peerId: PeerId?
private let scrollNode: ASScrollNode
private var items: [TelegramMediaFile] = []
@@ -36,6 +37,8 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
private var ignoreScrolling: Bool = false
private var animateInOnLayout: Bool = false
private weak var peekController: PeekController?
var previewedStickerItem: StickerPackItem?
var updateBackgroundOffset: ((CGFloat, Bool, ContainedViewLayoutTransition) -> Void)?
@@ -53,10 +56,11 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
|> distinctUntilChanged
}
init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings) {
init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, peerId: PeerId?) {
self.context = context
self.theme = theme
self.strings = strings
self.peerId = peerId
self.scrollNode = ASScrollNode()
@@ -99,12 +103,36 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
|> map { isStarred -> (ASDisplayNode, PeekControllerContent)? in
if let strongSelf = self, let controllerInteraction = strongSelf.getControllerInteraction?() {
var menuItems: [ContextMenuItem] = []
menuItems = [
.action(ContextMenuActionItem(text: strongSelf.strings.StickerPack_Send, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Resend"), color: theme.contextMenu.primaryColor) }, action: { _, f in
if strongSelf.peerId != strongSelf.context.account.peerId && strongSelf.peerId?.namespace != Namespaces.Peer.SecretChat {
menuItems.append(.action(ContextMenuActionItem(text: strongSelf.strings.Conversation_SendMessage_SendSilently, icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/SilentIcon"), color: theme.actionSheet.primaryTextColor)
}, action: { _, f in
if let strongSelf = self, let peekController = strongSelf.peekController {
if let animationNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.animationNode {
let _ = controllerInteraction.sendSticker(.standalone(media: item.file), true, false, nil, false, animationNode, animationNode.bounds)
} else if let imageNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.imageNode {
let _ = controllerInteraction.sendSticker(.standalone(media: item.file), true, false, nil, false, imageNode, imageNode.bounds)
}
}
f(.default)
})))
}
menuItems.append(.action(ContextMenuActionItem(text: strongSelf.strings.Conversation_SendMessage_ScheduleMessage, icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Menu/ScheduleIcon"), color: theme.actionSheet.primaryTextColor)
}, action: { _, f in
if let strongSelf = self, let peekController = strongSelf.peekController {
if let animationNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.animationNode {
let _ = controllerInteraction.sendSticker(.standalone(media: item.file), false, true, nil, false, animationNode, animationNode.bounds)
} else if let imageNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.imageNode {
let _ = controllerInteraction.sendSticker(.standalone(media: item.file), false, true, nil, false, imageNode, imageNode.bounds)
}
}
f(.default)
let _ = controllerInteraction.sendSticker(.standalone(media: item.file), false, false, nil, true, itemNode, itemNode.bounds)
})),
})))
menuItems.append(
.action(ContextMenuActionItem(text: isStarred ? strongSelf.strings.Stickers_RemoveFromFavorites : strongSelf.strings.Stickers_AddToFavorites, icon: { theme in generateTintedImage(image: isStarred ? UIImage(bundleImageName: "Chat/Context Menu/Unstar") : UIImage(bundleImageName: "Chat/Context Menu/Rate"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
f(.default)
@@ -115,7 +143,10 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
let _ = addSavedSticker(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, file: item.file).start()
}
}
})),
}))
)
menuItems.append(
.action(ContextMenuActionItem(text: strongSelf.strings.StickerPack_ViewPack, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Sticker"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
f(.default)
@@ -141,7 +172,8 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
}
}
}
}))]
}))
)
return (itemNode, StickerPreviewPeekContent(account: strongSelf.context.account, item: .pack(item), menu: menuItems))
} else {
return nil
@@ -159,6 +191,7 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
controller.visibilityUpdated = { [weak self] visible in
self?.previewingStickersPromise.set(visible)
}
strongSelf.peekController = controller
strongSelf.getControllerInteraction?()?.presentGlobalOverlayController(controller, nil)
return controller
}
@@ -431,7 +464,7 @@ final class InlineReactionSearchPanel: ChatInputContextPanelNode {
private var choosingStickerDisposable: Disposable?
override init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize) {
init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize, peerId: PeerId?) {
self.containerNode = ASDisplayNode()
self.backgroundNode = ASDisplayNode()
@@ -472,7 +505,7 @@ final class InlineReactionSearchPanel: ChatInputContextPanelNode {
self.backgroundContainerNode = ASDisplayNode()
self.stickersNode = InlineReactionSearchStickersNode(context: context, theme: theme, strings: strings)
self.stickersNode = InlineReactionSearchStickersNode(context: context, theme: theme, strings: strings, peerId: peerId)
super.init(context: context, theme: theme, strings: strings, fontSize: fontSize)