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() {
|
||||
isShowingSearchUI = true
|
||||
// Search bar
|
||||
// FIXME: This code is duplicated with SearchBar
|
||||
let searchBar = searchController.uiSearchController.searchBar
|
||||
searchBar.searchBarStyle = .minimal
|
||||
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)
|
||||
searchBar.setUpSessionStyle()
|
||||
navigationItem.titleView = searchBar
|
||||
// Nav bar buttons
|
||||
updateNavBarButtons()
|
||||
|
|
|
@ -6,7 +6,11 @@ import SessionMessagingKit
|
|||
|
||||
@objc
|
||||
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 tableViewTopConstraint: NSLayoutConstraint!
|
||||
|
||||
|
@ -85,16 +89,13 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
|
|||
|
||||
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
|
||||
// the dataSource has the correct data)
|
||||
view.addSubview(tableView)
|
||||
view.addSubview(emptyStateLabel)
|
||||
view.addSubview(fadeView)
|
||||
view.addSubview(clearAllButton)
|
||||
setupLayout()
|
||||
|
||||
// Notifications
|
||||
NotificationCenter.default.addObserver(
|
||||
|
@ -116,18 +117,11 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
|
|||
object: nil
|
||||
)
|
||||
|
||||
// Threads (part 2)
|
||||
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()
|
||||
reload()
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
reload()
|
||||
}
|
||||
|
||||
|
@ -189,7 +183,6 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
|
|||
tableView.reloadData()
|
||||
clearAllButton.isHidden = (messageRequestCount == 0)
|
||||
emptyStateLabel.isHidden = (messageRequestCount != 0)
|
||||
emptyStateLabel.isHidden = (messageRequestCount != 0)
|
||||
}
|
||||
|
||||
@objc private func handleYapDatabaseModifiedNotification(_ yapDatabase: YapDatabase) {
|
||||
|
|
|
@ -4,18 +4,21 @@ public final class SearchBar : UISearchBar {
|
|||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setUpStyle()
|
||||
setUpSessionStyle()
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
setUpStyle()
|
||||
setUpSessionStyle()
|
||||
}
|
||||
|
||||
private func setUpStyle() {
|
||||
}
|
||||
|
||||
public extension UISearchBar {
|
||||
|
||||
func setUpSessionStyle() {
|
||||
searchBarStyle = .minimal // Hide the border around the search bar
|
||||
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)!
|
||||
setImage(searchImage, for: .search, state: .normal)
|
||||
let clearImage = #imageLiteral(resourceName: "searchbar_clear").withTint(Colors.searchBarPlaceholder)!
|
||||
|
|
Loading…
Reference in New Issue