diff --git a/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertView.swift b/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertView.swift index 783accf..7560289 100644 --- a/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertView.swift +++ b/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertView.swift @@ -10,6 +10,52 @@ import UIKit import MapKit +class RealtimeAlertContainerView: UIView { + + lazy var alertView: RealtimeAlertView = { + let view = RealtimeAlertView() + view.translatesAutoresizingMaskIntoConstraints = false + return view + }() + + var animationColor: UIColor = .white + + // MARK: - Init + + convenience init() { + self.init(frame: .zero) + configureUI() + } + + // MARK: - Private + + private func configureUI() { + backgroundColor = .white + + addSubview(alertView) + + let margin: CGFloat = 24 + alertView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: margin).isActive = true + alertView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -margin).isActive = true + alertView.topAnchor.constraint(equalTo: topAnchor, constant: margin).isActive = true + alertView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -margin).isActive = true + } + + // MARK: - Public + + func startBackgroundAnimation() { + let animation = CABasicAnimation(keyPath: "backgroundColor") + animation.fromValue = UIColor.white.cgColor + animation.toValue = animationColor.cgColor + animation.duration = 2.0 + animation.beginTime = CACurrentMediaTime() + 1 + animation.autoreverses = true + animation.repeatCount = .infinity + + layer.add(animation, forKey: "backgroundColor") + } +} + class RealtimeAlertView: UIView { let titleLabel: UILabel = { @@ -46,6 +92,7 @@ class RealtimeAlertView: UIView { label.font = .preferredFont(forTextStyle: .title3) label.textColor = AppTheme.Colors.red label.textAlignment = .center + label.numberOfLines = 2 return label }() diff --git a/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertViewController.swift b/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertViewController.swift index 8c918c4..90e97b0 100644 --- a/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertViewController.swift +++ b/Sources/Earthquake Network/Controllers/Realtime Alert/RealtimeAlertViewController.swift @@ -16,7 +16,10 @@ class RealtimeAlertViewController: UIViewController, MKMapViewDelegate { // MARK: - Internal - private let notificationView = RealtimeAlertView() + private let containerView = RealtimeAlertContainerView() + private var notificationView: RealtimeAlertView { + containerView.alertView + } /// Alert to display private let realtimeAlert: EQNRealtimePushNotification /// Timer to constantly update countdown label @@ -52,7 +55,7 @@ class RealtimeAlertViewController: UIViewController, MKMapViewDelegate { // MARK: - View Lifecycle override func loadView() { - view = notificationView + view = containerView } override func viewDidLoad() { @@ -65,10 +68,20 @@ class RealtimeAlertViewController: UIViewController, MKMapViewDelegate { startWaveAnimation() } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + containerView.startBackgroundAnimation() + } + // MARK: - Private private func configureUI() { notificationView.closeButton.addTarget(self, action: #selector(onTapClose(_:)), for: .touchUpInside) + + // configure color for animation + let intensity = realtimeAlert.relativeIntensity() + containerView.animationColor = intensityTextColor(for: intensity) } private func updateUI() {