Skip to content

Commit 4c33639

Browse files
committed
Commented: environment methods.
1 parent cb8eb65 commit 4c33639

12 files changed

+347
-35
lines changed

Sources/DiffableTextKitXUIKit/Environment+AutocorrectionDisabled.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,49 @@
1212
import SwiftUI
1313

1414
//*============================================================================*
15-
// MARK: * Environment x Autocorrection Disabled [...]
15+
// MARK: * Environment x Autocorrection Disabled
1616
//*============================================================================*
17+
//=----------------------------------------------------------------------------=
18+
// MARK: + Keys
19+
//=----------------------------------------------------------------------------=
1720

1821
@usableFromInline enum DiffableTextViews_AutocorrectionDisabled: EnvironmentKey {
1922
@usableFromInline static let defaultValue: Bool = false
2023
}
2124

25+
//=----------------------------------------------------------------------------=
26+
// MARK: + Values
27+
//=----------------------------------------------------------------------------=
28+
2229
extension EnvironmentValues {
2330
@inlinable var diffableTextViews_autocorrectionDisabled: Bool {
2431
get { self[DiffableTextViews_AutocorrectionDisabled.self] }
2532
set { self[DiffableTextViews_AutocorrectionDisabled.self] = newValue }
2633
}
2734
}
2835

