     private func commonInit() {
         self.modalPresentationStyle = .custom
         self.transitioningDelegate = self.transitionDelegate
-    }
-
-    public override func viewWillDisappear(_ animated: Bool) {
-        super.viewWillDisappear(animated)
-        self.textFields?.first?.resignFirstResponder()
+
+        if self.preferredStyle == .alert {
+            let command = UIKeyCommand(input: "\r", modifierFlags: [],
+                                       action: #selector(self.handleHardwareReturnKey))
+            self.addKeyCommand(command)
+        }
     }
 
     // MARK: - Public

    }

    // MARK: - Private

    private func listenForKeyboardChanges() {
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardChange),

        self.configureAlertView()
    }

    public override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.textFields?.first?.resignFirstResponder()
    }

    public override var preferredStatusBarStyle: UIStatusBarStyle {
        return self.presentingViewController?.preferredStatusBarStyle ?? .default
    }
