diff --git a/iphone/Maps/Classes/Components/TabView/TabView.swift b/iphone/Maps/Classes/Components/TabView/TabView.swift index e13e7d404..3316b6802 100644 --- a/iphone/Maps/Classes/Components/TabView/TabView.swift +++ b/iphone/Maps/Classes/Components/TabView/TabView.swift @@ -19,6 +19,8 @@ fileprivate class ContentCell: UICollectionViewCell { fileprivate class HeaderCell: UICollectionViewCell { private let label = UILabel() + private var selectedAttributes: [NSAttributedString.Key : Any] = [:] + private var deselectedAttributes: [NSAttributedString.Key : Any] = [:] override init(frame: CGRect) { super.init(frame: frame) @@ -32,21 +34,31 @@ fileprivate class HeaderCell: UICollectionViewCell { label.textAlignment = .center } - var attributedText: NSAttributedString? { + override var isSelected: Bool { didSet { - label.attributedText = attributedText + label.attributedText = NSAttributedString(string: label.text ?? "", + attributes: isSelected ? selectedAttributes : deselectedAttributes) } } override func prepareForReuse() { super.prepareForReuse() - attributedText = nil + label.attributedText = nil } override func layoutSubviews() { super.layoutSubviews() 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 { @@ -88,7 +100,7 @@ class TabView: UIView { } } - var headerTextAttributes: [NSAttributedString.Key : Any] = [ + var selectedHeaderTextAttributes: [NSAttributedString.Key : Any] = [ .foregroundColor : UIColor.white, .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 { safeAreaLayoutGuide.layoutFrame } @@ -145,14 +166,10 @@ class TabView: UIView { 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.addSubview(tabsCollectionView) headerView.addSubview(slidingView) + headerView.addSeparator(.bottom) } private func configureContent() { @@ -235,7 +252,12 @@ extension TabView : UICollectionViewDataSource { cell = collectionView.dequeueReusableCell(withReuseIdentifier: CellId.header, for: indexPath) if let headerCell = cell as? HeaderCell { 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) { if (collectionView == tabsCollectionView) { - if selectedIndex != indexPath.item { + let isSelected = selectedIndex == indexPath.item + if !isSelected { selectedIndex = indexPath.item tabsContentCollectionView.scrollToItem(at: indexPath, at: .left, animated: true) 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, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { diff --git a/iphone/Maps/Core/Theme/GlobalStyleSheet.swift b/iphone/Maps/Core/Theme/GlobalStyleSheet.swift index b4ccdb595..bed3b22e5 100644 --- a/iphone/Maps/Core/Theme/GlobalStyleSheet.swift +++ b/iphone/Maps/Core/Theme/GlobalStyleSheet.swift @@ -4,6 +4,7 @@ enum GlobalStyleSheet: String, CaseIterable { case tableViewCell = "MWMTableViewCell" case defaultTableViewCell case tableViewHeaderFooterView = "TableViewHeaderFooterView" + case defaultSearchBar case searchBar = "SearchBar" case navigationBar = "NavigationBar" case navigationBarItem = "NavigationBarItem" @@ -95,6 +96,14 @@ extension GlobalStyleSheet: IStyleSheet { s.font = fonts.medium14 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: return .add { s in s.backgroundColor = colors.white @@ -224,10 +233,11 @@ extension GlobalStyleSheet: IStyleSheet { } case .tabView: return .add { s in - s.backgroundColor = colors.pressBackground - s.barTintColor = colors.primary - s.tintColor = colors.white - s.fontColor = colors.whitePrimaryText + s.backgroundColor = colors.white + s.barTintColor = colors.white + s.tintColor = colors.linkBlue + s.fontColor = colors.blackSecondaryText + s.fontColorHighlighted = colors.linkBlue s.font = fonts.medium14 } case .dialogView: diff --git a/iphone/Maps/Core/Theme/Renderers/TabViewRenderer.swift b/iphone/Maps/Core/Theme/Renderers/TabViewRenderer.swift index 5c1256a2a..34351260c 100644 --- a/iphone/Maps/Core/Theme/Renderers/TabViewRenderer.swift +++ b/iphone/Maps/Core/Theme/Renderers/TabViewRenderer.swift @@ -21,8 +21,12 @@ class TabViewRenderer { if let tintColor = style.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 { - control.headerTextAttributes = [.foregroundColor: fontColor, + control.deselectedHeaderTextAttributes = [.foregroundColor: fontColor, .font: font] } } diff --git a/iphone/Maps/Core/Theme/SearchStyleSheet.swift b/iphone/Maps/Core/Theme/SearchStyleSheet.swift index 2d448e307..0b4ec7c20 100644 --- a/iphone/Maps/Core/Theme/SearchStyleSheet.swift +++ b/iphone/Maps/Core/Theme/SearchStyleSheet.swift @@ -18,8 +18,8 @@ extension SearchStyleSheet: IStyleSheet { } case .searchCancelButton: return .add { s in - s.fontColor = colors.whitePrimaryText - s.fontColorHighlighted = colors.whitePrimaryTextHighlighted + s.fontColor = colors.linkBlue + s.fontColorHighlighted = colors.linkBlueHighlighted s.font = fonts.regular17 s.backgroundColor = .clear } diff --git a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapHeaderView.swift b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapHeaderView.swift index 46c931c70..5f006045b 100644 --- a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapHeaderView.swift +++ b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapHeaderView.swift @@ -24,6 +24,7 @@ final class SearchOnMapHeaderView: UIView { private let searchBar = UISearchBar() private let cancelButton = UIButton() private let cancelContainer = UIView() + private var separator: UIView? override init(frame: CGRect) { super.init(frame: frame) @@ -37,7 +38,7 @@ final class SearchOnMapHeaderView: UIView { } private func setupView() { - setStyle(.primaryBackground) + setStyle(.background) setupGrabberView() setupGrabberTapHandlerView() @@ -61,6 +62,7 @@ final class SearchOnMapHeaderView: UIView { } private func setupSearchBar() { + searchBar.setStyle(.defaultSearchBar) searchBar.placeholder = L("search") searchBar.showsCancelButton = false if #available(iOS 13.0, *) { @@ -71,7 +73,7 @@ final class SearchOnMapHeaderView: UIView { } private func setupCancelButton() { - cancelContainer.setStyle(.primaryBackground) + cancelContainer.setStyle(.background) cancelButton.setStyle(.searchCancelButton) cancelButton.setTitle(L("cancel"), for: .normal) cancelButton.addTarget(self, action: #selector(cancelButtonDidTap), for: .touchUpInside) @@ -83,6 +85,7 @@ final class SearchOnMapHeaderView: UIView { addSubview(searchBar) addSubview(cancelContainer) cancelContainer.addSubview(cancelButton) + separator = addSeparator(.bottom) grabberView.translatesAutoresizingMaskIntoConstraints = false grabberTapHandlerView.translatesAutoresizingMaskIntoConstraints = false @@ -142,4 +145,8 @@ final class SearchOnMapHeaderView: UIView { var searchQuery: SearchQuery { SearchQuery(searchBar.text ?? "", locale: searchBar.textInputMode?.primaryLanguage, source: .typedText) } + + func setSeparatorHidden(_ hidden: Bool) { + separator?.isHidden = hidden + } } diff --git a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift index 8c7cc57a2..f524f2d61 100644 --- a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift +++ b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift @@ -167,8 +167,8 @@ final class SearchOnMapViewController: UIViewController { } view.addSubview(availableAreaView) availableAreaView.addSubview(contentView) - contentView.addSubview(headerView) contentView.addSubview(searchResultsView) + contentView.addSubview(headerView) contentView.translatesAutoresizingMaskIntoConstraints = false headerView.translatesAutoresizingMaskIntoConstraints = false @@ -309,6 +309,7 @@ final class SearchOnMapViewController: UIViewController { case .searching: break } + headerView.setSeparatorHidden(content == .historyAndCategory) showView(viewToShow(for: content)) }