From b4aeaf26b3a45cd9734fe1b1cc379aefa355314e Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Tue, 12 Mar 2024 21:20:04 +0400 Subject: [PATCH] [ios] refactor Settings cells: use default properties instead of custom designed Signed-off-by: Kiryl Kaveryn --- .../Components/MWMTableViewController.m | 9 + .../Cells/SettingsTableViewLinkCell.swift | 21 +- .../SettingsTableViewSelectableCell.swift | 18 +- .../Cells/SettingsTableViewSwitchCell.swift | 33 +- .../UI/Settings/DrivingOptions.storyboard | 133 +-- iphone/Maps/UI/Storyboard/Settings.storyboard | 1047 ++++++----------- 6 files changed, 435 insertions(+), 826 deletions(-) diff --git a/iphone/Maps/Classes/Components/MWMTableViewController.m b/iphone/Maps/Classes/Components/MWMTableViewController.m index 86d6c42e07..5dce8e7712 100644 --- a/iphone/Maps/Classes/Components/MWMTableViewController.m +++ b/iphone/Maps/Classes/Components/MWMTableViewController.m @@ -5,6 +5,7 @@ #import "MWMTableViewController.h" #import "SwiftBridge.h" +static CGFloat const kMaxEstimatedTableViewCellHeight = 100.0; @interface MWMTableViewController () @@ -29,6 +30,14 @@ [self fixHeaderAndFooterFontsInDarkMode:view]; } +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return UITableViewAutomaticDimension; +} + +- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { + return kMaxEstimatedTableViewCellHeight; +} + // Fix table section header font color for all tables, including Setting and Route Options. - (void)fixHeaderAndFooterFontsInDarkMode:(UIView*)headerView { if ([headerView isKindOfClass: [UITableViewHeaderFooterView class]]) { diff --git a/iphone/Maps/UI/Settings/Cells/SettingsTableViewLinkCell.swift b/iphone/Maps/UI/Settings/Cells/SettingsTableViewLinkCell.swift index dbad461aad..48b9011fb4 100644 --- a/iphone/Maps/UI/Settings/Cells/SettingsTableViewLinkCell.swift +++ b/iphone/Maps/UI/Settings/Cells/SettingsTableViewLinkCell.swift @@ -1,19 +1,22 @@ @objc final class SettingsTableViewLinkCell: MWMTableViewCell { - @IBOutlet fileprivate weak var title: UILabel! - @IBOutlet fileprivate weak var info: UILabel? override func awakeFromNib() { super.awakeFromNib() - self.styleName = "Background" - self.title.styleName = "regular17:blackPrimaryText" - self.info?.styleName = "regular17:blackSecondaryText" + setupCell() + } + + private func setupCell() { + styleName = "Background" + textLabel?.styleName = "regular17:blackPrimaryText" + textLabel?.numberOfLines = 0 + textLabel?.lineBreakMode = .byWordWrapping + detailTextLabel?.styleName = "regular17:blackSecondaryText" } @objc func config(title: String, info: String?) { - self.title.text = title - - self.info?.text = info - self.info?.isHidden = info == nil + textLabel?.text = title + detailTextLabel?.text = info + detailTextLabel?.isHidden = info == nil } } diff --git a/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableCell.swift b/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableCell.swift index e9c52721e0..fff7a82c9a 100644 --- a/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableCell.swift +++ b/iphone/Maps/UI/Settings/Cells/SettingsTableViewSelectableCell.swift @@ -1,14 +1,24 @@ @objc final class SettingsTableViewSelectableCell: MWMTableViewCell { - @IBOutlet fileprivate weak var title: UILabel! override func awakeFromNib() { super.awakeFromNib() - self.styleName = "Background" - self.title.styleName = "regular17:blackPrimaryText" + setupCell() + } + + override func applyTheme() { + super.applyTheme() + textLabel?.applyTheme() + } + + private func setupCell() { + styleName = "Background" + textLabel?.styleName = "regular17:blackPrimaryText" + textLabel?.numberOfLines = 0 + textLabel?.lineBreakMode = .byWordWrapping } @objc func config(title: String) { - self.title.text = title + textLabel?.text = title } } diff --git a/iphone/Maps/UI/Settings/Cells/SettingsTableViewSwitchCell.swift b/iphone/Maps/UI/Settings/Cells/SettingsTableViewSwitchCell.swift index 5d5825aea9..552a405ece 100644 --- a/iphone/Maps/UI/Settings/Cells/SettingsTableViewSwitchCell.swift +++ b/iphone/Maps/UI/Settings/Cells/SettingsTableViewSwitchCell.swift @@ -5,12 +5,8 @@ protocol SettingsTableViewSwitchCellDelegate { @objc final class SettingsTableViewSwitchCell: MWMTableViewCell { - @IBOutlet fileprivate weak var title: UILabel! - @IBOutlet fileprivate weak var switchButton: UISwitch! { - didSet { - switchButton.addTarget(self, action: #selector(switchChanged), for: .valueChanged) - } - } + + private let switchButton = UISwitch() @IBOutlet weak var delegate: SettingsTableViewSwitchCellDelegate? @@ -30,26 +26,39 @@ final class SettingsTableViewSwitchCell: MWMTableViewCell { override func awakeFromNib() { super.awakeFromNib() - styleTitle() + setupCell() } - @objc func config(delegate: SettingsTableViewSwitchCellDelegate, title: String, isOn: Bool) { + @objc + func config(delegate: SettingsTableViewSwitchCellDelegate, title: String, isOn: Bool) { backgroundColor = UIColor.white() self.delegate = delegate - self.title.text = title + self.textLabel?.text = title styleTitle() switchButton.isOn = isOn } - @IBAction fileprivate func switchChanged() { + private func setupCell() { + styleName = "Background" + styleTitle() + textLabel?.numberOfLines = 0 + textLabel?.lineBreakMode = .byWordWrapping + + switchButton.onTintColor = UIColor.linkBlue() + switchButton.addTarget(self, action: #selector(switchChanged), for: .valueChanged) + accessoryView = switchButton + } + + @objc + private func switchChanged() { delegate?.switchCell(self, didChangeValue: switchButton.isOn) } - fileprivate func styleTitle() { + private func styleTitle() { let style = "regular17:" + (isEnabled ? "blackPrimaryText" : "blackSecondaryText") - title.setStyleAndApply(style) + textLabel?.setStyleAndApply(style) } } diff --git a/iphone/Maps/UI/Settings/DrivingOptions.storyboard b/iphone/Maps/UI/Settings/DrivingOptions.storyboard index 16e06ed0cf..6fcb30793e 100644 --- a/iphone/Maps/UI/Settings/DrivingOptions.storyboard +++ b/iphone/Maps/UI/Settings/DrivingOptions.storyboard @@ -1,169 +1,113 @@ - + - + - + - + - - + + - + - - - - - - - - - - - - + + - + - - - - - - - - - - - - + + - + - - - - - - - - - - - - + + - + - - - - - - - - - - @@ -186,4 +130,9 @@ + + + + + diff --git a/iphone/Maps/UI/Storyboard/Settings.storyboard b/iphone/Maps/UI/Storyboard/Settings.storyboard index 85c9fb3ba3..d8b4325f90 100644 --- a/iphone/Maps/UI/Storyboard/Settings.storyboard +++ b/iphone/Maps/UI/Storyboard/Settings.storyboard @@ -1,9 +1,9 @@ - + - + @@ -18,568 +18,363 @@ - + - + - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - @@ -633,89 +428,68 @@ - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - @@ -746,173 +520,131 @@ - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - @@ -944,99 +676,63 @@ - - + + - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - @@ -1063,29 +759,24 @@ - - + + - - - - - - - - @@ -1113,64 +804,47 @@ - + - - - - - - - - - - - + - - - - - - - - - - - - - @@ -1219,89 +893,68 @@ Приложение не использует мобильный интернет в роуминге. - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - @@ -1332,92 +985,68 @@ - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - -