Revision control

Copy as Markdown

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import Common
import ComponentLibrary
import Foundation
import UIKit
class FadeScrollViewViewController: UIViewController, Themeable {
private let loremIpsum =
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
"""
var themeManager: ThemeManager
var themeListenerCancellable: Any?
var themeObserver: NSObjectProtocol?
var notificationCenter: NotificationProtocol = NotificationCenter.default
private lazy var scrollView: FadeScrollView = .build { view in
view.showsHorizontalScrollIndicator = false
}
private lazy var contentView: UIView = .build { _ in }
private lazy var contentLabel: UILabel = .build { label in
label.adjustsFontForContentSizeCategory = true
label.numberOfLines = 0
}
init(themeManager: ThemeManager = AppContainer.shared.resolve()) {
self.themeManager = themeManager
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
setupView()
listenForThemeChanges(withNotificationCenter: notificationCenter)
applyTheme()
contentLabel.text = String(repeating: "\(loremIpsum)\n\n", count: 5)
}
private func setupView() {
contentView.addSubview(contentLabel)
scrollView.addSubview(contentView)
view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
scrollView.topAnchor.constraint(equalTo: view.topAnchor),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
scrollView.frameLayoutGuide.widthAnchor.constraint(equalTo: contentView.widthAnchor),
scrollView.contentLayoutGuide.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
scrollView.contentLayoutGuide.topAnchor.constraint(equalTo: contentView.topAnchor),
scrollView.contentLayoutGuide.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
scrollView.contentLayoutGuide.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
contentLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 8),
contentLabel.topAnchor.constraint(equalTo: contentView.topAnchor),
contentLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -8),
contentLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
])
}
// MARK: Themeable
func applyTheme() {
contentLabel.textColor = themeManager.currentTheme.colors.textPrimary
view.backgroundColor = themeManager.currentTheme.colors.layer1
}
}