Skip to content

Commit dda69c2

Browse files
committed
Refactor on multiline submit
1 parent dc413fd commit dda69c2

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ These release notes cover the current major version. See older versions for olde
1111

1212

1313

14+
## 6.1.1
15+
16+
This version renames the `onMultilineSubmit` view extension.
17+
18+
19+
1420
## 6.1
1521

1622
This version bumps the package to Swift 6.1 and deprecates some list views.

Sources/SwiftUIKit/Text/MultilineSubmitViewModifier.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,26 @@ public struct MultilineSubmitViewModifier: ViewModifier {
1616
///
1717
/// - Parameters:
1818
/// - text: The text binding used by the text field.
19-
/// - submitLabel: The submit label to use.
2019
/// - onSubmit: The function to call when return is pressed.
2120
public init(
2221
text: Binding<String>,
23-
submitLabel: SubmitLabel,
24-
onSubmit: @escaping () -> Void
22+
action: @escaping () -> Void
2523
) {
2624
self._text = text
27-
self.submitLabel = submitLabel
28-
self.onSubmit = onSubmit
25+
self.action = action
2926
}
3027

3128
@Binding
3229
private var text: String
3330

34-
private let submitLabel: SubmitLabel
35-
private let onSubmit: () -> Void
36-
31+
private let action: () -> Void
32+
3733
@FocusState
3834
private var isFocused: Bool
3935

4036
public func body(content: Content) -> some View {
4137
content
4238
.focused($isFocused)
43-
.submitLabel(submitLabel)
4439
#if os(visionOS)
4540
.onChange(of: text) { handle($1) }
4641
#else
@@ -53,28 +48,35 @@ public struct MultilineSubmitViewModifier: ViewModifier {
5348
guard newText.contains("\n") else { return }
5449
isFocused = false
5550
text = newText.replacingOccurrences(of: "\n", with: "")
56-
onSubmit()
51+
action()
5752
}
5853
}
5954

6055
public extension View {
6156

57+
@available(*, deprecated, renamed: "onMultilineSubmit(of:action:)")
58+
func multilineSubmit(
59+
for text: Binding<String>,
60+
submitLabel: SubmitLabel = .done,
61+
action: @escaping () -> Void = {}
62+
) -> some View {
63+
self.submitLabel(submitLabel)
64+
.onMultilineSubmit(of: text, action: action)
65+
}
66+
6267
/// Make a multiline textfield auto-submit when the primary button is pressed.
6368
///
6469
/// - Parameters:
6570
/// - text: The text binding used by the text field.
66-
/// - submitLabel: The submit label to use, by default `.done`.
6771
/// - action: The function to call when return is pressed.
68-
func multilineSubmit(
69-
for text: Binding<String>,
70-
submitLabel: SubmitLabel = .done,
72+
func onMultilineSubmit(
73+
of text: Binding<String>,
7174
action: @escaping () -> Void = {}
7275
) -> some View {
7376
self.modifier(
7477
MultilineSubmitViewModifier(
7578
text: text,
76-
submitLabel: submitLabel,
77-
onSubmit: action
79+
action: action
7880
)
7981
)
8082
}

0 commit comments

Comments
 (0)