2023-12-25 06:02:38 +00:00
|
|
|
//
|
2024-01-09 17:32:06 +00:00
|
|
|
// ViewExtensions.swift
|
2023-12-25 06:02:38 +00:00
|
|
|
// Jel
|
|
|
|
//
|
|
|
|
// Created by zerocool on 12/25/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
extension View {
|
|
|
|
/// Applies the given transform if the given condition evaluates to `true`.
|
|
|
|
@ViewBuilder func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
|
|
|
|
if condition() {
|
|
|
|
transform(self)
|
|
|
|
} else {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-09 17:32:06 +00:00
|
|
|
|
|
|
|
extension View {
|
|
|
|
/// Applies an inverse mask to the given view
|
|
|
|
public func inverseMask<Content: View>(_ mask: Content) -> some View {
|
|
|
|
let inverseMask = mask
|
|
|
|
.foregroundStyle(.black)
|
|
|
|
.background(.white)
|
|
|
|
.compositingGroup()
|
|
|
|
.luminanceToAlpha()
|
|
|
|
return self.mask(inverseMask)
|
|
|
|
}
|
|
|
|
}
|