Skip to content

Commit

Permalink
Merge pull request #17510 from wordpress-mobile/feature/about-remove-…
Browse files Browse the repository at this point in the history
…dependencies

Unified About: Remove dependencies
  • Loading branch information
frosty authored Nov 22, 2021
2 parents dfa2dc1 + 736f4c8 commit 69ca695
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 69ca695

Please sign in to comment.