// // PrimitiveViews.swift // TUIKit // // Primitive view types that serve as leaves in the view tree. // // MARK: - Never as View /// `Never` conforms to View for views that have no body. /// /// Primitive views like `Text` or containers like `TupleView` have no /// body of their own - they are rendered directly. This extension allows /// using `Never` as the body type. extension Never: View { public var body: Never { fatalError("Never.body should never be called") } } // MARK: - EmptyView /// A view that displays no content. /// /// `EmptyView` is useful for placeholders or when a view /// should display nothing under certain conditions. /// /// ```swift /// if showContent { /// Text("Content") /// } else { /// EmptyView() /// } /// ``` public struct EmptyView: View { /// Creates an empty view. public init() {} public var body: Never { fatalError("EmptyView has no body") } } // MARK: - ConditionalView /// A view that represents either the true or false branch of a conditional. /// /// This type is used internally by `ViewBuilder` for if-else statements. public enum ConditionalView: View { /// The true branch was executed. case trueContent(TrueContent) /// The false branch was executed. case falseContent(FalseContent) public var body: Never { fatalError("ConditionalView renders its children directly") } } // MARK: - ViewArray /// A view that contains an array of identical views. /// /// This type is used internally by `ViewBuilder` for for-in loops. /// /// ```swift /// ForEach(items) { item in /// Text(item.name) /// } /// ``` public struct ViewArray: View { /// The contained views. public let elements: [Element] /// Creates a ViewArray from an array of views. /// /// - Parameter elements: The views this container holds. public init(_ elements: [Element]) { self.elements = elements } public var body: Never { fatalError("ViewArray renders its children directly") } } // MARK: - Optional View Conformance /// Optional views conform to View when their Wrapped type does. extension Optional: View where Wrapped: View { public var body: some View { switch self { case .some(let view): view case .none: EmptyView() } } }