36+
//=----------------------------------------------------------------------------=
37+
// MARK: + View
38+
//=----------------------------------------------------------------------------=
39+
2940
public extension View {
30-
@inlinable func diffableTextViews_autocorrectionDisabled(_ disabled: Bool = true) -> some View {
31-
environment(\.diffableTextViews_autocorrectionDisabled, disabled)
41+
42+
/// Sets whether to disable autocorrection for diffable text views.
43+
///
44+
/// It is similar to `View/autocorrectionDisabled(_:)`.
45+
///
46+
/// ```
47+
/// DiffableTextField("Text", value: $text, style: .normal)
48+
/// .diffableTextViews_autocorrectionDisabled(true)
49+
/// ```
50+
///
51+
/// **Notes**
52+
///
53+
/// - The default value is `false`.
54+
/// - This method was added for consistency.
55+
///
56+
@inlinable func diffableTextViews_autocorrectionDisabled(_ disabled: Bool = true) -> some View {
57+
self.environment(\.diffableTextViews_autocorrectionDisabled, disabled)
3258
}
3359
}
3460

Sources/DiffableTextKitXUIKit/Environment+Font.swift

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,54 @@
1212
import SwiftUI
1313

1414
//*============================================================================*
15-
// MARK: * Environment x Font [...]
15+
// MARK: * Environment x Font
1616
//*============================================================================*
17+
//=----------------------------------------------------------------------------=
18+
// MARK: + Keys
19+
//=----------------------------------------------------------------------------=
1720

1821
@usableFromInline enum DiffableTextViews_Font: EnvironmentKey {
1922
@usableFromInline static let defaultValue: DiffableTextFont? = nil
2023
}
2124

25+
//=----------------------------------------------------------------------------=
26+
// MARK: + Values
27+
//=----------------------------------------------------------------------------=
28+
2229
extension EnvironmentValues {
2330
@inlinable var diffableTextViews_font: DiffableTextFont? {
2431
get { self[DiffableTextViews_Font.self] }
2532
set { self[DiffableTextViews_Font.self] = newValue }
2633
}
2734
}
2835

36+
//=----------------------------------------------------------------------------=
37+
// MARK: + View
38+
//=----------------------------------------------------------------------------=
39+
2940
public extension View {
30-
@inlinable func diffableTextViews_font(_ font: DiffableTextFont?) -> some View {
31-
environment(\.diffableTextViews_font, font)
41+
42+
/// Sets the default font for text in diffable text views.
43+
///
44+
/// It is similar to `View/font(_:)` but uses a SwiftUI-esque system font type.
45+
///
46+
/// ```
47+
/// DiffableTextField("Monospaced", value: $value, style: style)
48+
/// .diffableTextViews_font(.body.monospaced())
49+
/// ```
50+
///
51+
/// Monospaced fonts are recommended because they make as-you-type formatting
52+
/// more visually predictable. Sometimes it does not matter much, however. As-you-type
53+
/// formatting with trailing text alignment works fine with just about any font,
54+
/// because then the caret and/or selection does not jump around as much.
55+
///
56+
/// **Notes**
57+
///
58+
/// - The default value is `DiffableTextFont.body`.
59+
/// - It is not yet possible to convert `SwiftUI.Font` to `UIKit.UIFont`.
60+
///
61+
@inlinable func diffableTextViews_font(_ font: DiffableTextFont?) -> some View {
62+
self.environment(\.diffableTextViews_font, font)
3263
}
3364
}
3465

Sources/DiffableTextKitXUIKit/Environment+ForegroundColor.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,49 @@
1212
import SwiftUI
1313

1414
//*============================================================================*
15-
// MARK: * Environment x Foreground Color [...]
15+
// MARK: * Environment x Foreground Color
1616
//*============================================================================*
17+
//=----------------------------------------------------------------------------=
18+
// MARK: + Keys
19+
//=----------------------------------------------------------------------------=
1720

1821
@usableFromInline enum DiffableTextViews_ForegroundColor: EnvironmentKey {
1922
@usableFromInline static let defaultValue: Color? = nil
2023
}
2124

25+
//=----------------------------------------------------------------------------=
26+
// MARK: + Values
27+
//=----------------------------------------------------------------------------=
28+
2229
extension EnvironmentValues {
2330
@inlinable var diffableTextViews_foregroundColor: Color? {
2431
get { self[DiffableTextViews_ForegroundColor.self] }
2532
set { self[DiffableTextViews_ForegroundColor.self] = newValue }
2633
}
2734
}
2835

36+
//=----------------------------------------------------------------------------=
37+
// MARK: + View
38+
//=----------------------------------------------------------------------------=
39+
2940
public extension View {
30-
@inlinable func diffableTextViews_foregroundColor(_ color: Color?) -> some View {
31-
environment(\.diffableTextViews_foregroundColor, color)
41+
42+
/// Sets the text color of diffable text views.
43+
///
44+
/// It is similar to `View/foregroundColor(_:)`.
45+
///
46+
/// ```
47+
/// DiffableTextField("Amount", value: $amount, style: .number)
48+
/// .diffableTextViews_foregroundColor(amount > 100 ? .red : nil)
49+
/// ```
50+
///
51+
/// **Notes**
52+
///
53+
/// - The default value is `Color.primary`.
54+
/// - The `View/foregroundColor(_:)` environment value is inaccessible.
55+
///
56+
@inlinable func diffableTextViews_foregroundColor(_ color: Color?) -> some View {
57+
self.environment(\.diffableTextViews_foregroundColor, color)
3258
}
3359
}
3460

Sources/DiffableTextKitXUIKit/Environment+KeyboardType.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,49 @@
1212
import SwiftUI
1313

1414
//*============================================================================*
15-
// MARK: * Environment x Keyboard Type [...]
15+
// MARK: * Environment x Keyboard Type
1616
//*============================================================================*
17+
//=----------------------------------------------------------------------------=
18+
// MARK: + Keys
19+
//=----------------------------------------------------------------------------=
1720

1821
@usableFromInline enum DiffableTextViews_KeyboardType: EnvironmentKey {
1922
@usableFromInline static let defaultValue: UIKeyboardType = .default
2023
}
2124

25+
//=----------------------------------------------------------------------------=
26+
// MARK: + Values
27+
//=----------------------------------------------------------------------------=
28+
2229
extension EnvironmentValues {
2330
@inlinable var diffableTextViews_keyboardType: UIKeyboardType {
2431
get { self[DiffableTextViews_KeyboardType.self] }
2532
set { self[DiffableTextViews_KeyboardType.self] = newValue }
2633
}
2734
}
2835

36+
//=----------------------------------------------------------------------------=
37+
// MARK: + View
38+
//=----------------------------------------------------------------------------=
39+
2940
public extension View {
30-
@inlinable func diffableTextViews_keyboardType(_ type: UIKeyboardType) -> some View {
31-
environment(\.diffableTextViews_keyboardType, type)
41+
42+
/// Sets the keyboard type for diffable text views.
43+
///
44+
/// It is similar to `View/keyboardType(_:)`.
45+
///
46+
/// ```
47+
/// TextField("Amount", value: $amount, style: .currency("USD"))
48+
/// .keyboardType(.decimalPad)
49+
/// ```
50+
///
51+
/// **Notes**
52+
///
53+
/// - The default value is `UIKeyboardType.default`.
54+
/// - The `View/keyboardType(_:)` environment value is inaccessible.
55+
///
56+
@inlinable func diffableTextViews_keyboardType(_ type: UIKeyboardType) -> some View {
57+
self.environment(\.diffableTextViews_keyboardType, type)
3258
}
3359
}
3460

Sources/DiffableTextKitXUIKit/Environment+MultilineTextAlignment.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,49 @@
1212
import SwiftUI
1313

1414
//*============================================================================*
15-
// MARK: * Environment x Multiline Text Alignment [...]
15+
// MARK: * Environment x Multiline Text Alignment
1616
//*============================================================================*
17+
//=----------------------------------------------------------------------------=
18+
// MARK: + Keys
19+
//=----------------------------------------------------------------------------=
1720

1821
@usableFromInline enum DiffableTextViews_MultilineTextAlignment: EnvironmentKey {
1922
@usableFromInline static let defaultValue: TextAlignment = .leading
2023
}
2124

25+
//=----------------------------------------------------------------------------=
26+
// MARK: + Values
27+
//=----------------------------------------------------------------------------=
28+
2229
extension EnvironmentValues {
2330
@inlinable var diffableTextViews_multilineTextAlignment: TextAlignment {
2431
get { self[DiffableTextViews_MultilineTextAlignment.self] }
2532
set { self[DiffableTextViews_MultilineTextAlignment.self] = newValue }
2633
}
2734
}
2835

36+
//=----------------------------------------------------------------------------=
37+
// MARK: + View
38+
//=----------------------------------------------------------------------------=
39+
2940
public extension View {
30-
@inlinable func diffableTextViews_multilineTextAlignment(_ alignment: TextAlignment) -> some View {
31-
environment(\.diffableTextViews_multilineTextAlignment, alignment)
41+
42+
/// Sets the alignment of text a diffable text view.
43+
///
44+
/// It is similar to `View/multilineTextAlignment(_:)`.
45+
///
46+
/// ```
47+
/// DiffableTextField("Amount", value: $value, style: .number)
48+
/// .multilineTextAlignment(.trailing)
49+
/// ```
50+
///
51+
/// **Notes**
52+
///
53+
/// - The default value is `TextAlignment.leading`.
54+
/// - This method was added for consistency.
55+
///
56+
@inlinable func diffableTextViews_multilineTextAlignment(_ alignment: TextAlignment) -> some View {
57+
self.environment(\.diffableTextViews_multilineTextAlignment, alignment)
3258
}
3359
}
3460

Sources/DiffableTextKitXUIKit/Environment+OnSubmit.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,23 @@ public extension View {
3131

3232
/// Adds an action to perform when the user submits a value to this view.
3333
///
34-
/// DiffableTextViews trigger this action when the user hits the return key.
34+
/// It is similar to `View/onSubmit(_:)`.
3535
///
36-
@inlinable func diffableTextViews_onSubmit(_ action: (() -> Void)?) -> some View {
37-
environment(\.diffableTextViews_onSubmit, action.map(Trigger.init))
36+
/// ```
37+
/// DiffableTextField("Username", text: $username, style: .normal)
38+
/// .onSubmit {
39+
/// guard model.validate() else { return }
40+
/// model.login()
41+
/// }
42+
/// ```
43+
///
44+
/// **Notes**
45+
///
46+
/// - The action triggers when the user hits the return key.
47+
/// - The `View/onSubmit(_:)` environment value is inaccessible.
48+
///
49+
@inlinable func diffableTextViews_onSubmit(_ action: (() -> Void)?) -> some View {
50+
self.environment(\.diffableTextViews_onSubmit, action.map(Trigger.init))
3851
}
3952
}
4053

Sources/DiffableTextKitXUIKit/Environment+SubmitLabel.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,49 @@
1212
import SwiftUI
1313

1414
//*============================================================================*
15-
// MARK: * Environment x Submit Label [...]
15+
// MARK: * Environment x Submit Label
1616
//*============================================================================*
17+
//=----------------------------------------------------------------------------=
18+
// MARK: + Keys
19+
//=----------------------------------------------------------------------------=
1720

1821
@usableFromInline enum DiffableTextViews_SubmitLabel: EnvironmentKey {
1922
@usableFromInline static let defaultValue: UIReturnKeyType = .default
2023
}
2124

25+
//=----------------------------------------------------------------------------=
26+
// MARK: + Values
27+
//=----------------------------------------------------------------------------=
28+
2229
extension EnvironmentValues {
2330
@inlinable var diffableTextViews_submitLabel: UIReturnKeyType {
2431
get { self[DiffableTextViews_SubmitLabel.self] }
2532
set { self[DiffableTextViews_SubmitLabel.self] = newValue }
2633
}
2734
}
2835

36+
//=----------------------------------------------------------------------------=
37+
// MARK: + View
38+
//=----------------------------------------------------------------------------=
39+
2940
public extension View {
30-
@inlinable func diffableTextViews_submitLabel(_ label: UIReturnKeyType) -> some View {
31-
environment(\.diffableTextViews_submitLabel, label)
41+
42+
/// Sets the submit label for diffable text views.
43+
///
44+
/// It is similar to `View/submitLabel(_:)`.
45+
///
46+
/// ```
47+
/// DiffableTextField("Prints on submit...", value: $value, style: style)
48+
/// .diffableTextViews_submitLabel(.return)
49+
/// ```
50+
///
51+
/// **Notes**
52+
///
53+
/// - The default value is `UIReturnKeyType.default`.
54+
/// - The `View/submitLabel(_:)` environment value is inaccessible.
55+
///
56+
@inlinable func diffableTextViews_submitLabel(_ label: UIReturnKeyType) -> some View {
57+
self.environment(\.diffableTextViews_submitLabel, label)
3258
}
3359
}
3460

0 commit comments

Comments
 (0)