Skip to content

Commit f874246

Browse files
committed
readme updated
1 parent c2c3f26 commit f874246

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Focuser
22

3-
Focuser allows to focus SwiftUI text fields dynamically and implements ability move go through the form using Keyboard for iOS 13 and iOS 14. Implementation is designed to follow [Apple `@FocusState`](https://developer.apple.com/documentation/swiftui/focusstate) property wrapper. Since most of us cannot update our apps to serve iOS 15 exclusively `Focuser` will provide an easy way to accomplish the same thing.
3+
Focuser allows to focus SwiftUI text fields dynamically and implements ability move go through the form using Keyboard for iOS 13 and iOS 14. Implementation is modeled to follow [Apple `@FocusState`](https://developer.apple.com/documentation/swiftui/focusstate) property wrapper however instead of however instead of `@FocusState` we use `@FocusStateLegacy` and for `.focused(...)` we use `.focusedLegacy(...)`. Since most of us cannot update our apps to serve iOS 15 exclusively `Focuser` will provide an easy way to change first responder and connect to keyboard "next"/"done" buttons.
44

55
## Preview
66

@@ -26,11 +26,11 @@ To use Focuser you first need to `import Focuser` and define an `enum` correspon
2626
import Focuser
2727

2828
enum FormFields {
29-
case none, username, password, name
29+
case username, password, name
3030
}
3131
```
3232

33-
`.none` is a special case used to reasign first responder. Since Focuser allows to focus keyboard to the next text fields using keybaord we have to provide additional information of what the next field should be. We provide this using extension on our struct comforming to `FocusStateCompliant` protocol. In addition of providing computed variable `next` we also provide `last`. This indicates to Focuser when it should show "done" keyboard button instead of "next".
33+
Since Focuser allows to focus keyboard to the next text fields using keybaord we have to provide additional information of what the next field should be. We provide this using extension on our struct comforming to `FocusStateCompliant` protocol. In addition of providing computed variable `next` we also provide `last`. This indicates to Focuser when it should show "done" keyboard button instead of "next". To resign first responder (hide keyboard) set your `focusedField` to `nil`.
3434

3535
```swift
3636
extension FormFields: FocusStateCompliant {
@@ -39,13 +39,13 @@ extension FormFields: FocusStateCompliant {
3939
.name
4040
}
4141

42-
var next: FormFields {
42+
var next: FormFields? {
4343
switch self {
4444
case .username:
4545
return .password
4646
case .password:
4747
return .name
48-
default: return .none
48+
default: return nil
4949
}
5050
}
5151
}
@@ -55,7 +55,7 @@ Finally we can build our form
5555

5656
```swift
5757
struct ContentView: View {
58-
@FocusStateLegacy var focusedField: FormFields = .username
58+
@FocusStateLegacy var focusedField: FormFields?
5959
@State var username = ""
6060
@State var password = ""
6161
@State var name = ""
@@ -72,7 +72,7 @@ struct ContentView: View {
7272
.focusedLegacy($focusedField, equals: .name)
7373

7474
Button(action: {
75-
focusedField = .password
75+
focusedField = FormFields.password
7676
}) {
7777
Text("Focus Password")
7878
}
@@ -96,6 +96,15 @@ TextField("Username", text: $username)
9696
.focusedLegacy($focusedField, equals: .username)
9797
```
9898

99+
## Comparison to iOS 15 `@FocusState`
100+
101+
The API is analogous and our property wrapper has exactly the same definition. If you ever decide to switch to iOS 15 wrapper, all you need to do is replace
102+
103+
`@FocusStateLegacy` -> `@FocusState`
104+
`.focusedLegacy(...)` -> `.focused(...)`
105+
106+
However, Focuser additionally offers to show different keyboard return button such as "next" or "done" based on where you are in the form.
107+
99108
## To do
100109

101110
- Support for `TextEditor`

0 commit comments

Comments
 (0)