87 lines
2.5 KiB
Swift
87 lines
2.5 KiB
Swift
//
|
|
// PreferencesView.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Murad Shabanov on 08.02.2022.
|
|
// Copyright © 2022 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
final class PreferencesView: NSView {
|
|
|
|
private enum Constants {
|
|
|
|
enum Geometry {
|
|
static let barEmptyHeight: CGFloat = 0
|
|
static let barHeight: CGFloat = 36
|
|
}
|
|
}
|
|
|
|
private var navigationBarHeightAnchor: NSLayoutConstraint?
|
|
|
|
// MARK: - JSNavigationControllerViewDelegate
|
|
|
|
let barView: NSView
|
|
let contentView: NSView
|
|
var leadingConstraint: NSLayoutConstraint?
|
|
|
|
|
|
// MARK: - Initializers
|
|
|
|
override init(frame frameRect: NSRect) {
|
|
|
|
|
|
self.barView = NSView()
|
|
self.contentView = NSView()
|
|
|
|
super.init(frame: frameRect)
|
|
|
|
self.createUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func createUI() {
|
|
|
|
self.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
self.barView.translatesAutoresizingMaskIntoConstraints = false
|
|
self.addSubview(self.barView)
|
|
|
|
self.contentView.translatesAutoresizingMaskIntoConstraints = false
|
|
self.addSubview(self.contentView)
|
|
|
|
let heightLayout = self.barView.heightAnchor.constraint(equalToConstant: 0)
|
|
self.navigationBarHeightAnchor = heightLayout
|
|
|
|
NSLayoutConstraint.activate([
|
|
heightLayout,
|
|
self.barView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
|
|
self.barView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
|
|
self.barView.topAnchor.constraint(equalTo: self.topAnchor),
|
|
//
|
|
self.contentView.topAnchor.constraint(equalTo: self.barView.bottomAnchor),
|
|
self.contentView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
|
|
self.contentView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
|
|
self.contentView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - JSNavigationControllerViewDelegate
|
|
|
|
extension PreferencesView: JSNavigationControllerViewDelegate {
|
|
|
|
var navigationBarView: NSView? { self.barView }
|
|
|
|
func hasNavigationBar(_ hasBar: Bool) {
|
|
guard let heightLayout = self.navigationBarHeightAnchor else { return }
|
|
heightLayout.constant = hasBar ? Constants.Geometry.barHeight : Constants.Geometry.barEmptyHeight
|
|
}
|
|
}
|