[ios] remove primary green background from the search screen header

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn
2025-05-19 17:22:42 +04:00
committed by Konstantin Pastbin
parent 2299de287f
commit 7be49ab00a
6 changed files with 72 additions and 21 deletions

View File

@@ -19,6 +19,8 @@ fileprivate class ContentCell: UICollectionViewCell {
fileprivate class HeaderCell: UICollectionViewCell { fileprivate class HeaderCell: UICollectionViewCell {
private let label = UILabel() private let label = UILabel()
private var selectedAttributes: [NSAttributedString.Key : Any] = [:]
private var deselectedAttributes: [NSAttributedString.Key : Any] = [:]
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
@@ -32,21 +34,31 @@ fileprivate class HeaderCell: UICollectionViewCell {
label.textAlignment = .center label.textAlignment = .center
} }
var attributedText: NSAttributedString? { override var isSelected: Bool {
didSet { didSet {
label.attributedText = attributedText label.attributedText = NSAttributedString(string: label.text ?? "",
attributes: isSelected ? selectedAttributes : deselectedAttributes)
} }
} }
override func prepareForReuse() { override func prepareForReuse() {
super.prepareForReuse() super.prepareForReuse()
attributedText = nil label.attributedText = nil
} }
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
label.frame = contentView.bounds label.frame = contentView.bounds
} }
func configureWith(selectedAttributes: [NSAttributedString.Key : Any],
deselectedAttributes: [NSAttributedString.Key : Any],
text: String) {
self.selectedAttributes = selectedAttributes
self.deselectedAttributes = deselectedAttributes
label.attributedText = NSAttributedString(string: text.uppercased(),
attributes: deselectedAttributes)
}
} }
protocol TabViewDataSource: AnyObject { protocol TabViewDataSource: AnyObject {
@@ -88,7 +100,7 @@ class TabView: UIView {
} }
} }
var headerTextAttributes: [NSAttributedString.Key : Any] = [ var selectedHeaderTextAttributes: [NSAttributedString.Key : Any] = [
.foregroundColor : UIColor.white, .foregroundColor : UIColor.white,
.font : UIFont.systemFont(ofSize: 14, weight: .semibold) .font : UIFont.systemFont(ofSize: 14, weight: .semibold)
] { ] {
@@ -97,6 +109,15 @@ class TabView: UIView {
} }
} }
var deselectedHeaderTextAttributes: [NSAttributedString.Key : Any] = [
.foregroundColor : UIColor.gray,
.font : UIFont.systemFont(ofSize: 14, weight: .semibold)
] {
didSet {
tabsCollectionView.reloadData()
}
}
var contentFrame: CGRect { var contentFrame: CGRect {
safeAreaLayoutGuide.layoutFrame safeAreaLayoutGuide.layoutFrame
} }
@@ -145,14 +166,10 @@ class TabView: UIView {
slidingView.backgroundColor = tintColor slidingView.backgroundColor = tintColor
headerView.layer.shadowOffset = CGSize(width: 0, height: 2)
headerView.layer.shadowColor = UIColor(white: 0, alpha: 1).cgColor
headerView.layer.shadowOpacity = 0.12
headerView.layer.shadowRadius = 2
headerView.layer.masksToBounds = false
headerView.backgroundColor = barTintColor headerView.backgroundColor = barTintColor
headerView.addSubview(tabsCollectionView) headerView.addSubview(tabsCollectionView)
headerView.addSubview(slidingView) headerView.addSubview(slidingView)
headerView.addSeparator(.bottom)
} }
private func configureContent() { private func configureContent() {
@@ -235,7 +252,12 @@ extension TabView : UICollectionViewDataSource {
cell = collectionView.dequeueReusableCell(withReuseIdentifier: CellId.header, for: indexPath) cell = collectionView.dequeueReusableCell(withReuseIdentifier: CellId.header, for: indexPath)
if let headerCell = cell as? HeaderCell { if let headerCell = cell as? HeaderCell {
let title = dataSource?.tabView(self, titleAt: indexPath.item) ?? "" let title = dataSource?.tabView(self, titleAt: indexPath.item) ?? ""
headerCell.attributedText = NSAttributedString(string: title.uppercased(), attributes: headerTextAttributes) headerCell.configureWith(selectedAttributes: selectedHeaderTextAttributes,
deselectedAttributes: deselectedHeaderTextAttributes,
text: title)
if indexPath.item == selectedIndex {
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: [])
}
} }
} }
@@ -264,7 +286,8 @@ extension TabView : UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if (collectionView == tabsCollectionView) { if (collectionView == tabsCollectionView) {
if selectedIndex != indexPath.item { let isSelected = selectedIndex == indexPath.item
if !isSelected {
selectedIndex = indexPath.item selectedIndex = indexPath.item
tabsContentCollectionView.scrollToItem(at: indexPath, at: .left, animated: true) tabsContentCollectionView.scrollToItem(at: indexPath, at: .left, animated: true)
delegate?.tabView(self, didSelectTabAt: selectedIndex!) delegate?.tabView(self, didSelectTabAt: selectedIndex!)
@@ -272,6 +295,12 @@ extension TabView : UICollectionViewDelegateFlowLayout {
} }
} }
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
if (collectionView == tabsCollectionView) {
collectionView.deselectItem(at: indexPath, animated: false)
}
}
func collectionView(_ collectionView: UICollectionView, func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout, layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize { sizeForItemAt indexPath: IndexPath) -> CGSize {

View File

@@ -4,6 +4,7 @@ enum GlobalStyleSheet: String, CaseIterable {
case tableViewCell = "MWMTableViewCell" case tableViewCell = "MWMTableViewCell"
case defaultTableViewCell case defaultTableViewCell
case tableViewHeaderFooterView = "TableViewHeaderFooterView" case tableViewHeaderFooterView = "TableViewHeaderFooterView"
case defaultSearchBar
case searchBar = "SearchBar" case searchBar = "SearchBar"
case navigationBar = "NavigationBar" case navigationBar = "NavigationBar"
case navigationBarItem = "NavigationBarItem" case navigationBarItem = "NavigationBarItem"
@@ -95,6 +96,14 @@ extension GlobalStyleSheet: IStyleSheet {
s.font = fonts.medium14 s.font = fonts.medium14
s.fontColor = colors.blackSecondaryText s.fontColor = colors.blackSecondaryText
} }
case .defaultSearchBar:
return .add { s in
s.backgroundColor = colors.pressBackground
s.barTintColor = colors.clear
s.fontColor = colors.blackPrimaryText
s.fontColorDetailed = UIColor.white
s.tintColor = colors.blackSecondaryText
}
case .searchBar: case .searchBar:
return .add { s in return .add { s in
s.backgroundColor = colors.white s.backgroundColor = colors.white
@@ -224,10 +233,11 @@ extension GlobalStyleSheet: IStyleSheet {
} }
case .tabView: case .tabView:
return .add { s in return .add { s in
s.backgroundColor = colors.pressBackground s.backgroundColor = colors.white
s.barTintColor = colors.primary s.barTintColor = colors.white
s.tintColor = colors.white s.tintColor = colors.linkBlue
s.fontColor = colors.whitePrimaryText s.fontColor = colors.blackSecondaryText
s.fontColorHighlighted = colors.linkBlue
s.font = fonts.medium14 s.font = fonts.medium14
} }
case .dialogView: case .dialogView:

View File

@@ -21,8 +21,12 @@ class TabViewRenderer {
if let tintColor = style.tintColor { if let tintColor = style.tintColor {
control.tintColor = tintColor control.tintColor = tintColor
} }
if let font = style.font, let fontColor = style.fontColorHighlighted {
control.selectedHeaderTextAttributes = [.foregroundColor: fontColor,
.font: font]
}
if let font = style.font, let fontColor = style.fontColor { if let font = style.font, let fontColor = style.fontColor {
control.headerTextAttributes = [.foregroundColor: fontColor, control.deselectedHeaderTextAttributes = [.foregroundColor: fontColor,
.font: font] .font: font]
} }
} }

View File

@@ -18,8 +18,8 @@ extension SearchStyleSheet: IStyleSheet {
} }
case .searchCancelButton: case .searchCancelButton:
return .add { s in return .add { s in
s.fontColor = colors.whitePrimaryText s.fontColor = colors.linkBlue
s.fontColorHighlighted = colors.whitePrimaryTextHighlighted s.fontColorHighlighted = colors.linkBlueHighlighted
s.font = fonts.regular17 s.font = fonts.regular17
s.backgroundColor = .clear s.backgroundColor = .clear
} }

View File

@@ -24,6 +24,7 @@ final class SearchOnMapHeaderView: UIView {
private let searchBar = UISearchBar() private let searchBar = UISearchBar()
private let cancelButton = UIButton() private let cancelButton = UIButton()
private let cancelContainer = UIView() private let cancelContainer = UIView()
private var separator: UIView?
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
@@ -37,7 +38,7 @@ final class SearchOnMapHeaderView: UIView {
} }
private func setupView() { private func setupView() {
setStyle(.primaryBackground) setStyle(.background)
setupGrabberView() setupGrabberView()
setupGrabberTapHandlerView() setupGrabberTapHandlerView()
@@ -61,6 +62,7 @@ final class SearchOnMapHeaderView: UIView {
} }
private func setupSearchBar() { private func setupSearchBar() {
searchBar.setStyle(.defaultSearchBar)
searchBar.placeholder = L("search") searchBar.placeholder = L("search")
searchBar.showsCancelButton = false searchBar.showsCancelButton = false
if #available(iOS 13.0, *) { if #available(iOS 13.0, *) {
@@ -71,7 +73,7 @@ final class SearchOnMapHeaderView: UIView {
} }
private func setupCancelButton() { private func setupCancelButton() {
cancelContainer.setStyle(.primaryBackground) cancelContainer.setStyle(.background)
cancelButton.setStyle(.searchCancelButton) cancelButton.setStyle(.searchCancelButton)
cancelButton.setTitle(L("cancel"), for: .normal) cancelButton.setTitle(L("cancel"), for: .normal)
cancelButton.addTarget(self, action: #selector(cancelButtonDidTap), for: .touchUpInside) cancelButton.addTarget(self, action: #selector(cancelButtonDidTap), for: .touchUpInside)
@@ -83,6 +85,7 @@ final class SearchOnMapHeaderView: UIView {
addSubview(searchBar) addSubview(searchBar)
addSubview(cancelContainer) addSubview(cancelContainer)
cancelContainer.addSubview(cancelButton) cancelContainer.addSubview(cancelButton)
separator = addSeparator(.bottom)
grabberView.translatesAutoresizingMaskIntoConstraints = false grabberView.translatesAutoresizingMaskIntoConstraints = false
grabberTapHandlerView.translatesAutoresizingMaskIntoConstraints = false grabberTapHandlerView.translatesAutoresizingMaskIntoConstraints = false
@@ -142,4 +145,8 @@ final class SearchOnMapHeaderView: UIView {
var searchQuery: SearchQuery { var searchQuery: SearchQuery {
SearchQuery(searchBar.text ?? "", locale: searchBar.textInputMode?.primaryLanguage, source: .typedText) SearchQuery(searchBar.text ?? "", locale: searchBar.textInputMode?.primaryLanguage, source: .typedText)
} }
func setSeparatorHidden(_ hidden: Bool) {
separator?.isHidden = hidden
}
} }

View File

@@ -167,8 +167,8 @@ final class SearchOnMapViewController: UIViewController {
} }
view.addSubview(availableAreaView) view.addSubview(availableAreaView)
availableAreaView.addSubview(contentView) availableAreaView.addSubview(contentView)
contentView.addSubview(headerView)
contentView.addSubview(searchResultsView) contentView.addSubview(searchResultsView)
contentView.addSubview(headerView)
contentView.translatesAutoresizingMaskIntoConstraints = false contentView.translatesAutoresizingMaskIntoConstraints = false
headerView.translatesAutoresizingMaskIntoConstraints = false headerView.translatesAutoresizingMaskIntoConstraints = false
@@ -309,6 +309,7 @@ final class SearchOnMapViewController: UIViewController {
case .searching: case .searching:
break break
} }
headerView.setSeparatorHidden(content == .historyAndCategory)
showView(viewToShow(for: content)) showView(viewToShow(for: content))
} }