mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Attachment menu improvements
This commit is contained in:
@@ -11,6 +11,7 @@ import AccountContext
|
||||
import ContactListUI
|
||||
import SearchUI
|
||||
import AttachmentUI
|
||||
import SearchBarNode
|
||||
|
||||
class ContactSelectionControllerImpl: ViewController, ContactSelectionController, PresentableController, AttachmentContainable {
|
||||
private let context: AccountContext
|
||||
@@ -56,7 +57,7 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
private var presentationData: PresentationData
|
||||
private var presentationDataDisposable: Disposable?
|
||||
|
||||
private var searchContentNode: NavigationBarSearchContentNode?
|
||||
private var searchContentNode: NavigationBarContentNode?
|
||||
|
||||
var displayNavigationActivity: Bool = false {
|
||||
didSet {
|
||||
@@ -98,10 +99,10 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
|
||||
self.scrollToTop = { [weak self] in
|
||||
if let strongSelf = self {
|
||||
if let searchContentNode = strongSelf.searchContentNode {
|
||||
if let searchContentNode = strongSelf.searchContentNode as? NavigationBarSearchContentNode {
|
||||
searchContentNode.updateExpansionProgress(1.0, animated: true)
|
||||
}
|
||||
strongSelf.contactsNode.contactListNode.scrollToTop()
|
||||
strongSelf.contactsNode.scrollToTop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
}
|
||||
|
||||
if params.multipleSelection {
|
||||
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Select, style: .plain, target: self, action: #selector(self.beginSelection))
|
||||
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: PresentationResourcesRootController.navigationCompactSearchIcon(self.presentationData.theme), style: .plain, target: self, action: #selector(self.beginSearch))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +141,11 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
self.presentationDataDisposable?.dispose()
|
||||
}
|
||||
|
||||
@objc private func beginSearch() {
|
||||
self.requestAttachmentMenuExpansion()
|
||||
self.activateSearch()
|
||||
}
|
||||
|
||||
@objc private func beginSelection() {
|
||||
self.navigationItem.rightBarButtonItem = nil
|
||||
self.contactsNode.beginSelection()
|
||||
@@ -148,7 +154,7 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
private func updateThemeAndStrings() {
|
||||
self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBarStyle.style
|
||||
self.navigationBar?.updatePresentationData(NavigationBarPresentationData(presentationData: self.presentationData))
|
||||
self.searchContentNode?.updateThemeAndPlaceholder(theme: self.presentationData.theme, placeholder: self.presentationData.strings.Common_Search)
|
||||
(self.searchContentNode as? NavigationBarSearchContentNode)?.updateThemeAndPlaceholder(theme: self.presentationData.theme, placeholder: self.presentationData.strings.Common_Search)
|
||||
self.title = self.titleProducer(self.presentationData.strings)
|
||||
self.tabBarItem.title = self.presentationData.strings.Contacts_Title
|
||||
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Back, style: .plain, target: nil, action: nil)
|
||||
@@ -196,13 +202,13 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
}
|
||||
|
||||
self.contactsNode.contactListNode.contentOffsetChanged = { [weak self] offset in
|
||||
if let strongSelf = self, let searchContentNode = strongSelf.searchContentNode {
|
||||
if let strongSelf = self, let searchContentNode = strongSelf.searchContentNode as? NavigationBarSearchContentNode {
|
||||
searchContentNode.updateListVisibleContentOffset(offset)
|
||||
}
|
||||
}
|
||||
|
||||
self.contactsNode.contactListNode.contentScrollingEnded = { [weak self] listView in
|
||||
if let strongSelf = self, let searchContentNode = strongSelf.searchContentNode {
|
||||
if let strongSelf = self, let searchContentNode = strongSelf.searchContentNode as? NavigationBarSearchContentNode {
|
||||
return fixNavigationSearchableListNodeScrolling(listView, searchNode: searchContentNode)
|
||||
} else {
|
||||
return false
|
||||
@@ -268,10 +274,27 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
|
||||
private func activateSearch() {
|
||||
if self.displayNavigationBar {
|
||||
if let searchContentNode = self.searchContentNode {
|
||||
if let searchContentNode = self.searchContentNode as? NavigationBarSearchContentNode {
|
||||
self.contactsNode.activateSearch(placeholderNode: searchContentNode.placeholderNode)
|
||||
self.setDisplayNavigationBar(false, transition: .animated(duration: 0.5, curve: .spring))
|
||||
} else if self.multipleSelection {
|
||||
let contentNode = ContactsSearchNavigationContentNode(presentationData: self.presentationData, dismissSearch: { [weak self] in
|
||||
if let strongSelf = self, let navigationBar = strongSelf.navigationBar, let searchContentNode = strongSelf.searchContentNode as? ContactsSearchNavigationContentNode {
|
||||
searchContentNode.deactivate()
|
||||
strongSelf.searchContentNode = nil
|
||||
navigationBar.setContentNode(nil, animated: true)
|
||||
strongSelf.contactsNode.deactivateOverlaySearch()
|
||||
}
|
||||
}, updateSearchQuery: { [weak self] query in
|
||||
if let strongSelf = self {
|
||||
strongSelf.contactsNode.searchContainerNode?.searchTextUpdated(text: query)
|
||||
}
|
||||
})
|
||||
self.searchContentNode = contentNode
|
||||
self.navigationBar?.setContentNode(contentNode, animated: true)
|
||||
self.contactsNode.activateOverlaySearch()
|
||||
contentNode.activate()
|
||||
}
|
||||
self.setDisplayNavigationBar(false, transition: .animated(duration: 0.5, curve: .spring))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +302,7 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
if !self.displayNavigationBar {
|
||||
self.contactsNode.prepareDeactivateSearch()
|
||||
self.setDisplayNavigationBar(true, transition: .animated(duration: 0.5, curve: .spring))
|
||||
if let searchContentNode = self.searchContentNode {
|
||||
if let searchContentNode = self.searchContentNode as? NavigationBarSearchContentNode {
|
||||
self.contactsNode.deactivateSearch(placeholderNode: searchContentNode.placeholderNode)
|
||||
}
|
||||
}
|
||||
@@ -303,3 +326,57 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController
|
||||
self.deactivateSearch()
|
||||
}
|
||||
}
|
||||
|
||||
private let searchBarFont = Font.regular(17.0)
|
||||
|
||||
final class ContactsSearchNavigationContentNode: NavigationBarContentNode {
|
||||
private var presentationData: PresentationData
|
||||
|
||||
private let searchBar: SearchBarNode
|
||||
|
||||
init(presentationData: PresentationData, dismissSearch: @escaping () -> Void, updateSearchQuery: @escaping (String) -> Void) {
|
||||
self.presentationData = presentationData
|
||||
|
||||
self.searchBar = SearchBarNode(theme: SearchBarNodeTheme(theme: presentationData.theme, hasSeparator: false), strings: presentationData.strings, fieldStyle: .modern)
|
||||
self.searchBar.placeholderString = NSAttributedString(string: presentationData.strings.Common_Search, font: searchBarFont, textColor: presentationData.theme.rootController.navigationSearchBar.inputPlaceholderTextColor)
|
||||
|
||||
super.init()
|
||||
|
||||
self.addSubnode(self.searchBar)
|
||||
|
||||
self.searchBar.cancel = { [weak self] in
|
||||
self?.searchBar.deactivate(clear: false)
|
||||
dismissSearch()
|
||||
}
|
||||
self.searchBar.textUpdated = { query, _ in
|
||||
updateSearchQuery(query)
|
||||
}
|
||||
}
|
||||
|
||||
override var nominalHeight: CGFloat {
|
||||
return 56.0
|
||||
}
|
||||
|
||||
override func updateLayout(size: CGSize, leftInset: CGFloat, rightInset: CGFloat, transition: ContainedViewLayoutTransition) {
|
||||
let searchBarFrame = CGRect(origin: CGPoint(x: 0.0, y: size.height - self.nominalHeight), size: CGSize(width: size.width, height: 56.0))
|
||||
self.searchBar.frame = searchBarFrame
|
||||
self.searchBar.updateLayout(boundingSize: searchBarFrame.size, leftInset: leftInset, rightInset: rightInset, transition: transition)
|
||||
}
|
||||
|
||||
func activate() {
|
||||
self.searchBar.activate()
|
||||
}
|
||||
|
||||
func deactivate() {
|
||||
self.searchBar.deactivate(clear: false)
|
||||
}
|
||||
|
||||
func updateActivity(_ activity: Bool) {
|
||||
self.searchBar.activity = activity
|
||||
}
|
||||
|
||||
func updatePresentationData(_ presentationData: PresentationData) {
|
||||
self.presentationData = presentationData
|
||||
self.searchBar.updateThemeAndStrings(theme: SearchBarNodeTheme(theme: presentationData.theme, hasSeparator: false), strings: presentationData.strings)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user