diff --git a/Riot/Modules/Common/SectionFooters/SectionFooterView.swift b/Riot/Modules/Common/SectionFooters/SectionFooterView.swift index 394207b74e..21ac03c7af 100644 --- a/Riot/Modules/Common/SectionFooters/SectionFooterView.swift +++ b/Riot/Modules/Common/SectionFooters/SectionFooterView.swift @@ -15,16 +15,44 @@ // import UIKit +import Reusable -/// A subclass of `UITableViewHeaderFooterView` that conforms `Themable` +/// A subclass of `UITableViewHeaderFooterView` that conforms to `Themable` /// to create a consistent looking custom footer inside of the app. If using gesture /// recognizers on the view, be aware that these will be automatically removed on reuse. @objcMembers -class SectionFooterView: UITableViewHeaderFooterView, Themable { +class SectionFooterView: UITableViewHeaderFooterView, NibLoadable, Themable { + + // MARK: - Properties + static var defaultReuseIdentifier: String { String(describing: Self.self) } + static var nib: UINib { + // Copy paste from NibReusable in order to expose to ObjC + UINib(nibName: String(describing: self), bundle: Bundle(for: self)) + } + + var leadingInset: CGFloat { + get { footerLabelLeadingConstraint.constant } + set { footerLabelLeadingConstraint.constant = newValue } + } + + // Expose `footerLabel` as the default label property. + override var textLabel: UILabel? { + footerLabel + } + + /// The text label added in the xib file. Using our own label was necessary due to the behaviour + /// on iOS 12-14 where any customisation to the text label would be wiped out after being set + /// in `tableView:viewForFooterInSection`. This behaviour is fixed in iOS 15. + @IBOutlet private weak var footerLabel: UILabel! + /// The label's leading constraint, relative to the safe area insets. + @IBOutlet private weak var footerLabelLeadingConstraint: NSLayoutConstraint! + + // MARK: - Public + override func prepareForReuse() { super.prepareForReuse() @@ -34,8 +62,8 @@ class SectionFooterView: UITableViewHeaderFooterView, Themable { } func update(theme: Theme) { - textLabel?.textColor = theme.colors.secondaryContent - textLabel?.font = theme.fonts.subheadline - textLabel?.numberOfLines = 0 + footerLabel.textColor = theme.colors.secondaryContent + footerLabel.font = theme.fonts.subheadline + footerLabel.numberOfLines = 0 } } diff --git a/Riot/Modules/Common/SectionFooters/SectionFooterView.xib b/Riot/Modules/Common/SectionFooters/SectionFooterView.xib new file mode 100644 index 0000000000..1dbf29848d --- /dev/null +++ b/Riot/Modules/Common/SectionFooters/SectionFooterView.xib @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Riot/Modules/Settings/Security/SecurityViewController.m b/Riot/Modules/Settings/Security/SecurityViewController.m index 1f8adbf4cd..5e479e5340 100644 --- a/Riot/Modules/Settings/Security/SecurityViewController.m +++ b/Riot/Modules/Settings/Security/SecurityViewController.m @@ -159,7 +159,7 @@ - (void)viewDidLoad [self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]]; [self.tableView registerNib:MXKTableViewCellWithTextView.nib forCellReuseIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier]]; [self.tableView registerNib:MXKTableViewCellWithButton.nib forCellReuseIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]]; - [self.tableView registerClass:SectionFooterView.class forHeaderFooterViewReuseIdentifier:[SectionFooterView defaultReuseIdentifier]]; + [self.tableView registerNib:SectionFooterView.nib forHeaderFooterViewReuseIdentifier:[SectionFooterView defaultReuseIdentifier]]; // Enable self sizing cells and footers self.tableView.rowHeight = UITableViewAutomaticDimension; @@ -1313,6 +1313,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger SectionFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionFooterView.defaultReuseIdentifier]; [view updateWithTheme:ThemeService.shared.theme]; + view.leadingInset = tableView.vc_separatorInset.left; view.textLabel.text = footerTitle; return view; @@ -1346,20 +1347,6 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce } } -//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section -//{ -// if (section == SECTION_CRYPTO_SESSIONS) -// { -// return 44; -// } -// return 24; -//} -// -//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section -//{ -// return 24; -//} - - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.tableView == tableView) diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 758b151b83..458eb48da8 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -602,7 +602,7 @@ - (void)viewDidLoad [self.tableView registerClass:TableViewCellWithPhoneNumberTextField.class forCellReuseIdentifier:[TableViewCellWithPhoneNumberTextField defaultReuseIdentifier]]; [self.tableView registerClass:GroupTableViewCellWithSwitch.class forCellReuseIdentifier:[GroupTableViewCellWithSwitch defaultReuseIdentifier]]; [self.tableView registerNib:MXKTableViewCellWithTextView.nib forCellReuseIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier]]; - [self.tableView registerClass:SectionFooterView.class forHeaderFooterViewReuseIdentifier:[SectionFooterView defaultReuseIdentifier]]; + [self.tableView registerNib:SectionFooterView.nib forHeaderFooterViewReuseIdentifier:[SectionFooterView defaultReuseIdentifier]]; // Enable self sizing cells and footers self.tableView.rowHeight = UITableViewAutomaticDimension; @@ -2442,6 +2442,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger SectionFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionFooterView.defaultReuseIdentifier]; [view updateWithTheme:ThemeService.shared.theme]; + view.leadingInset = tableView.vc_separatorInset.left; view.textLabel.attributedText = attributedFooterTitle; if (section == SECTION_TAG_USER_SETTINGS) diff --git a/Riot/Modules/Spaces/BetaAnnounceCell.swift b/Riot/Modules/Spaces/BetaAnnounceCell.swift index 9897c9417f..08485e91ae 100644 --- a/Riot/Modules/Spaces/BetaAnnounceCell.swift +++ b/Riot/Modules/Spaces/BetaAnnounceCell.swift @@ -82,7 +82,7 @@ final class BetaAnnounceCell: UITableViewCell, Themable { } } -// Copy past from NibReusable in order to expose these methods to ObjC +// Copy paste from NibReusable in order to expose these methods to ObjC extension BetaAnnounceCell { @objc static var reuseIdentifier: String { return String(describing: self)