From ac0bde8445ca5cb8384d72824d675048485aeb68 Mon Sep 17 00:00:00 2001 From: Muukii Date: Fri, 21 Jun 2024 18:22:47 +0900 Subject: [PATCH] Patch --- .../Components/Conditional.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Sources/SwiftUISupport/Components/Conditional.swift diff --git a/Sources/SwiftUISupport/Components/Conditional.swift b/Sources/SwiftUISupport/Components/Conditional.swift new file mode 100644 index 0000000000..e428ae35f4 --- /dev/null +++ b/Sources/SwiftUISupport/Components/Conditional.swift @@ -0,0 +1,24 @@ +import SwiftUI + +extension View { + /// Applies the given transform if the given condition evaluates to `true`. + /// @see Referenced from: https://www.avanderlee.com/swiftui/conditional-view-modifier/ + /// - Parameters: + /// - condition: The condition to evaluate. + /// - transform: The transform to apply to the source `View`. + /// - Returns: Either the original `View` or the modified `View` if the condition is `true`. + @ViewBuilder public func `if`(_ condition: Bool, transform: (Self) -> Content) -> some View { + if condition { + transform(self) + } else { + self + } + } + + @ViewBuilder + public func `do`( + @ViewBuilder transform: (Self) -> Content + ) -> some View { + transform(self) + } +}