Skip to content

Commit fdc5938

Browse files
authored
Fix: Unable to dismiss keyboard when editing Product Title (#16288)
2 parents 0865397 + 2f76cda commit fdc5938

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
23.6
55
-----
66
- [*] Handle sites configured with `http` siteAddress.
7+
- [*] Fix: Unable to dismiss keyboard when editing Product Title. [https://github.com/woocommerce/woocommerce-ios/pull/16288]
78

89
23.5
910
-----

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormTableViewDataSource.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ private extension ProductFormTableViewDataSource {
208208
productStatus: productStatus,
209209
placeholder: placeholder,
210210
textViewMinimumHeight: 10.0,
211+
shouldDismissOnReturn: true,
211212
isScrollEnabled: false,
212213
onNameChange: { [weak self] (newName) in self?.onNameChange?(newName) },
213214
style: .headline)

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ private extension ProductFormViewController {
645645
tableView.delegate = self
646646
tableView.accessibilityIdentifier = "product-form"
647647
tableView.cellLayoutMarginsFollowReadableWidth = true
648+
tableView.keyboardDismissMode = .onDrag
648649

649650
tableView.backgroundColor = .listForeground(modal: false)
650651
tableView.removeLastCellSeparator()

WooCommerce/Classes/ViewRelated/ReusableViews/EnhancedTextView.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ final class EnhancedTextView: UITextView {
66

77
var onTextChange: ((String) -> Void)?
88
var onTextDidBeginEditing: (() -> Void)?
9+
var shouldDismissOnReturn: Bool = false
910

1011
var placeholder: String? {
1112
didSet {
@@ -84,6 +85,18 @@ private extension EnhancedTextView {
8485
//
8586
extension EnhancedTextView: UITextViewDelegate {
8687

88+
func textView(_ textView: UITextView,
89+
shouldChangeTextIn range: NSRange,
90+
replacementText text: String) -> Bool {
91+
92+
if shouldDismissOnReturn && text == "\n" {
93+
textView.resignFirstResponder()
94+
return false
95+
}
96+
97+
return true
98+
}
99+
87100
func textViewDidBeginEditing(_ textView: UITextView) {
88101
hidePlaceholder()
89102
onTextDidBeginEditing?()

WooCommerce/Classes/ViewRelated/ReusableViews/LabeledTextViewTableViewCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ final class LabeledTextViewTableViewCell: UITableViewCell {
88
var productStatus: ProductStatus
99
var placeholder: String? = nil
1010
var textViewMinimumHeight: CGFloat? = nil
11+
var shouldDismissOnReturn: Bool = false
1112
var isScrollEnabled: Bool = true
12-
var keyboardType: UIKeyboardType = .default
1313
var onNameChange: ((_ text: String) -> Void)? = nil
1414
var onTextDidBeginEditing: (() -> Void)? = nil
1515
var style: Style = .headline
@@ -33,7 +33,7 @@ final class LabeledTextViewTableViewCell: UITableViewCell {
3333
productTextField.isScrollEnabled = viewModel.isScrollEnabled
3434
productTextField.onTextChange = viewModel.onNameChange
3535
productTextField.onTextDidBeginEditing = viewModel.onTextDidBeginEditing
36-
productTextField.keyboardType = viewModel.keyboardType
36+
productTextField.shouldDismissOnReturn = viewModel.shouldDismissOnReturn
3737
configureProductStatusLabel(productStatus: viewModel.productStatus)
3838
applyStyle(style: viewModel.style)
3939
}

0 commit comments

Comments
 (0)