Files
raspberry/iOS/Wallet/Sources/Common/Popup/PopupNotificationController.swift
2022-11-24 21:36:54 +03:00

166 lines
7.4 KiB
Swift

//
// PopupNotificationController.swift
// Malinka
//
// Created by user on 17.11.2022.
// Copyright © 2022 NUT.Tech. All rights reserved.
//
import UIKit
final class PopupNotificationController: UIViewController {
private enum Constants {
static let shadowColor = UIColor.black.withAlphaComponent(0.70)
static let titleFontSize: CGFloat = 28
static let descriptionFontSize: CGFloat = 16
static let buttonFontSize: CGFloat = 14
}
private enum Geometry {
static let dialogViewRadius: CGFloat = 20
static let dialogViewWidth: CGFloat = 343
static let dialogViewHeight: CGFloat = 253
static let separatorViewHeight: CGFloat = 3
static let separatorViewWidth: CGFloat = 49
static let separatorViewTop: CGFloat = 12
static let buttonRadius: CGFloat = 10
static let buttonHeight: CGFloat = 48
static let buttonBottom: CGFloat = 43
static let titleIconTop: CGFloat = 24
static let descriptionLabelMargin: CGFloat = 34
static let commonMargin: CGFloat = 12
static let iconSize: CGFloat = 24
static let titleLeftMargin: CGFloat = 10
}
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
label.font = FontFamily.GolosUI.bold.font(size: Constants.titleFontSize)
label.textColor = Asset.textCoal.color
return label
}()
private lazy var descriptionLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
label.font = FontFamily.GolosUI.regular.font(size: Constants.descriptionFontSize)
label.textColor = Asset.textCoal.color
return label
}()
private lazy var dialogView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.clipsToBounds = true
view.backgroundColor = Asset.snow.color
view.layer.cornerRadius = Geometry.dialogViewRadius
return view
}()
private lazy var separatorView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.clipsToBounds = true
view.backgroundColor = Asset.lightGray.color
return view
}()
private lazy var titleIcon: UIImageView = {
let icon = UIImageView()
icon.translatesAutoresizingMaskIntoConstraints = false
return icon
}()
private lazy var button: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.clipsToBounds = true
button.layer.cornerRadius = Geometry.buttonRadius
button.titleLabel?.font = FontFamily.GolosUI.regular.font(size: Constants.buttonFontSize)
button.backgroundColor = Asset.deepWater.color
button.setTitleColor(Asset.textSnow.color, for: .normal)
button.addTarget(self, action: #selector(self.close), for: .touchDown)
return button
}()
private lazy var shadowView: UIControl = {
let view = UIControl()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = Constants.shadowColor
view.addTarget(self, action: #selector(self.close), for: .touchDown)
return view
}()
convenience init(title: String,
description: String,
buttonText: String,
icon: UIImage? = nil) {
self.init()
self.titleLabel.text = title
self.descriptionLabel.text = description
self.button.setTitle(buttonText, for: .normal)
self.titleIcon.image = icon
self.modalPresentationStyle = .overFullScreen
self.modalTransitionStyle = .crossDissolve
}
override func viewDidLoad() {
super.viewDidLoad()
self.setupLayout()
}
private func setupLayout() {
self.dialogView.addSubview(self.titleIcon)
self.dialogView.addSubview(self.titleLabel)
self.dialogView.addSubview(self.descriptionLabel)
self.dialogView.addSubview(self.button)
self.view.addSubview(self.shadowView)
self.view.addSubview(self.dialogView)
self.view.addSubview(self.separatorView)
NSLayoutConstraint.activate([
self.shadowView.leftAnchor.constraint(equalTo: self.view.leftAnchor),
self.shadowView.rightAnchor.constraint(equalTo: self.view.rightAnchor),
self.shadowView.topAnchor.constraint(equalTo: self.view.topAnchor),
self.shadowView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
self.dialogView.leftAnchor.constraint(equalTo: self.view.leftAnchor),
self.dialogView.rightAnchor.constraint(equalTo: self.view.rightAnchor),
self.dialogView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
self.dialogView.heightAnchor.constraint(equalToConstant: Geometry.dialogViewHeight),
self.separatorView.widthAnchor.constraint(equalToConstant: Geometry.separatorViewWidth),
self.separatorView.heightAnchor.constraint(equalToConstant: Geometry.separatorViewHeight),
self.separatorView.topAnchor.constraint(equalTo: self.dialogView.topAnchor, constant: Geometry.separatorViewTop),
self.separatorView.centerXAnchor.constraint(equalTo: self.dialogView.centerXAnchor),
self.titleIcon.leftAnchor.constraint(equalTo: self.dialogView.leftAnchor, constant: Geometry.commonMargin),
self.titleIcon.topAnchor.constraint(equalTo: self.dialogView.topAnchor, constant: Geometry.titleIconTop),
self.titleIcon.widthAnchor.constraint(lessThanOrEqualToConstant: Geometry.iconSize),
self.titleIcon.heightAnchor.constraint(equalToConstant: Geometry.iconSize),
self.titleLabel.leftAnchor.constraint(equalTo: self.titleIcon.rightAnchor, constant: Geometry.titleLeftMargin),
self.titleLabel.centerYAnchor.constraint(equalTo: self.titleIcon.centerYAnchor),
self.titleLabel.rightAnchor.constraint(equalTo: self.dialogView.rightAnchor, constant: -Geometry.commonMargin),
self.descriptionLabel.topAnchor.constraint(equalTo: self.titleLabel.bottomAnchor, constant: Geometry.descriptionLabelMargin),
self.descriptionLabel.leftAnchor.constraint(equalTo: self.dialogView.leftAnchor, constant: Geometry.commonMargin),
self.descriptionLabel.rightAnchor.constraint(equalTo: self.dialogView.rightAnchor, constant: -Geometry.commonMargin),
self.descriptionLabel.bottomAnchor.constraint(equalTo: self.button.topAnchor, constant: -Geometry.descriptionLabelMargin),
self.button.leftAnchor.constraint(equalTo: self.dialogView.leftAnchor, constant: Geometry.commonMargin),
self.button.rightAnchor.constraint(equalTo: self.dialogView.rightAnchor, constant: -Geometry.commonMargin),
self.button.bottomAnchor.constraint(equalTo: self.dialogView.bottomAnchor, constant: -Geometry.buttonBottom),
self.button.heightAnchor.constraint(equalToConstant: Geometry.buttonHeight)
])
}
@objc private func close() {
self.dismiss(animated: true)
}
}