diff options
author | Shav Kinderlehrer <[email protected]> | 2023-12-25 01:02:38 -0500 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-12-25 01:02:38 -0500 |
commit | bd0b6ff491b33088a4db55c495b8aab797f0b22a (patch) | |
tree | 2989fcff9f37810368efa246046f31dd67eadff4 /Jel/Models/ViewConditionalMethod.swift | |
parent | 8e73b094bafb635c30845b996340bc492e5633e4 (diff) | |
download | jel-bd0b6ff491b33088a4db55c495b8aab797f0b22a.tar.gz jel-bd0b6ff491b33088a4db55c495b8aab797f0b22a.zip |
Fix searchBar jank
Diffstat (limited to 'Jel/Models/ViewConditionalMethod.swift')
-rw-r--r-- | Jel/Models/ViewConditionalMethod.swift | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Jel/Models/ViewConditionalMethod.swift b/Jel/Models/ViewConditionalMethod.swift new file mode 100644 index 0000000..195a8dc --- /dev/null +++ b/Jel/Models/ViewConditionalMethod.swift @@ -0,0 +1,23 @@ +// +// ViewConditionalMethod.swift +// Jel +// +// Created by zerocool on 12/25/23. +// + +import SwiftUI + +extension View { + /// Applies the given transform if the given condition evaluates to `true`. + /// - 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 func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View { + if condition() { + transform(self) + } else { + self + } + } +} |