Skip to content

Commit 53339fb

Browse files
committed
AddANoteViewController: becomeFirstResponder on viewDidAppear / resign on viewWillDisappear
1 parent 37c9736 commit 53339fb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

WooCommerce/Classes/Extensions/UIView+Helpers.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import UIKit
33

44

5-
/// UIView Helper Methods
5+
/// UIView Class Methods
66
///
77
extension UIView {
88

@@ -19,3 +19,23 @@ extension UIView {
1919
return loadNib().instantiate(withOwner: nil, options: nil).first as! T
2020
}
2121
}
22+
23+
24+
/// UIView Extension Methods
25+
///
26+
extension UIView {
27+
28+
/// Returns the first Subview of the specified Type (if any).
29+
///
30+
func firstSubview<T: UIView>(ofType type: T.Type) -> T? {
31+
for subview in subviews {
32+
guard let target = (subview as? T) ?? subview.firstSubview(ofType: type) else {
33+
continue
34+
}
35+
36+
return target
37+
}
38+
39+
return nil
40+
}
41+
}

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/AddNote/AddANoteViewController.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ class AddANoteViewController: UIViewController {
2727
loadSections()
2828
}
2929

30+
override func viewDidAppear(_ animated: Bool) {
31+
super.viewDidAppear(animated)
32+
tableView.firstSubview(ofType: UITextView.self)?.becomeFirstResponder()
33+
}
34+
35+
override func viewWillDisappear(_ animated: Bool) {
36+
super.viewWillDisappear(animated)
37+
view.endEditing(true)
38+
}
39+
3040
func configureNavigation() {
3141
title = NSLocalizedString("Order #\(viewModel.order.number)", comment: "Add a note screen - title. Example: Order #15")
3242

0 commit comments

Comments
 (0)