blob: 39e4405da8e6de50c3989c89fdcbaaa875c3e032 (
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
32
33
34
35
36
37
38
39
40
41
|
//
// View+Conditionals.swift
// MullvadVPN
//
// Created by Jon Petersson on 2025-01-07.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import SwiftUI
extension View {
@ViewBuilder func `if`<Content: View>(
_ conditional: Bool,
@ViewBuilder _ content: (Self) -> Content
) -> some View {
if conditional {
content(self)
} else {
self
}
}
@ViewBuilder func ifLet<Content: View, T>(
_ conditional: T?,
@ViewBuilder _ content: (Self, _ value: T) -> Content
) -> some View {
if let value = conditional {
content(self, value)
} else {
self
}
}
@ViewBuilder func showIf(_ conditional: Bool) -> some View {
if conditional {
self
} else {
EmptyView()
}
}
}
|