Various fixes

This commit is contained in:
Ilya Laktyushin 2022-10-23 02:50:45 +03:00
parent 95ee0e7cf3
commit 0bf8b373e3
7 changed files with 77 additions and 30 deletions

View File

@ -92,6 +92,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
private let openMessage: (EnginePeer, Int64?, EngineMessage.Id, Bool) -> Void private let openMessage: (EnginePeer, Int64?, EngineMessage.Id, Bool) -> Void
private let navigationController: NavigationController? private let navigationController: NavigationController?
private let dimNode: ASDisplayNode
let filterContainerNode: ChatListSearchFiltersContainerNode let filterContainerNode: ChatListSearchFiltersContainerNode
private let paneContainerNode: ChatListSearchPaneContainerNode private let paneContainerNode: ChatListSearchPaneContainerNode
private var selectionPanelNode: ChatListSearchMessageSelectionPanelNode? private var selectionPanelNode: ChatListSearchMessageSelectionPanelNode?
@ -149,6 +150,9 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
self.present = present self.present = present
self.presentInGlobalOverlay = presentInGlobalOverlay self.presentInGlobalOverlay = presentInGlobalOverlay
self.dimNode = ASDisplayNode()
self.dimNode.backgroundColor = UIColor.black.withAlphaComponent(0.5)
self.filterContainerNode = ChatListSearchFiltersContainerNode() self.filterContainerNode = ChatListSearchFiltersContainerNode()
self.paneContainerNode = ChatListSearchPaneContainerNode(context: context, animationCache: animationCache, animationRenderer: animationRenderer, updatedPresentationData: updatedPresentationData, peersFilter: self.peersFilter, location: location, searchQuery: self.searchQuery.get(), searchOptions: self.searchOptions.get(), navigationController: navigationController) self.paneContainerNode = ChatListSearchPaneContainerNode(context: context, animationCache: animationCache, animationRenderer: animationRenderer, updatedPresentationData: updatedPresentationData, peersFilter: self.peersFilter, location: location, searchQuery: self.searchQuery.get(), searchOptions: self.searchOptions.get(), navigationController: navigationController)
self.paneContainerNode.clipsToBounds = true self.paneContainerNode.clipsToBounds = true
@ -157,6 +161,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
self.backgroundColor = filter.contains(.excludeRecent) ? nil : self.presentationData.theme.chatList.backgroundColor self.backgroundColor = filter.contains(.excludeRecent) ? nil : self.presentationData.theme.chatList.backgroundColor
self.addSubnode(self.dimNode)
self.addSubnode(self.paneContainerNode) self.addSubnode(self.paneContainerNode)
let interaction = ChatListSearchInteraction(openPeer: { peer, chatPeer, threadId, value in let interaction = ChatListSearchInteraction(openPeer: { peer, chatPeer, threadId, value in
@ -483,10 +488,21 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
self.copyProtectionTooltipController?.dismiss() self.copyProtectionTooltipController?.dismiss()
} }
public override func didLoad() {
super.didLoad()
self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture(_:))))
}
public override var hasDim: Bool { public override var hasDim: Bool {
return self.peersFilter.contains(.excludeRecent) return self.peersFilter.contains(.excludeRecent)
} }
public override var animateBackgroundAppearance: Bool {
return !self.hasDim
}
private func updateState(_ f: (ChatListSearchContainerNodeSearchState) -> ChatListSearchContainerNodeSearchState) { private func updateState(_ f: (ChatListSearchContainerNodeSearchState) -> ChatListSearchContainerNodeSearchState) {
let state = f(self.stateValue) let state = f(self.stateValue)
if state != self.stateValue { if state != self.stateValue {
@ -607,6 +623,12 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
self.setQuery?(nil, tokens, query ?? "") self.setQuery?(nil, tokens, query ?? "")
} }
@objc private func dimTapGesture(_ recognizer: UITapGestureRecognizer) {
if case .ended = recognizer.state {
self.cancel?()
}
}
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { override public func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition) super.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition)
@ -614,6 +636,8 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
self.validLayout = (layout, navigationBarHeight) self.validLayout = (layout, navigationBarHeight)
let topInset = navigationBarHeight let topInset = navigationBarHeight
transition.updateFrame(node: self.dimNode, frame: CGRect(origin: CGPoint(x: 0.0, y: topInset), size: CGSize(width: layout.size.width, height: layout.size.height - topInset)))
transition.updateFrame(node: self.filterContainerNode, frame: CGRect(origin: CGPoint(x: 0.0, y: navigationBarHeight + 6.0), size: CGSize(width: layout.size.width, height: 38.0))) transition.updateFrame(node: self.filterContainerNode, frame: CGRect(origin: CGPoint(x: 0.0, y: navigationBarHeight + 6.0), size: CGSize(width: layout.size.width, height: 38.0)))
var isForum = false var isForum = false

View File

@ -376,8 +376,11 @@ final class ChatListSearchPaneContainerNode: ASDisplayNode, UIGestureRecognizerD
self.currentParams = (size, sideInset, bottomInset, visibleHeight, presentationData, availablePanes) self.currentParams = (size, sideInset, bottomInset, visibleHeight, presentationData, availablePanes)
if case .forum = self.location {
self.backgroundColor = .clear
} else {
self.backgroundColor = presentationData.theme.list.itemBlocksBackgroundColor self.backgroundColor = presentationData.theme.list.itemBlocksBackgroundColor
}
let paneFrame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height)) let paneFrame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))
var visiblePaneIndices: [Int] = [] var visiblePaneIndices: [Int] = []

