diff --git a/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutHeaderView.swift b/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutHeaderView.swift index 37515e44ce78..7b75af4bd869 100644 --- a/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutHeaderView.swift +++ b/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutHeaderView.swift @@ -1,16 +1,37 @@ import Foundation -import SwiftUI + + +/// Defines the content of the header that appears on the top level about screen. +struct AboutScreenAppInfo { + /// The app's name + let name: String + /// The current build version of the app + let version: String + /// The app's icon + let icon: UIImage +} + +struct AboutScreenFonts { + let appName: UIFont + let appVersion: UIFont + + static let defaultFonts: AboutScreenFonts = { + // Title is serif semibold large title + let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle) + let serifFontDescriptor = fontDescriptor.withDesign(.serif) ?? fontDescriptor + let traits = [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold] + let descriptor = serifFontDescriptor.addingAttributes([.traits: traits]) + + let font = UIFont(descriptor: descriptor, size: descriptor.pointSize) + return AboutScreenFonts(appName: font, + appVersion: .preferredFont(forTextStyle: .callout)) + }() +} final class UnifiedAboutHeaderView: UIView { // MARK: - Customization Support - struct AppInfo { - let icon: UIImage - let name: String - let version: String - } - struct Spacing { let betweenAppIconAndAppNameLabel: CGFloat let betweenAppNameLabelAndAppVersionLabel: CGFloat @@ -22,11 +43,6 @@ final class UnifiedAboutHeaderView: UIView { let appIconCornerRadius: CGFloat } - struct Fonts { - let appName: UIFont - let appVersion: UIFont - } - // MARK: - Defaults public static let defaultSizing = Sizing( @@ -40,17 +56,17 @@ final class UnifiedAboutHeaderView: UIView { // MARK: - View Customization - private let appInfo: AppInfo + private let appInfo: AboutScreenAppInfo private let spacing: Spacing private let sizing: Sizing - private let fonts: Fonts + private let fonts: AboutScreenFonts // MARK: - Initializers - init(appInfo: AppInfo, + init(appInfo: AboutScreenAppInfo, sizing: Sizing = defaultSizing, spacing: Spacing = defaultSpacing, - fonts: Fonts) { + fonts: AboutScreenFonts) { self.appInfo = appInfo self.sizing = sizing diff --git a/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutViewController.swift b/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutViewController.swift index 753984480810..582ec56f1cab 100644 --- a/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/App Settings/About/UnifiedAboutViewController.swift @@ -1,8 +1,10 @@ import UIKit -import WordPressShared class UnifiedAboutViewController: UIViewController, OrientationLimited { + private let appInfo: AboutScreenAppInfo? + private let fonts: AboutScreenFonts? + private let configuration: AboutScreenConfiguration private let isSubmenu: Bool @@ -41,19 +43,14 @@ class UnifiedAboutViewController: UIViewController, OrientationLimited { return tableView }() - let headerView: UIView = { - // These customizations are temporarily here, but if this VC is moved into a framework we'll need to move them - // into the main App. - let appInfo = UnifiedAboutHeaderView.AppInfo( - icon: UIImage(named: AppIcon.currentOrDefault.imageName) ?? UIImage(), - name: (Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String) ?? "", - version: Bundle.main.detailedVersionNumber() ?? "") + lazy var headerView: UIView? = { + guard let appInfo = appInfo else { + return nil + } - let fonts = UnifiedAboutHeaderView.Fonts( - appName: WPStyleGuide.serifFontForTextStyle(.largeTitle, fontWeight: .semibold), - appVersion: WPStyleGuide.tableviewTextFont()) + let headerFonts = fonts ?? AboutScreenFonts.defaultFonts - let headerView = UnifiedAboutHeaderView(appInfo: appInfo, fonts: fonts) + let headerView = UnifiedAboutHeaderView(appInfo: appInfo, fonts: headerFonts) // Setting the frame once is needed so that the table view header will show. // This seems to be a table view bug although I'm not entirely sure. @@ -99,12 +96,9 @@ class UnifiedAboutViewController: UIViewController, OrientationLimited { // MARK: - View lifecycle - static func controller(configuration: AboutScreenConfiguration) -> UIViewController { - let controller = UnifiedAboutViewController(configuration: configuration) - return UINavigationController(rootViewController: controller) - } - - init(configuration: AboutScreenConfiguration, isSubmenu: Bool = false) { + init(appInfo: AboutScreenAppInfo? = nil, configuration: AboutScreenConfiguration, fonts: AboutScreenFonts? = nil, isSubmenu: Bool = false) { + self.appInfo = appInfo + self.fonts = fonts self.configuration = configuration self.isSubmenu = isSubmenu super.init(nibName: nil, bundle: nil) diff --git a/WordPress/Classes/ViewRelated/Me/App Settings/About/WordPressAboutScreenConfiguration.swift b/WordPress/Classes/ViewRelated/Me/App Settings/About/WordPressAboutScreenConfiguration.swift index 5994702703b7..afd78b09762b 100644 --- a/WordPress/Classes/ViewRelated/Me/App Settings/About/WordPressAboutScreenConfiguration.swift +++ b/WordPress/Classes/ViewRelated/Me/App Settings/About/WordPressAboutScreenConfiguration.swift @@ -11,6 +11,13 @@ struct WebViewPresenter { } class WordPressAboutScreenConfiguration: AboutScreenConfiguration { + static let appInfo = AboutScreenAppInfo(name: (Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String) ?? "", + version: Bundle.main.detailedVersionNumber() ?? "", + icon: UIImage(named: AppIcon.currentOrDefault.imageName) ?? UIImage()) + + static let fonts = AboutScreenFonts(appName: WPStyleGuide.serifFontForTextStyle(.largeTitle, fontWeight: .semibold), + appVersion: WPStyleGuide.tableviewTextFont()) + let sharePresenter: ShareAppContentPresenter let webViewPresenter = WebViewPresenter() diff --git a/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift b/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift index 525d78e16c17..0c88a2b96dba 100644 --- a/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift @@ -254,9 +254,12 @@ class MeViewController: UITableViewController { private func pushAbout() -> ImmuTableAction { return { [unowned self] _ in let configuration = WordPressAboutScreenConfiguration(sharePresenter: self.sharePresenter) - let controller = UnifiedAboutViewController.controller(configuration: configuration) - controller.modalPresentationStyle = .formSheet - self.present(controller, animated: true) { + let controller = UnifiedAboutViewController(appInfo: WordPressAboutScreenConfiguration.appInfo, + configuration: configuration, + fonts: WordPressAboutScreenConfiguration.fonts) + let navigationController = UINavigationController(rootViewController: controller) + navigationController.modalPresentationStyle = .formSheet + self.present(navigationController, animated: true) { self.tableView.deselectSelectedRowWithAnimation(true) } }