mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Contacts sort selector Bot button icons tg://msg scheme support Calculate service message color using current wallpaper Various fixes
176 lines
7.5 KiB
Swift
176 lines
7.5 KiB
Swift
import Display
|
|
import AsyncDisplayKit
|
|
import UIKit
|
|
import Postbox
|
|
import TelegramCore
|
|
import SwiftSignalKit
|
|
|
|
final class ContactSelectionControllerNode: ASDisplayNode {
|
|
var displayProgress: Bool = false {
|
|
didSet {
|
|
if self.displayProgress != oldValue {
|
|
self.dimNode.alpha = self.displayProgress ? 1.0 : 0.0
|
|
self.dimNode.isUserInteractionEnabled = self.displayProgress
|
|
}
|
|
}
|
|
}
|
|
|
|
let displayDeviceContacts: Bool
|
|
|
|
let contactListNode: ContactListNode
|
|
private let dimNode: ASDisplayNode
|
|
|
|
private let account: Account
|
|
private var searchDisplayController: SearchDisplayController?
|
|
|
|
private var containerLayout: (ContainerViewLayout, CGFloat)?
|
|
|
|
var navigationBar: NavigationBar?
|
|
|
|
var requestDeactivateSearch: (() -> Void)?
|
|
var requestOpenPeerFromSearch: ((ContactListPeer) -> Void)?
|
|
var dismiss: (() -> Void)?
|
|
|
|
var presentationData: PresentationData
|
|
var presentationDataDisposable: Disposable?
|
|
|
|
init(account: Account, options: [ContactListAdditionalOption], displayDeviceContacts: Bool) {
|
|
self.account = account
|
|
self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
|
|
self.displayDeviceContacts = displayDeviceContacts
|
|
|
|
self.contactListNode = ContactListNode(account: account, presentation: .single(.natural(displaySearch: true, options: options)))
|
|
|
|
self.dimNode = ASDisplayNode()
|
|
|
|
super.init()
|
|
|
|
self.setViewBlock({
|
|
return UITracingLayerView()
|
|
})
|
|
|
|
self.backgroundColor = self.presentationData.theme.chatList.backgroundColor
|
|
|
|
self.addSubnode(self.contactListNode)
|
|
|
|
self.presentationDataDisposable = (account.telegramApplicationContext.presentationData
|
|
|> deliverOnMainQueue).start(next: { [weak self] presentationData in
|
|
if let strongSelf = self {
|
|
let previousTheme = strongSelf.presentationData.theme
|
|
strongSelf.presentationData = presentationData
|
|
if previousTheme !== presentationData.theme {
|
|
strongSelf.updateTheme()
|
|
}
|
|
}
|
|
})
|
|
|
|
self.dimNode.backgroundColor = self.presentationData.theme.list.plainBackgroundColor.withAlphaComponent(0.5)
|
|
self.dimNode.alpha = 0.0
|
|
self.dimNode.isUserInteractionEnabled = false
|
|
self.addSubnode(self.dimNode)
|
|
}
|
|
|
|
deinit {
|
|
self.presentationDataDisposable?.dispose()
|
|
}
|
|
|
|
private func updateTheme() {
|
|
self.backgroundColor = self.presentationData.theme.chatList.backgroundColor
|
|
self.searchDisplayController?.updateThemeAndStrings(theme: self.presentationData.theme, strings: self.presentationData.strings)
|
|
self.dimNode.backgroundColor = self.presentationData.theme.list.plainBackgroundColor.withAlphaComponent(0.5)
|
|
}
|
|
|
|
func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {
|
|
self.containerLayout = (layout, navigationBarHeight)
|
|
|
|
transition.updateFrame(node: self.dimNode, frame: CGRect(origin: CGPoint(), size: layout.size))
|
|
|
|
var insets = layout.insets(options: [.input])
|
|
insets.top += navigationBarHeight
|
|
|
|
if let searchDisplayController = self.searchDisplayController {
|
|
searchDisplayController.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition)
|
|
if !searchDisplayController.isDeactivating {
|
|
insets.top += layout.statusBarHeight ?? 0.0
|
|
}
|
|
}
|
|
|
|
self.contactListNode.containerLayoutUpdated(ContainerViewLayout(size: layout.size, metrics: layout.metrics, intrinsicInsets: insets, safeInsets: layout.safeInsets, statusBarHeight: layout.statusBarHeight, inputHeight: layout.inputHeight, standardInputHeight: layout.standardInputHeight, inputHeightIsInteractivellyChanging: layout.inputHeightIsInteractivellyChanging), transition: transition)
|
|
|
|
self.contactListNode.frame = CGRect(origin: CGPoint(), size: layout.size)
|
|
|
|
if let searchDisplayController = self.searchDisplayController {
|
|
searchDisplayController.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition)
|
|
}
|
|
}
|
|
|
|
func activateSearch() {
|
|
guard let (containerLayout, navigationBarHeight) = self.containerLayout, let navigationBar = self.navigationBar else {
|
|
return
|
|
}
|
|
|
|
var maybePlaceholderNode: SearchBarPlaceholderNode?
|
|
self.contactListNode.listNode.forEachItemNode { node in
|
|
if let node = node as? ChatListSearchItemNode {
|
|
maybePlaceholderNode = node.searchBarNode
|
|
}
|
|
}
|
|
|
|
if let _ = self.searchDisplayController {
|
|
return
|
|
}
|
|
|
|
if let placeholderNode = maybePlaceholderNode {
|
|
var categories: ContactsSearchCategories = [.cloudContacts]
|
|
if self.displayDeviceContacts {
|
|
categories.insert(.deviceContacts)
|
|
} else {
|
|
categories.insert(.global)
|
|
}
|
|
self.searchDisplayController = SearchDisplayController(theme: self.presentationData.theme, strings: self.presentationData.strings, contentNode: ContactsSearchContainerNode(account: self.account, onlyWriteable: false, categories: categories, openPeer: { [weak self] peer in
|
|
self?.requestOpenPeerFromSearch?(peer)
|
|
}), cancel: { [weak self] in
|
|
if let requestDeactivateSearch = self?.requestDeactivateSearch {
|
|
requestDeactivateSearch()
|
|
}
|
|
})
|
|
|
|
self.searchDisplayController?.containerLayoutUpdated(containerLayout, navigationBarHeight: navigationBarHeight, transition: .immediate)
|
|
self.searchDisplayController?.activate(insertSubnode: { subnode in
|
|
self.insertSubnode(subnode, belowSubnode: self.dimNode)
|
|
}, placeholder: placeholderNode)
|
|
}
|
|
}
|
|
|
|
func prepareDeactivateSearch() {
|
|
self.searchDisplayController?.isDeactivating = true
|
|
}
|
|
|
|
func deactivateSearch() {
|
|
if let searchDisplayController = self.searchDisplayController {
|
|
var maybePlaceholderNode: SearchBarPlaceholderNode?
|
|
self.contactListNode.listNode.forEachItemNode { node in
|
|
if let node = node as? ChatListSearchItemNode {
|
|
maybePlaceholderNode = node.searchBarNode
|
|
}
|
|
}
|
|
|
|
searchDisplayController.deactivate(placeholder: maybePlaceholderNode)
|
|
self.searchDisplayController = nil
|
|
}
|
|
}
|
|
|
|
func animateIn() {
|
|
self.layer.animatePosition(from: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), to: self.layer.position, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring)
|
|
}
|
|
|
|
func animateOut(completion: (() -> Void)? = nil) {
|
|
self.layer.animatePosition(from: self.layer.position, to: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), duration: 0.2, timingFunction: kCAMediaTimingFunctionEaseInEaseOut, removeOnCompletion: false, completion: { [weak self] _ in
|
|
if let strongSelf = self {
|
|
strongSelf.dismiss?()
|
|
}
|
|
completion?()
|
|
})
|
|
}
|
|
}
|