@@ -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
6055public 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