Yattee v2 rewrite

This commit is contained in:
Arkadiusz Fal
2026-02-08 18:31:16 +01:00
parent 20d0cfc0c7
commit 05f921d605
1043 changed files with 163875 additions and 68430 deletions

View File

@@ -0,0 +1,50 @@
//
// View+Conditional.swift
// Yattee
//
// Conditional view modifier extension.
//
import SwiftUI
extension View {
/// Conditionally applies a transformation to the view.
@ViewBuilder
func `if`<Transform: View>(
_ condition: Bool,
transform: (Self) -> Transform
) -> some View {
if condition {
transform(self)
} else {
self
}
}
/// Conditionally applies one of two transformations.
@ViewBuilder
func `if`<TrueContent: View, FalseContent: View>(
_ condition: Bool,
then trueTransform: (Self) -> TrueContent,
else falseTransform: (Self) -> FalseContent
) -> some View {
if condition {
trueTransform(self)
} else {
falseTransform(self)
}
}
/// Conditionally applies a transformation when an optional value is present.
@ViewBuilder
func ifLet<T, Transform: View>(
_ value: T?,
transform: (Self, T) -> Transform
) -> some View {
if let value {
transform(self, value)
} else {
self
}
}
}