Skip to content

Commit

Permalink
Merge pull request #6 from ricocrescenzio95/2-unify-formatter-and-par…
Browse files Browse the repository at this point in the history
…seableformatstyle

Unify formatter and parseableFormatStyle/Formatter
  • Loading branch information
ricocrescenzio95 authored Apr 15, 2022
2 parents a5e9431 + 3a8ba92 commit ea2c26c
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 31 deletions.
1 change: 1 addition & 0 deletions SUITextFieldExample/SUITextFieldExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct ContentView: View {
SUITextField(
value: $myDouble,
format: .number,
formatPolicy: .onChange,
placeholder: AttributedString("Hey there")
.mergingAttributes(AttributeContainer(placeholderAttributes))
)
Expand Down
19 changes: 19 additions & 0 deletions Sources/SwiftUITextField/SwiftUITextField.docc/SUITextField.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

## Topics

### Creating a text field with a string

- ``SUITextField/init(text:placeholder:)-5btu0``
- ``SUITextField/init(text:placeholder:)-7334w``
- ``SUITextField/init(text:placeholder:)-9p6by``

### Creating a text field with a value (iOS 15)

- ``SUITextField/init(value:format:formatPolicy:placeholder:defaultValue:)-3i36v``
- ``SUITextField/init(value:format:formatPolicy:placeholder:defaultValue:)-5fdb3``
- ``SUITextField/init(value:format:formatPolicy:placeholder:)-9l23l``
- ``SUITextField/init(value:format:formatPolicy:placeholder:)-2bhgs``
- ``FormatPolicy``

### Creating a text field with a value (pre-iOS 15)

- ``SUITextField/init(value:formatter:formatPolicy:placeholder:defaultValue:)-3wopi``
- ``SUITextField/init(value:formatter:formatPolicy:placeholder:defaultValue:)-1cub1``

### Modify style and behaviors

- <doc:EnvironmentModifiers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ formatters. Check all the provided initializers in ``SUITextField``!
- ``ResponderState``
- ``ResponderChainCoordinator``


### Miscellaneous

- ``CharacterReplacement``
Expand Down
20 changes: 20 additions & 0 deletions Sources/SwiftUITextField/TextField/FormatPolicy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// FormatPolicy.swift
//
//
// Created by Rico Crescenzio on 15/04/22.
//

import Foundation

/// Indicates when the bound value is updated on a ``SUITextField`` with format/formatter.
///
/// Policy can specify when the conversion is made, either during typing or when text field did end editing.
public enum FormatPolicy {

/// Parses the text to bound value on every text insertion.
case onChange

/// Parses the text to bound value when text field end editing.
case onCommit
}
Loading

0 comments on commit ea2c26c

Please sign in to comment.