Files
2021-07-08 22:30:34 +06:00

90 lines
3.2 KiB
Swift

//
// NotificationsBellModuleView.swift
// PrivadoVPN
//
// Created by Zhandos Bolatbekov on 12.01.2021.
// Copyright © 2021 Privado LLC. All rights reserved.
//
import Foundation
import UIKit
class NotificationsBellModuleView: UIButton, NotificationsBellViewInput {
private enum Constants {
static let bellImage = "notifications_button"
enum Color {
static let badgeBorderColor = UIColor(red: 25, green: 33, blue: 70)
static let badgeFillColor = UIColor(red: 228, green: 59, blue: 105)
}
enum Geometry {
static let imageSize = CGSize(width: 14, height: 18)
static let badgeSize: CGFloat = 9.3
static let badgeBorderWidth: CGFloat = 1.7
static let badgeTop: CGFloat = 1
static let badgeRight: CGFloat = 2
}
}
var output: NotificationsBellModuleOutput
private let badgeView: UIView = {
let badge = UIView()
badge.translatesAutoresizingMaskIntoConstraints = false
badge.layer.cornerRadius = Constants.Geometry.badgeSize / 2
badge.layer.borderWidth = Constants.Geometry.badgeBorderWidth
badge.layer.backgroundColor = Constants.Color.badgeFillColor.cgColor
badge.layer.borderColor = Constants.Color.badgeBorderColor.cgColor
badge.clipsToBounds = true
badge.isHidden = true
return badge
}()
// MARK: - Init
init(output: NotificationsBellModuleOutput) {
self.output = output
super.init(frame: .zero)
let bellImage = UIImage(named: Constants.bellImage)
let bellImageView = UIImageView(image: bellImage)
bellImageView.translatesAutoresizingMaskIntoConstraints = false
addSubview(bellImageView)
NSLayoutConstraint.activate([
bellImageView.heightAnchor.constraint(equalToConstant: Constants.Geometry.imageSize.height),
bellImageView.widthAnchor.constraint(equalToConstant: Constants.Geometry.imageSize.width),
bellImageView.centerXAnchor.constraint(equalTo: self.centerXAnchor),
bellImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor)
])
addSubview(badgeView)
NSLayoutConstraint.activate([
badgeView.topAnchor.constraint(equalTo: bellImageView.topAnchor, constant: Constants.Geometry.badgeTop),
badgeView.rightAnchor.constraint(equalTo: bellImageView.rightAnchor, constant: Constants.Geometry.badgeRight),
badgeView.heightAnchor.constraint(equalToConstant: Constants.Geometry.badgeSize),
badgeView.widthAnchor.constraint(equalToConstant: Constants.Geometry.badgeSize)
])
addTarget(self, action: #selector(notificationsButtonClick), for: .touchUpInside)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Interface
func showBadge(_ show: Bool) {
badgeView.isHidden = !show
}
func set(highlighted: Bool) { }
// MARK: - Methods
@objc
private func notificationsButtonClick() {
output.openNotificationsList()
}
}