blob: 7cb201f01f45ba3cb4e32e649836f3cdcdf74f9b (
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+Modifier.swift
// MullvadVPN
//
// Created by Steffen Ernst on 2025-01-21.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import SwiftUI
extension View {
/**
A view modifier that can be used to conditionally apply other view modifiers.
# Example #
```
.apply {
if #available(iOS 16.4, *) {
$0.scrollBounceBehavior(.basedOnSize)
} else {
$0
}
}
```
*/
func apply<V: View>(@ViewBuilder _ block: (Self) -> V) -> V { block(self) }
/**
Uses the AccessibilityIdentifier you specify to identify the view.
# Discussion #
Use this value for testing. It isn’t visible to the user.
*/
func accessibilityIdentifier(_ id: AccessibilityIdentifier?) -> some View {
apply {
if let id {
$0.accessibilityIdentifier(id.asString)
} else {
$0
}
}
}
}
|