material-components_materia.../components/TextFields/examples/experimental/InputTextFieldStoryboardExampleViewController.swift
Andrew Overton c56d5d76d3
Add @objc annotations to get examples to show up in Dragons (#7168)
This is a follow up PR for #7166 adds @objc annotations to Swift catalogMetadata() methods, because the Swift 4 compiler no longer attempts to infer what methods should be visible to Objective-C. As a result of this change in the compiler, no Swift examples were showing up in Dragons after #7166. See this article: https://useyourloaf.com/blog/objc-warnings-upgrading-to-swift-4/ for additional context.
2019-04-17 21:35:43 -04:00

109 lines
3.1 KiB
Swift

// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import UIKit
final class SimpleTextFieldStoryboardExampleViewController: UIViewController {
@IBOutlet var filledTextField: UITextField!
@IBOutlet weak var outlinedTextField: UITextField!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func viewDidLoad() {
super.viewDidLoad()
registerKeyboardNotifications()
}
}
extension SimpleTextFieldStoryboardExampleViewController: UITextFieldDelegate {
func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
return true
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
return false
}
}
extension SimpleTextFieldStoryboardExampleViewController: UITextViewDelegate {
func textViewDidEndEditing(_ textView: UITextView) {
print(textView.text)
}
}
// MARK: - Keyboard Handling
extension SimpleTextFieldStoryboardExampleViewController {
func registerKeyboardNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(
self,
selector: #selector(keyboardWillShow(notif:)),
name: UIResponder.keyboardWillShowNotification,
object: nil)
notificationCenter.addObserver(
self,
selector: #selector(keyboardWillHide(notif:)),
name: UIResponder.keyboardWillHideNotification,
object: nil)
notificationCenter.addObserver(
self,
selector: #selector(keyboardWillShow(notif:)),
name: UIResponder.keyboardWillChangeFrameNotification,
object: nil)
}
@objc func keyboardWillShow(notif: Notification) {
guard let _ = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}
}
@objc func keyboardWillHide(notif: Notification) {
}
}
// MARK: - Status Bar Style
extension SimpleTextFieldStoryboardExampleViewController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
// MARK: - CatalogByConvention
extension SimpleTextFieldStoryboardExampleViewController {
@objc class func catalogMetadata() -> [String: Any] {
return [
"breadcrumbs": ["Text Field", "Input Text Field (Storyboard)"],
"description": "Text fields let users enter and edit text.",
"primaryDemo": false,
"presentable": false,
"storyboardName": "SimpleTextFieldStoryboardExampleViewController"
]
}
}