Improve dial pad screen with new config

This commit is contained in:
ismailgulek
2021-01-21 21:26:12 +03:00
parent 4bed157a69
commit a00a33e66a
3 changed files with 42 additions and 6 deletions
@@ -20,6 +20,12 @@ import Foundation
@objcMembers
class DialpadConfiguration: NSObject {
/// Option for a dial pad to show the title or not.
var showsTitle: Bool
/// Option for a dial pad to show the close button or not.
var showsCloseButton: Bool
/// Option for a dial pad to show the backspace button or not.
var showsBackspaceButton: Bool
@@ -35,10 +41,14 @@ class DialpadConfiguration: NSObject {
/// Default configuration object. All options are enabled by default.
static let `default`: DialpadConfiguration = DialpadConfiguration()
init(showsBackspaceButton: Bool = true,
init(showsTitle: Bool = true,
showsCloseButton: Bool = true,
showsBackspaceButton: Bool = true,
showsCallButton: Bool = true,
formattingEnabled: Bool = true,
editingEnabled: Bool = true) {
self.showsTitle = showsTitle
self.showsCloseButton = showsCloseButton
self.showsBackspaceButton = showsBackspaceButton
self.showsCallButton = showsCallButton
self.formattingEnabled = formattingEnabled
@@ -291,6 +291,8 @@
<outlet property="digitsStackView" destination="fnQ-jm-HT2" id="ltK-Bg-hwY"/>
<outlet property="lineView" destination="iak-30-PMd" id="T6L-kl-Dsy"/>
<outlet property="phoneNumberTextField" destination="iWR-Bv-qzs" id="ezn-FP-ihl"/>
<outlet property="phoneNumberTextFieldTopConstraint" destination="nkS-49-CiR" id="Anh-q0-26b"/>
<outlet property="spaceButton" destination="Xig-ln-gBC" id="tJi-AD-WOu"/>
<outlet property="titleLabel" destination="ObS-Bw-Z12" id="0ZH-xI-zhw"/>
</connections>
</viewController>
@@ -22,7 +22,7 @@ import libPhoneNumber_iOS
@objc protocol DialpadViewControllerDelegate: class {
@objc optional func dialpadViewControllerDidTapCall(_ viewController: DialpadViewController,
withPhoneNumber phoneNumber: String)
func dialpadViewControllerDidTapClose(_ viewController: DialpadViewController)
@objc optional func dialpadViewControllerDidTapClose(_ viewController: DialpadViewController)
@objc optional func dialpadViewControllerDidTapDigit(_ viewController: DialpadViewController, digit: String)
}
@@ -32,8 +32,23 @@ class DialpadViewController: UIViewController {
// MARK: Outlets
@IBOutlet private weak var closeButton: UIButton!
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var phoneNumberTextFieldTopConstraint: NSLayoutConstraint! {
didSet {
if !configuration.showsTitle && !configuration.showsCloseButton {
phoneNumberTextFieldTopConstraint.constant = 0
}
}
}
@IBOutlet private weak var closeButton: UIButton! {
didSet {
closeButton.isHidden = !configuration.showsCloseButton
}
}
@IBOutlet private weak var titleLabel: UILabel! {
didSet {
titleLabel.isHidden = !configuration.showsTitle
}
}
@IBOutlet private weak var phoneNumberTextField: UITextField! {
didSet {
phoneNumberTextField.text = nil
@@ -57,6 +72,11 @@ class DialpadViewController: UIViewController {
callButton.isHidden = !configuration.showsCallButton
}
}
@IBOutlet private weak var spaceButton: UIButton! {
didSet {
spaceButton.isHidden = !configuration.showsBackspaceButton || !configuration.showsCallButton
}
}
// MARK: Private
@@ -81,7 +101,7 @@ class DialpadViewController: UIViewController {
}
}
/// Phone number as non-formatted
private var rawPhoneNumber: String {
var rawPhoneNumber: String {
return phoneNumber.vc_removingAllWhitespaces()
}
private var theme: Theme!
@@ -229,7 +249,7 @@ class DialpadViewController: UIViewController {
}
@IBAction private func closeButtonAction(_ sender: UIButton) {
delegate?.dialpadViewControllerDidTapClose(self)
delegate?.dialpadViewControllerDidTapClose?(self)
}
@IBAction private func digitButtonAction(_ sender: DialpadButton) {
@@ -269,6 +289,10 @@ class DialpadViewController: UIViewController {
}
@IBAction private func backspaceButtonAction(_ sender: DialpadActionButton) {
defer {
delegate?.dialpadViewControllerDidTapDigit?(self, digit: "")
}
if phoneNumber.isEmpty {
return
}