blob: 7f5486522843357833cc415d0645009bbbe65bdb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
//
// ViewExtensions.swift
// 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
}
}
}
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)
}
}
|