Support found sticker preview

This commit is contained in:
Ali
2023-03-07 13:50:12 +04:00
parent 69091c606d
commit 48cb7f25ec
3 changed files with 45 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import EntityKeyboard
import ChatControllerInteraction
import MultiplexedVideoNode
import FeaturedStickersScreen
import StickerPeekUI
private let searchBarHeight: CGFloat = 52.0
@@ -37,6 +38,7 @@ public final class PaneSearchContainerNode: ASDisplayNode, EntitySearchContainer
public private(set) var contentNode: PaneSearchContentNode & ASDisplayNode
private let controllerInteraction: ChatControllerInteraction
private let inputNodeInteraction: ChatMediaInputNodeInteraction
private let peekBehavior: EmojiContentPeekBehavior?
private let backgroundNode: ASDisplayNode
private let searchBar: PaneSearchBarNode
@@ -51,11 +53,12 @@ public final class PaneSearchContainerNode: ASDisplayNode, EntitySearchContainer
return self.contentNode.ready
}
public init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, controllerInteraction: ChatControllerInteraction, inputNodeInteraction: ChatMediaInputNodeInteraction, mode: ChatMediaInputSearchMode, trendingGifsPromise: Promise<ChatMediaInputGifPaneTrendingState?>, cancel: @escaping () -> Void) {
public init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, controllerInteraction: ChatControllerInteraction, inputNodeInteraction: ChatMediaInputNodeInteraction, mode: ChatMediaInputSearchMode, trendingGifsPromise: Promise<ChatMediaInputGifPaneTrendingState?>, cancel: @escaping () -> Void, peekBehavior: EmojiContentPeekBehavior?) {
self.context = context
self.mode = mode
self.controllerInteraction = controllerInteraction
self.inputNodeInteraction = inputNodeInteraction
self.peekBehavior = peekBehavior
switch mode {
case .gif:
self.contentNode = GifPaneSearchContentNode(context: context, theme: theme, strings: strings, controllerInteraction: controllerInteraction, inputNodeInteraction: inputNodeInteraction, trendingPromise: trendingGifsPromise)
@@ -103,6 +106,41 @@ public final class PaneSearchContainerNode: ASDisplayNode, EntitySearchContainer
self?.openGifContextMenu?(file, node, rect, gesture, isSaved)
}
}
if let contentNode = self.contentNode as? StickerPaneSearchContentNode, let peekBehavior = self.peekBehavior {
peekBehavior.setGestureRecognizerEnabled(view: self.contentNode.view, isEnabled: true, itemAtPoint: { [weak contentNode] point in
guard let contentNode else {
return nil
}
guard let (itemNode, item) = contentNode.itemAt(point: point) else {
return nil
}
var maybeFile: TelegramMediaFile?
if let item = item as? StickerPreviewPeekItem {
switch item {
case let .found(foundItem):
maybeFile = foundItem.file
case let .pack(fileValue):
maybeFile = fileValue
}
}
guard let file = maybeFile else {
return nil
}
var groupId: AnyHashable = AnyHashable("search")
for attribute in file.attributes {
if case let .Sticker(_, packReference, _) = attribute {
if case let .id(id, _) = packReference {
groupId = AnyHashable(ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id))
}
}
}
return (groupId, itemNode.layer, file)
})
}
}
public func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings) {