Skip to content

Commit b42061a

Browse files
authored
Added option for whether the system automatically enables the Return key (#23)
- The default value for this property is false. If you set it to true, the keyboard disables the Return key when the text entry area contains no text. As soon as the user enters some text, the Return key is automatically enabled. https://developer.apple.com/documentation/uikit/uitextinputtraits/enablesreturnkeyautomatically
1 parent 4511dd0 commit b42061a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/ResponsiveTextField/ResponsiveTextField.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public struct ResponsiveTextField {
2424
/// some external state.
2525
let isSecure: Bool
2626

27+
/// Enables return key automatically.
28+
let enablesReturnKeyAutomatically: Bool
29+
2730
/// Can be used to programatically control the text field's first responder state.
2831
///
2932
/// When the binding's wrapped value is set, it will cause the text field to try and become or resign first responder status
@@ -130,6 +133,7 @@ public struct ResponsiveTextField {
130133
placeholder: String?,
131134
text: Binding<String>,
132135
isSecure: Bool = false,
136+
enablesReturnKeyAutomatically: Bool = false,
133137
adjustsFontForContentSizeCategory: Bool = true,
134138
firstResponderDemand: Binding<FirstResponderDemand?>? = nil,
135139
configuration: Configuration = .empty,
@@ -144,6 +148,7 @@ public struct ResponsiveTextField {
144148
self.text = text
145149
self.firstResponderDemand = firstResponderDemand
146150
self.isSecure = isSecure
151+
self.enablesReturnKeyAutomatically = enablesReturnKeyAutomatically
147152
self.configuration = configuration
148153
self.adjustsFontForContentSizeCategory = adjustsFontForContentSizeCategory
149154
self.onFirstResponderStateChanged = onFirstResponderStateChanged
@@ -329,6 +334,7 @@ extension ResponsiveTextField: UIViewRepresentable {
329334
textField.text = text.wrappedValue
330335
textField.isEnabled = isEnabled
331336
textField.isSecureTextEntry = isSecure
337+
textField.enablesReturnKeyAutomatically = enablesReturnKeyAutomatically
332338
textField.font = font
333339
textField.adjustsFontForContentSizeCategory = adjustsFontForContentSizeCategory
334340
textField.textColor = textColor
@@ -364,6 +370,7 @@ extension ResponsiveTextField: UIViewRepresentable {
364370
public func updateUIView(_ uiView: UITextField, context: Context) {
365371
uiView.isEnabled = isEnabled
366372
uiView.isSecureTextEntry = isSecure
373+
uiView.enablesReturnKeyAutomatically = enablesReturnKeyAutomatically
367374
uiView.returnKeyType = returnKeyType
368375
uiView.text = text.wrappedValue
369376
uiView.textColor = textColor

0 commit comments

Comments
 (0)