Settings: Switch to UIKit
This commit is contained in:
47
App/Common UI/GenericContentView.swift
Normal file
47
App/Common UI/GenericContentView.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// GenericContentView.swift
|
||||
// GenericContentView
|
||||
//
|
||||
// Created by James Magahern on 6/29/21.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class GenericContentView<View, Configuration> : UIView, UIContentView
|
||||
where View: UIView, Configuration: UIContentConfiguration
|
||||
{
|
||||
typealias Applicator = (Configuration, View) -> Void
|
||||
|
||||
var insets: UIEdgeInsets = .zero
|
||||
let applicator: Applicator
|
||||
let view: View
|
||||
|
||||
var configuration: UIContentConfiguration {
|
||||
didSet {
|
||||
guard let config = configuration as? Configuration else { return }
|
||||
apply(config)
|
||||
}
|
||||
}
|
||||
|
||||
init(configuration: Configuration, view: View, applicator: @escaping Applicator) {
|
||||
self.configuration = configuration
|
||||
self.view = view
|
||||
self.applicator = applicator
|
||||
super.init(frame: .zero)
|
||||
addSubview(view)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
view.frame = bounds.inset(by: insets)
|
||||
}
|
||||
|
||||
internal func apply(_ configuration: Configuration) {
|
||||
applicator(configuration, view)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user