View File

@ -1834,6 +1834,10 @@ public final class ChatListNode: ListView {
return strongSelf.isSelectionGestureEnabled return strongSelf.isSelectionGestureEnabled
} }
self.view.addGestureRecognizer(selectionRecognizer) self.view.addGestureRecognizer(selectionRecognizer)
if case .forum = location {
self.isSelectionGestureEnabled = false
}
} }
deinit { deinit {

View File

@ -213,7 +213,9 @@ public final class SearchDisplayController {
if let placeholder = placeholder { if let placeholder = placeholder {
let initialTextBackgroundFrame = placeholder.convert(placeholder.backgroundNode.frame, to: nil) let initialTextBackgroundFrame = placeholder.convert(placeholder.backgroundNode.frame, to: nil)
let contentNodePosition = self.backgroundNode.layer.position let contentNodePosition = self.backgroundNode.layer.position
if contentNode.animateBackgroundAppearance {
self.backgroundNode.layer.animatePosition(from: CGPoint(x: contentNodePosition.x, y: contentNodePosition.y + (initialTextBackgroundFrame.maxY + 8.0 - contentNavigationBarHeight)), to: contentNodePosition, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring) self.backgroundNode.layer.animatePosition(from: CGPoint(x: contentNodePosition.x, y: contentNodePosition.y + (initialTextBackgroundFrame.maxY + 8.0 - contentNavigationBarHeight)), to: contentNodePosition, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring)
}
self.searchBar.placeholderString = placeholder.placeholderString self.searchBar.placeholderString = placeholder.placeholderString
} }
} }

View File

@ -12,6 +12,10 @@ open class SearchDisplayControllerContentNode: ASDisplayNode {
public final var setQuery: ((NSAttributedString?, [SearchBarToken], String) -> Void)? public final var setQuery: ((NSAttributedString?, [SearchBarToken], String) -> Void)?
public final var setPlaceholder: ((String) -> Void)? public final var setPlaceholder: ((String) -> Void)?
open var animateBackgroundAppearance: Bool {
return true
}
open var hasDim: Bool { open var hasDim: Bool {
return false return false
} }

View File

@ -1394,8 +1394,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
isSelectionEnabled = false isSelectionEnabled = false
} else if case .pinnedMessages = self.chatPresentationInterfaceState.subject { } else if case .pinnedMessages = self.chatPresentationInterfaceState.subject {
isSelectionEnabled = false isSelectionEnabled = false
} else if case .forum = self.chatLocation {
isSelectionEnabled = false
} }
self.historyNode.isSelectionGestureEnabled = isSelectionEnabled self.historyNode.isSelectionGestureEnabled = isSelectionEnabled

View File

