50 lines
1.4 KiB
Swift
50 lines
1.4 KiB
Swift
//
|
|
// BaseView.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Zhandos Bolatbekov on 04.06.2021.
|
|
// Copyright © 2021 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BaseView: UIView, ReactivelyConstrained {
|
|
|
|
var portraitConstraints = [NSLayoutConstraint]()
|
|
var landscapeConstraints = [NSLayoutConstraint]()
|
|
var sharedConstraints = [NSLayoutConstraint]()
|
|
|
|
let layoutEmitter = Emitter<EmitterLayoutChangeType>()
|
|
|
|
init() {
|
|
super.init(frame: .zero)
|
|
|
|
self.layoutEmitter.addReaction { [weak self] isLandscape -> ShouldContinueReceiveNotifications in
|
|
|
|
guard let self = self else { return false }
|
|
|
|
if isLandscape {
|
|
NSLayoutConstraint.deactivate(self.portraitConstraints)
|
|
NSLayoutConstraint.activate(self.landscapeConstraints)
|
|
} else {
|
|
NSLayoutConstraint.deactivate(self.landscapeConstraints)
|
|
NSLayoutConstraint.activate(self.portraitConstraints)
|
|
}
|
|
NSLayoutConstraint.activate(self.sharedConstraints)
|
|
|
|
self.subviews.forEach { view in
|
|
if let view = view as? BaseView {
|
|
view.layoutEmitter.invoke(isLandscape)
|
|
}
|
|
}
|
|
|
|
self.layoutIfNeeded()
|
|
|
|
return true
|
|
}
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder: NSCoder) { nil }
|
|
}
|