| 1 |
//
|
|
| 2 |
// ChatLayout
|
|
| 3 |
// StaticViewFactory.swift
|
|
| 4 |
// https://github.com/ekazaev/ChatLayout
|
|
| 5 |
//
|
|
| 6 |
// Created by Eugene Kazaev in 2020-2023.
|
|
| 7 |
// Distributed under the MIT license.
|
|
| 8 |
//
|
|
| 9 |
// Become a sponsor:
|
|
| 10 |
// https://github.com/sponsors/ekazaev
|
|
| 11 |
//
|
|
| 12 |
|
|
| 13 |
import Foundation
|
|
| 14 |
import UIKit
|
|
| 15 |
|
|
| 16 |
/// A factory that creates optional contained `UIView`s should conform to this protocol.
|
|
| 17 |
public protocol StaticViewFactory {
|
|
| 18 |
|
|
| 19 |
/// A type of the view to build.
|
|
| 20 |
associatedtype View: UIView
|
|
| 21 |
|
|
| 22 |
/// Factory method that will be called by the corresponding container `UIView`
|
|
| 23 |
/// - Parameter bounds: A bounds rect of the container.
|
|
| 24 |
/// - Returns: Build `UIView` instance.
|
|
| 25 |
static func buildView(within bounds: CGRect) -> View?
|
|
| 26 |
|
|
| 27 |
}
|
|
| 28 |
|
|
| 29 |
/// Default extension build the `UIView` using its default constructor.
|
|
| 30 |
public extension StaticViewFactory where Self: UIView {
|
|
| 31 |
|
|
| 32 |
static func buildView(within bounds: CGRect) -> Self? {
|
! |
| 33 |
Self(frame: bounds)
|
! |
| 34 |
}
|
! |
| 35 |
|
|
| 36 |
}
|
|
| 37 |
|
|
| 38 |
/// Use this factory to specify that this view should not be build and should be equal to nil within the container.
|
|
| 39 |
public struct VoidViewFactory: StaticViewFactory {
|
|
| 40 |
|
|
| 41 |
/// Nil view placeholder type.
|
|
| 42 |
public final class VoidView: UIView {
|
|
| 43 |
|
|
| 44 |
@available(*, unavailable, message: "This view can not be instantiated.")
|
|
| 45 |
public required init?(coder aDecoder: NSCoder) {
|
! |
| 46 |
fatalError("This view can not be instantiated.")
|
! |
| 47 |
}
|
! |
| 48 |
|
|
| 49 |
@available(*, unavailable, message: "This view can not be instantiated.")
|
|
| 50 |
public override init(frame: CGRect) {
|
! |
| 51 |
fatalError("This view can not be instantiated.")
|
! |
| 52 |
}
|
! |
| 53 |
|
|
| 54 |
@available(*, unavailable, message: "This view can not be instantiated.")
|
|
| 55 |
public init() {
|
! |
| 56 |
fatalError("This view can not be instantiated.")
|
! |
| 57 |
}
|
! |
| 58 |
|
|
| 59 |
}
|
|
| 60 |
|
|
| 61 |
public static func buildView(within bounds: CGRect) -> VoidView? {
|
! |
| 62 |
nil
|
! |
| 63 |
}
|
! |
| 64 |
|
|
| 65 |
}
|
|