Skip to content

Commit

Permalink
Update fonts, add attributed strings and add tap gestures back.
Browse files Browse the repository at this point in the history
Footers use subheadline. Headers use footnote.
  • Loading branch information
pixlwave committed Oct 15, 2021
1 parent 5204154 commit 06b1473
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 103 deletions.
2 changes: 1 addition & 1 deletion DesignKit/Source/FontsUIkit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import UIKit
/**
ObjC class for holding fonts for use in UIKit.
*/
@objc public class FontsUIKit: NSObject, Fonts {
@objcMembers public class FontsUIKit: NSObject, Fonts {

public var largeTitle: UIFont

Expand Down
16 changes: 15 additions & 1 deletion Riot/Modules/Common/Models/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ final class Section: NSObject {
let tag: Int
var rows: [Row]
var headerTitle: String?
var footerTitle: String?
var attributedFooterTitle: NSAttributedString?

var footerTitle: String? {
get {
attributedFooterTitle?.string
}
set {
guard let newValue = newValue else {
attributedFooterTitle = nil
return
}

attributedFooterTitle = NSAttributedString(string: newValue)
}
}

init(withTag tag: Int) {
self.tag = tag
Expand Down
41 changes: 41 additions & 0 deletions Riot/Modules/Common/SectionFooters/SectionFooterView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import UIKit

/// A subclass of `UITableViewHeaderFooterView` that conforms `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 {
static var defaultReuseIdentifier: String {
String(describing: Self.self)
}

override func prepareForReuse() {
super.prepareForReuse()

for recognizer in gestureRecognizers ?? [] {
removeGestureRecognizer(recognizer)
}
}

func update(theme: Theme) {
textLabel?.textColor = theme.colors.secondaryContent
textLabel?.font = theme.fonts.subheadline
textLabel?.numberOfLines = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Foundation

private enum DiscoverySectionRows {
case info(text: String)
case attributedInfo(attributedText: NSAttributedString)
case button(title: String, action: () -> Void)
case threePid(threePid: MX3PID)
}
Expand All @@ -41,6 +40,12 @@ private enum DiscoverySectionRows {

@objc weak var delegate: SettingsDiscoveryTableViewSectionDelegate?

@objc var attributedFooterTitle: NSAttributedString?

@objc var footerShouldScrollToUserSettings: Bool {
attributedFooterTitle != nil
}

// MARK: Private

private var theme: Theme!
Expand Down Expand Up @@ -96,13 +101,6 @@ private enum DiscoverySectionRows {
infoCell.selectionStyle = .none
cell = infoCell
}
case .attributedInfo(attributedText: let infoText):
if let infoCell: MXKTableViewCell = self.cellType(at: row) {
infoCell.textLabel?.numberOfLines = 0
infoCell.textLabel?.attributedText = infoText
infoCell.selectionStyle = .none
cell = infoCell
}
case .button(title: let title, action: let action):
if let buttonCell: MXKTableViewCellWithButton = self.cellType(at: row) {
buttonCell.mxkButton.setTitle(title, for: .normal)
Expand Down Expand Up @@ -145,15 +143,6 @@ private enum DiscoverySectionRows {
switch discoveryRow {
case .threePid(threePid: let threePid):
self.viewModel.process(viewAction: .select(threePid: threePid))
case .attributedInfo(attributedText: _):
if case let .loaded(displayMode) = self.viewState {
switch displayMode {
case .noThreePidsAdded, .threePidsAdded:
self.viewModel.process(viewAction: .tapUserSettingsLink)
default:
break
}
}
default:
break
}
Expand Down Expand Up @@ -183,6 +172,7 @@ private enum DiscoverySectionRows {

private func updateRows() {

attributedFooterTitle = nil;
let discoveryRows: [DiscoverySectionRows]

switch self.viewState {
Expand All @@ -202,9 +192,8 @@ private enum DiscoverySectionRows {
})
]
case .noThreePidsAdded:
discoveryRows = [
.attributedInfo(attributedText: self.threePidsManagementInfoAttributedString())
]
discoveryRows = []
attributedFooterTitle = self.threePidsManagementInfoAttributedString()
case .threePidsAdded(let emails, let phoneNumbers):

let emailThreePids = emails.map { (email) -> DiscoverySectionRows in
Expand All @@ -218,7 +207,7 @@ private enum DiscoverySectionRows {
var threePidsRows: [DiscoverySectionRows] = []
threePidsRows.append(contentsOf: emailThreePids)
threePidsRows.append(contentsOf: phoneNumbersThreePids)
threePidsRows.append(.attributedInfo(attributedText: self.threePidsManagementInfoAttributedString()))
attributedFooterTitle = self.threePidsManagementInfoAttributedString()

discoveryRows = threePidsRows
}
Expand All @@ -236,11 +225,11 @@ private enum DiscoverySectionRows {

private func threePidsManagementInfoAttributedString() -> NSAttributedString {
let attributedInfoString = NSMutableAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart1,
attributes: [.foregroundColor: self.theme.textPrimaryColor, .font: Constants.defaultFont])
attributes: [:])
attributedInfoString.append(NSAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart2,
attributes: [.foregroundColor: self.theme.tintColor, .font: Constants.defaultFont]))
attributes: [.foregroundColor: self.theme.tintColor]))
attributedInfoString.append(NSAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart3,
attributes: [.foregroundColor: self.theme.tintColor, .font: Constants.defaultFont]))
attributes: [:]))
return attributedInfoString
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ enum SettingsDiscoveryViewAction {
case load
case acceptTerms
case select(threePid: MX3PID)
case tapUserSettingsLink
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ import Foundation
self.acceptTerms()
case .select(threePid: let threePid):
self.coordinatorDelegate?.settingsDiscoveryViewModel(self, didSelectThreePidWith: threePid.medium.identifier, and: threePid.address)
case .tapUserSettingsLink:
self.coordinatorDelegate?.settingsDiscoveryViewModelDidTapUserSettingsLink(self)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ protocol SettingsDiscoveryViewModelViewDelegate: AnyObject {

@objc protocol SettingsDiscoveryViewModelCoordinatorDelegate: AnyObject {
func settingsDiscoveryViewModel(_ viewModel: SettingsDiscoveryViewModel, didSelectThreePidWith medium: String, and address: String)
func settingsDiscoveryViewModelDidTapUserSettingsLink(_ viewModel: SettingsDiscoveryViewModel)
}

protocol SettingsDiscoveryViewModelType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view
// Customize label style
UITableViewHeaderFooterView *tableViewHeaderFooterView = (UITableViewHeaderFooterView*)view;
tableViewHeaderFooterView.textLabel.textColor = ThemeService.shared.theme.colors.secondaryContent;
tableViewHeaderFooterView.textLabel.font = ThemeService.shared.theme.fonts.footnote;
}
}

Expand Down
29 changes: 16 additions & 13 deletions Riot/Modules/Settings/Security/SecurityViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ - (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]];

// Enable self sizing cells
// Enable self sizing cells and footers
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 50;
self.tableView.sectionFooterHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionFooterHeight = 50;

if (self.mainSession.crypto.backup)
{
Expand Down Expand Up @@ -1295,26 +1298,26 @@ - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view
// Customize label style
UITableViewHeaderFooterView *tableViewHeaderFooterView = (UITableViewHeaderFooterView*)view;
tableViewHeaderFooterView.textLabel.textColor = ThemeService.shared.theme.colors.secondaryContent;
tableViewHeaderFooterView.textLabel.font = ThemeService.shared.theme.fonts.footnote;
}
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
Section *tableSection = [self.tableViewSections sectionAtIndex:section];
return tableSection.footerTitle;
}

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section
{
if ([view isKindOfClass:UITableViewHeaderFooterView.class])
NSString *footerTitle = [_tableViewSections sectionAtIndex:section].footerTitle;

if (!footerTitle)
{
// Customize label style
UITableViewHeaderFooterView *tableViewHeaderFooterView = (UITableViewHeaderFooterView*)view;
tableViewHeaderFooterView.textLabel.textColor = ThemeService.shared.theme.colors.secondaryContent;
return nil;
}

SectionFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionFooterView.defaultReuseIdentifier];
[view updateWithTheme:ThemeService.shared.theme];
view.textLabel.text = footerTitle;

return view;
}


#pragma mark - UITableView delegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
Expand Down
Loading

0 comments on commit 06b1473

Please sign in to comment.