// // LaunchScreenScrollView.swift // PrivadoVPN // // Created by Lizaveta Malinouskaya on 6/22/21. // Copyright © 2021 Privado LLC. All rights reserved. // import UIKit class LaunchScreenScrollView: UITextView { enum Constants { enum UI { static let font = UIFont.primary(size: 13, weight: .medium) static let textColor = Colors.basicText.color static let bgColor = Colors.Base.primaryDarkBlue.color static let insetHorizontal: CGFloat = 32 static let insetVertical: CGFloat = 60 static let lineSpacing: CGFloat = 19 } enum LocalizedString { static let content = "launch.content" } } private var compactConstraints = [NSLayoutConstraint]() private var regularConstraints = [NSLayoutConstraint]() private var sharedConstraints = [NSLayoutConstraint]() private let isLandscapeModeEmitter = Emitter() // MARK: - Init init() { super.init(frame: .zero, textContainer: nil) configureUI() self.isLandscapeModeEmitter.addReaction { [weak self] isLandscape -> ShouldContinueReceiveNotifications in self?.activateLayoutFor(landscape: isLandscape) return self.isExist } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } // MARK: - UI private func configureUI() { self.translatesAutoresizingMaskIntoConstraints = false self.showsVerticalScrollIndicator = false self.showsHorizontalScrollIndicator = false self.isEditable = false self.setContentText(with: self) // Self apperance self.font = Constants.UI.font self.textColor = Constants.UI.textColor self.backgroundColor = Constants.UI.bgColor self.textContainerInset = UIEdgeInsets(top: Constants.UI.insetVertical, left: Constants.UI.insetHorizontal, bottom: Constants.UI.insetVertical, right: Constants.UI.insetHorizontal) // Self scroll indicator self.isScrollEnabled = true self.showsVerticalScrollIndicator = true self.scrollIndicatorInsets = UIEdgeInsets(top: Constants.UI.insetVertical, left: 0, bottom: Constants.UI.insetVertical, right: 0) } private func setContentText(with container: UITextView) { let text = NSLocalizedString(Constants.LocalizedString.content, comment: "Privacy policy") let mutableAttributedString = NSMutableAttributedString(string: text) let style = NSMutableParagraphStyle() style.lineSpacing = Constants.UI.lineSpacing mutableAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: style], range: NSRange(location: 0, length: mutableAttributedString.length)) self.attributedText = mutableAttributedString } private func activateLayoutFor(landscape: Bool) { if landscape { NSLayoutConstraint.deactivate(self.compactConstraints) NSLayoutConstraint.activate(self.regularConstraints) } else { NSLayoutConstraint.deactivate(self.regularConstraints) NSLayoutConstraint.activate(self.compactConstraints) } NSLayoutConstraint.activate(self.sharedConstraints) } }