Files
TUIkit/Sources/TUIKit/Core/PrimitiveViews.swift
T
phranck 45e73faafb refactor: Rename package from SwiftTUI to TUIKit
BREAKING CHANGE: Package name changed due to name collision with
existing rensbreur/SwiftTUI package.

Changes:
- Rename package from SwiftTUI to TUIKit in Package.swift
- Rename Sources/SwiftTUI to Sources/TUIKit
- Rename Sources/SwiftTUIExample to Sources/TUIKitExample
- Rename Tests/SwiftTUITests to Tests/TUIKitTests
- Rename SwiftTUI.swift to TUIKit.swift
- Update all imports: import SwiftTUI -> import TUIKit
- Update all code references: SwiftTUI.renderToBuffer -> TUIKit.renderToBuffer
- Update documentation comments
- Rename swiftTUIVersion to tuiKitVersion

All 181 tests passing.
2026-01-28 19:32:09 +01:00

101 lines
2.4 KiB
Swift

//
// 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<TrueContent: View, FalseContent: View>: 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<Element: View>: 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()
}
}
}