Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update about screen #2152

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions DuckDuckGo/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,64 @@

import UIKit
import Core
import SwiftUI
import DesignResourcesKit

class AboutViewController: UIViewController {
class AboutViewController: UIHostingController<AboutView> {

@IBOutlet weak var headerText: UILabel!
@IBOutlet weak var descriptionText: UILabel!
@IBOutlet weak var logoImage: UIImageView!
@IBOutlet weak var moreButton: UIButton!

override func viewDidLoad() {
super.viewDidLoad()

applyTheme(ThemeManager.shared.currentTheme)
convenience init() {
self.init(rootView: AboutView())
}

@IBAction func onPrivacyLinkTapped(_ sender: UIButton) {
dismiss(animated: true) {
UIApplication.shared.open(URL.aboutLink, options: [:])
}

struct AboutView: View {

var body: some View {
ScrollView {
VStack(spacing: 12) {
Image("Logo")
.resizable()
.frame(width: 96, height: 96)
.padding(.top)

Image("TextDuckDuckGo")

Text("Welcome to the Duck Side!")
.daxHeadline()

Rectangle()
.frame(width: 80, height: 0.5)
.foregroundColor(Color(designSystemColor: .lines))
.padding()

Text(LocalizedStringKey(UserText.aboutText))
.lineLimit(nil)
.multilineTextAlignment(.leading)
.foregroundColor(.primary)
.tintIfAvailable(Color(designSystemColor: .accent))
.padding(.horizontal, 32)
.padding(.bottom)

Spacer()
}
.frame(maxWidth: .infinity)
}
.background(Rectangle()
.ignoresSafeArea()
.foregroundColor(Color(designSystemColor: .background)))
}

}

extension AboutViewController: Themable {
private extension View {

func decorate(with theme: Theme) {
view.backgroundColor = theme.backgroundColor

switch theme.currentImageSet {
case .light:
logoImage?.image = UIImage(named: "LogoDarkText")
case .dark:
logoImage?.image = UIImage(named: "LogoLightText")
@ViewBuilder func tintIfAvailable(_ color: Color) -> some View {
if #available(iOS 16.0, *) {
tint(color)
} else {
self
}

decorateDescription(with: theme)

headerText.textColor = theme.aboutScreenTextColor
moreButton.setTitleColor(theme.aboutScreenButtonColor, for: .normal)
}

private func decorateDescription(with theme: Theme) {
if let attributedText = descriptionText.attributedText,
var font = attributedText.attribute(NSAttributedString.Key.font, at: 0, effectiveRange: nil) as? UIFont {

let attributes: [NSAttributedString.Key: Any]
if traitCollection.horizontalSizeClass == .regular,
traitCollection.verticalSizeClass == .regular {
font = font.withSize(24.0)
attributes = [.foregroundColor: theme.aboutScreenTextColor,
.font: font]
} else {
attributes = [.foregroundColor: theme.aboutScreenTextColor,
.font: font]
}

let decoratedText = NSMutableAttributedString(string: UserText.settingsAboutText)
decoratedText.addAttributes(attributes, range: NSRange(location: 0, length: decoratedText.length))

descriptionText.attributedText = decoratedText
}
}
}
Loading