Skip to content

Commit ea2c26c

Browse files
Merge pull request #6 from ricocrescenzio95/2-unify-formatter-and-parseableformatstyle
Unify formatter and parseableFormatStyle/Formatter
2 parents a5e9431 + 3a8ba92 commit ea2c26c

File tree

5 files changed

+185
-31
lines changed

5 files changed

+185
-31
lines changed

SUITextFieldExample/SUITextFieldExample/ContentView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct ContentView: View {
8787
SUITextField(
8888
value: $myDouble,
8989
format: .number,
90+
formatPolicy: .onChange,
9091
placeholder: AttributedString("Hey there")
9192
.mergingAttributes(AttributeContainer(placeholderAttributes))
9293
)

Sources/SwiftUITextField/SwiftUITextField.docc/SUITextField.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
## Topics
44

5+
### Creating a text field with a string
6+
7+
- ``SUITextField/init(text:placeholder:)-5btu0``
8+
- ``SUITextField/init(text:placeholder:)-7334w``
9+
- ``SUITextField/init(text:placeholder:)-9p6by``
10+
11+
### Creating a text field with a value (iOS 15)
12+
13+
- ``SUITextField/init(value:format:formatPolicy:placeholder:defaultValue:)-3i36v``
14+
- ``SUITextField/init(value:format:formatPolicy:placeholder:defaultValue:)-5fdb3``
15+
- ``SUITextField/init(value:format:formatPolicy:placeholder:)-9l23l``
16+
- ``SUITextField/init(value:format:formatPolicy:placeholder:)-2bhgs``
17+
- ``FormatPolicy``
18+
19+
### Creating a text field with a value (pre-iOS 15)
20+
21+
- ``SUITextField/init(value:formatter:formatPolicy:placeholder:defaultValue:)-3wopi``
22+
- ``SUITextField/init(value:formatter:formatPolicy:placeholder:defaultValue:)-1cub1``
23+
524
### Modify style and behaviors
625

726
- <doc:EnvironmentModifiers>

Sources/SwiftUITextField/SwiftUITextField.docc/SwiftUITextField.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ formatters. Check all the provided initializers in ``SUITextField``!
8484
- ``ResponderState``
8585
- ``ResponderChainCoordinator``
8686

87-
8887
### Miscellaneous
8988

9089
- ``CharacterReplacement``
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// FormatPolicy.swift
3+
//
4+
//
5+
// Created by Rico Crescenzio on 15/04/22.
6+
//
7+
8+
import Foundation
9+
10+
/// Indicates when the bound value is updated on a ``SUITextField`` with format/formatter.
11+
///
12+
/// Policy can specify when the conversion is made, either during typing or when text field did end editing.
13+
public enum FormatPolicy {
14+
15+
/// Parses the text to bound value on every text insertion.
16+
case onChange
17+
18+
/// Parses the text to bound value when text field end editing.
19+
case onCommit
20+
}

0 commit comments

Comments
 (0)