Skip to content

Commit

Permalink
Add SectionFooterView.xib to fix fonts on iOS 12-14.
Browse files Browse the repository at this point in the history
Update SecurityViewController too.
  • Loading branch information
pixlwave committed Oct 20, 2021
1 parent 5466aeb commit 6a1fd34
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
38 changes: 33 additions & 5 deletions Riot/Modules/Common/SectionFooters/SectionFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
}
}
40 changes: 40 additions & 0 deletions Riot/Modules/Common/SectionFooters/SectionFooterView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="SectionFooterView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="210"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tZ9-SU-Yp2">
<rect key="frame" x="20" y="50" width="374" height="148"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="tZ9-SU-Yp2" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="6" id="6jE-ua-fKl"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="tZ9-SU-Yp2" secondAttribute="trailing" constant="20" id="OMT-ZP-qap"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="tZ9-SU-Yp2" secondAttribute="bottom" constant="12" id="Yrv-I1-gG1"/>
<constraint firstItem="tZ9-SU-Yp2" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="k4h-Zl-arh"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="footerLabel" destination="tZ9-SU-Yp2" id="V24-Xh-sz0"/>
<outlet property="footerLabelLeadingConstraint" destination="k4h-Zl-arh" id="TjX-h5-vJJ"/>
</connections>
<point key="canvasLocation" x="131.8840579710145" y="-170.08928571428569"/>
</view>
</objects>
</document>
3 changes: 2 additions & 1 deletion Riot/Modules/Settings/Security/SecurityViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Spaces/BetaAnnounceCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6a1fd34

Please sign in to comment.