/
Environment+TextFieldStyle.swift
62 lines (52 loc) · 2.29 KB
/
Environment+TextFieldStyle.swift
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//=----------------------------------------------------------------------------=
// This source file is part of the DiffableTextViews open source project.
//
// Copyright (c) 2022 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
#if canImport(UIKit)
import SwiftUI
//*============================================================================*
// MARK: * Environment x Text Field Style
//*============================================================================*
//=----------------------------------------------------------------------------=
// MARK: + Keys
//=----------------------------------------------------------------------------=
@usableFromInline enum DiffableTextViews_TextFieldStyle: EnvironmentKey {
@usableFromInline static let defaultValue: UITextField.BorderStyle = .none
}
//=----------------------------------------------------------------------------=
// MARK: + Values
//=----------------------------------------------------------------------------=
extension EnvironmentValues {
@inlinable var diffableTextViews_textFieldStyle: UITextField.BorderStyle {
get { self[DiffableTextViews_TextFieldStyle.self] }
set { self[DiffableTextViews_TextFieldStyle.self] = newValue }
}
}
//=----------------------------------------------------------------------------=
// MARK: + View
//=----------------------------------------------------------------------------=
public extension View {
/// Sets the text field style for diffable text views.
///
/// It is similar to `View/textFieldStyle(_:), but based on UIKit.
///
/// ```
/// DiffableTextField("Bordered", value: $value, style: style)
/// .diffableTextViews_textFieldStyle(.roundedRect)
/// ```
///
/// **Notes**
///
/// - The value is read when the view is set up.
/// - The default value is `UITextField.BorderStyle.none`.
/// - The `View/textFieldStyle(_:)` environment value is inaccessible.
///
@inlinable func diffableTextViews_textFieldStyle(_ style: UITextField.BorderStyle) -> some View {
self.environment(\.diffableTextViews_textFieldStyle, style)
}
}
#endif