@ -348,7 +348,7 @@ final class ChatLoadingPlaceholderNode: ASDisplayNode {
let messageContainer = self.messageContainers[k] let messageContainer = self.messageContainers[k]
let messageSize = messageContainer.frame.size let messageSize = messageContainer.frame.size
messageContainer.update(size: size, hasAvatar: self.isGroup, rect: CGRect(origin: CGPoint(x: 0.0, y: offset - messageSize.height), size: messageSize), transition: transition) messageContainer.update(size: size, hasAvatar: self.chatType != .channel, rect: CGRect(origin: CGPoint(x: 0.0, y: offset - messageSize.height), size: messageSize), transition: transition)
offset -= messageSize.height offset -= messageSize.height
} }
} }
@ -374,19 +374,28 @@ final class ChatLoadingPlaceholderNode: ASDisplayNode {
} }
} }
private var isGroup = false enum ChatType: Equatable {
case generic
case group
case channel
}
private var chatType: ChatType = .channel
func updatePresentationInterfaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState) { func updatePresentationInterfaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState) {
var isGroup = false var chatType: ChatType = .channel
if let peer = chatPresentationInterfaceState.renderedPeer?.peer { if let peer = chatPresentationInterfaceState.renderedPeer?.peer {
if peer is TelegramGroup { if peer is TelegramGroup {
isGroup = true chatType = .group
} else if let channel = peer as? TelegramChannel, case .group = channel.info { } else if let channel = peer as? TelegramChannel {
isGroup = true if case .group = channel.info {
chatType = .group
} else {
chatType = .channel
}
} }
} }
if self.isGroup != isGroup { if self.chatType != chatType {
self.isGroup = isGroup self.chatType = chatType
if let (size, insets) = self.validLayout { if let (size, insets) = self.validLayout {
self.updateLayout(size: size, insets: insets, transition: .immediate) self.updateLayout(size: size, insets: insets, transition: .immediate)
} }
@ -417,27 +426,30 @@ final class ChatLoadingPlaceholderNode: ASDisplayNode {
let dimensions: [CGSize] = [ let dimensions: [CGSize] = [
CGSize(width: floorToScreenPixels(0.47 * size.width), height: tallHeight), CGSize(width: floorToScreenPixels(0.47 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.57 * size.width), height: tallHeight), CGSize(width: floorToScreenPixels(0.58 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.73 * size.width), height: tallHeight), CGSize(width: floorToScreenPixels(0.69 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.47 * size.width), height: tallHeight), CGSize(width: floorToScreenPixels(0.47 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.57 * size.width), height: tallHeight), CGSize(width: floorToScreenPixels(0.58 * size.width), height: shortHeight),
CGSize(width: floorToScreenPixels(0.36 * size.width), height: shortHeight),
CGSize(width: floorToScreenPixels(0.47 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.57 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.73 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.36 * size.width), height: tallHeight), CGSize(width: floorToScreenPixels(0.36 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.57 * size.width), height: shortHeight), CGSize(width: floorToScreenPixels(0.47 * size.width), height: tallHeight),
] CGSize(width: floorToScreenPixels(0.36 * size.width), height: shortHeight),
CGSize(width: floorToScreenPixels(0.58 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.69 * size.width), height: tallHeight),
CGSize(width: floorToScreenPixels(0.58 * size.width), height: tallHeight),
].map {
if self.chatType == .channel {
return CGSize(width: floor($0.width * 1.3), height: floor($0.height * 1.8))
} else {
return $0
}
}
var offset: CGFloat = 5.0 var offset: CGFloat = 5.0
var index = 0 var index = 0
// if let (insetCount, _) = self.bottomInset {
// index += insetCount
// }
for messageContainer in self.messageContainers { for messageContainer in self.messageContainers {
let messageSize = dimensions[index % 11] let messageSize = dimensions[index % 11]
messageContainer.update(size: bounds.size, hasAvatar: self.isGroup, rect: CGRect(origin: CGPoint(x: 0.0, y: bounds.size.height - insets.bottom - offset - messageSize.height), size: messageSize), transition: transition) messageContainer.update(size: bounds.size, hasAvatar: self.chatType != .channel, rect: CGRect(origin: CGPoint(x: 0.0, y: bounds.size.height - insets.bottom - offset - messageSize.height), size: messageSize), transition: transition)
offset += messageSize.height offset += messageSize.height
index += 1 index += 1
} }