minor refactor in search bar & message request vc
This commit is contained in:
parent
ccae9141ff
commit
78e2c4f55c
|
@ -820,28 +820,8 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
||||||
func showSearchUI() {
|
func showSearchUI() {
|
||||||
isShowingSearchUI = true
|
isShowingSearchUI = true
|
||||||
// Search bar
|
// Search bar
|
||||||
// FIXME: This code is duplicated with SearchBar
|
|
||||||
let searchBar = searchController.uiSearchController.searchBar
|
let searchBar = searchController.uiSearchController.searchBar
|
||||||
searchBar.searchBarStyle = .minimal
|
searchBar.setUpSessionStyle()
|
||||||
searchBar.barStyle = .black
|
|
||||||
searchBar.tintColor = Colors.text
|
|
||||||
let searchIcon = UIImage(named: "searchbar_search")!.asTintedImage(color: Colors.searchBarPlaceholder)
|
|
||||||
searchBar.setImage(searchIcon, for: .search, state: UIControl.State.normal)
|
|
||||||
let clearIcon = UIImage(named: "searchbar_clear")!.asTintedImage(color: Colors.searchBarPlaceholder)
|
|
||||||
searchBar.setImage(clearIcon, for: .clear, state: UIControl.State.normal)
|
|
||||||
let searchTextField: UITextField
|
|
||||||
if #available(iOS 13, *) {
|
|
||||||
searchTextField = searchBar.searchTextField
|
|
||||||
} else {
|
|
||||||
searchTextField = searchBar.value(forKey: "_searchField") as! UITextField
|
|
||||||
}
|
|
||||||
searchTextField.backgroundColor = Colors.searchBarBackground
|
|
||||||
searchTextField.textColor = Colors.text
|
|
||||||
searchTextField.attributedPlaceholder = NSAttributedString(string: "Search", attributes: [ .foregroundColor : Colors.searchBarPlaceholder ])
|
|
||||||
searchTextField.keyboardAppearance = isLightMode ? .default : .dark
|
|
||||||
searchBar.setPositionAdjustment(UIOffset(horizontal: 4, vertical: 0), for: .search)
|
|
||||||
searchBar.searchTextPositionAdjustment = UIOffset(horizontal: 2, vertical: 0)
|
|
||||||
searchBar.setPositionAdjustment(UIOffset(horizontal: -4, vertical: 0), for: .clear)
|
|
||||||
navigationItem.titleView = searchBar
|
navigationItem.titleView = searchBar
|
||||||
// Nav bar buttons
|
// Nav bar buttons
|
||||||
updateNavBarButtons()
|
updateNavBarButtons()
|
||||||
|
|
|
@ -6,7 +6,11 @@ import SessionMessagingKit
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDataSource {
|
class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDataSource {
|
||||||
private var threads: YapDatabaseViewMappings!
|
private var threads: YapDatabaseViewMappings! = {
|
||||||
|
let result = YapDatabaseViewMappings(groups: [ TSMessageRequestGroup ], view: TSThreadDatabaseViewExtensionName)
|
||||||
|
result.setIsReversed(true, forGroup: TSMessageRequestGroup)
|
||||||
|
return result
|
||||||
|
}()
|
||||||
private var threadViewModelCache: [String: ThreadViewModel] = [:] // Thread ID to ThreadViewModel
|
private var threadViewModelCache: [String: ThreadViewModel] = [:] // Thread ID to ThreadViewModel
|
||||||
private var tableViewTopConstraint: NSLayoutConstraint!
|
private var tableViewTopConstraint: NSLayoutConstraint!
|
||||||
|
|
||||||
|
@ -85,16 +89,13 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
|
||||||
|
|
||||||
ViewControllerUtilities.setUpDefaultSessionStyle(for: self, title: NSLocalizedString("MESSAGE_REQUESTS_TITLE", comment: ""), hasCustomBackButton: false)
|
ViewControllerUtilities.setUpDefaultSessionStyle(for: self, title: NSLocalizedString("MESSAGE_REQUESTS_TITLE", comment: ""), hasCustomBackButton: false)
|
||||||
|
|
||||||
// Threads (part 1)
|
|
||||||
// Freeze the connection for use on the main thread (this gives us a stable data source that doesn't change until we tell it to)
|
|
||||||
dbConnection.beginLongLivedReadTransaction()
|
|
||||||
|
|
||||||
// Add the UI (MUST be done after the thread freeze so the 'tableView' creation and setting
|
// Add the UI (MUST be done after the thread freeze so the 'tableView' creation and setting
|
||||||
// the dataSource has the correct data)
|
// the dataSource has the correct data)
|
||||||
view.addSubview(tableView)
|
view.addSubview(tableView)
|
||||||
view.addSubview(emptyStateLabel)
|
view.addSubview(emptyStateLabel)
|
||||||
view.addSubview(fadeView)
|
view.addSubview(fadeView)
|
||||||
view.addSubview(clearAllButton)
|
view.addSubview(clearAllButton)
|
||||||
|
setupLayout()
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
NotificationCenter.default.addObserver(
|
NotificationCenter.default.addObserver(
|
||||||
|
@ -116,18 +117,11 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
|
||||||
object: nil
|
object: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
// Threads (part 2)
|
reload()
|
||||||
threads = YapDatabaseViewMappings(groups: [ TSMessageRequestGroup ], view: TSThreadDatabaseViewExtensionName) // The extension should be registered at this point
|
|
||||||
dbConnection.read { transaction in
|
|
||||||
self.threads.update(with: transaction) // Perform the initial update
|
|
||||||
}
|
|
||||||
|
|
||||||
setupLayout()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +183,6 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
clearAllButton.isHidden = (messageRequestCount == 0)
|
clearAllButton.isHidden = (messageRequestCount == 0)
|
||||||
emptyStateLabel.isHidden = (messageRequestCount != 0)
|
emptyStateLabel.isHidden = (messageRequestCount != 0)
|
||||||
emptyStateLabel.isHidden = (messageRequestCount != 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func handleYapDatabaseModifiedNotification(_ yapDatabase: YapDatabase) {
|
@objc private func handleYapDatabaseModifiedNotification(_ yapDatabase: YapDatabase) {
|
||||||
|
|
|
@ -4,18 +4,21 @@ public final class SearchBar : UISearchBar {
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
setUpStyle()
|
setUpSessionStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
setUpStyle()
|
setUpSessionStyle()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private func setUpStyle() {
|
|
||||||
|
public extension UISearchBar {
|
||||||
|
|
||||||
|
func setUpSessionStyle() {
|
||||||
searchBarStyle = .minimal // Hide the border around the search bar
|
searchBarStyle = .minimal // Hide the border around the search bar
|
||||||
barStyle = .black // Use Apple's black design as a base
|
barStyle = .black // Use Apple's black design as a base
|
||||||
tintColor = Colors.accent // The cursor color
|
tintColor = Colors.text // The cursor color
|
||||||
let searchImage = #imageLiteral(resourceName: "searchbar_search").withTint(Colors.searchBarPlaceholder)!
|
let searchImage = #imageLiteral(resourceName: "searchbar_search").withTint(Colors.searchBarPlaceholder)!
|
||||||
setImage(searchImage, for: .search, state: .normal)
|
setImage(searchImage, for: .search, state: .normal)
|
||||||
let clearImage = #imageLiteral(resourceName: "searchbar_clear").withTint(Colors.searchBarPlaceholder)!
|
let clearImage = #imageLiteral(resourceName: "searchbar_clear").withTint(Colors.searchBarPlaceholder)!
|
||||||
|
|
Loading…
Reference in New Issue