Small Settings QOL improvements
This commit is contained in:
@@ -32,18 +32,45 @@ struct TextFieldContentConfiguration : UIContentConfiguration
|
|||||||
{
|
{
|
||||||
var text: String = ""
|
var text: String = ""
|
||||||
var placeholderText: String? = nil
|
var placeholderText: String? = nil
|
||||||
var textChanged: ((String) -> Void)
|
var textChanged: ((String) -> Void)? = nil
|
||||||
|
var pressedReturn: ((UITextField) -> Void)? = nil
|
||||||
|
var keyboardType: UIKeyboardType = .default
|
||||||
|
var returnKeyType: UIReturnKeyType = .default
|
||||||
|
|
||||||
func makeContentView() -> UIView & UIContentView {
|
func makeContentView() -> UIView & UIContentView {
|
||||||
let textField = UITextField(frame: .zero)
|
let textField = UITextField(frame: .zero)
|
||||||
textField.borderStyle = .roundedRect
|
textField.borderStyle = .roundedRect
|
||||||
textField.autocorrectionType = .no
|
textField.autocorrectionType = .no
|
||||||
textField.autocapitalizationType = .none
|
textField.autocapitalizationType = .none
|
||||||
|
textField.keyboardType = keyboardType
|
||||||
|
textField.returnKeyType = returnKeyType
|
||||||
|
|
||||||
return GenericContentView<UITextField, TextFieldContentConfiguration>(configuration: self, view: textField) { config, textField in
|
return GenericContentView<UITextField, TextFieldContentConfiguration>(configuration: self, view: textField) { config, textField in
|
||||||
textField.text = config.text
|
textField.text = config.text
|
||||||
textField.placeholder = config.placeholderText
|
textField.placeholder = config.placeholderText
|
||||||
textField.addAction(UIAction { _ in config.textChanged(textField.text ?? "") }, for: .editingChanged)
|
|
||||||
|
if let textChanged = config.textChanged {
|
||||||
|
textField.addAction(UIAction { _ in textChanged(textField.text ?? "") }, for: .editingChanged)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let pressedReturn = config.pressedReturn {
|
||||||
|
class ReturnDelegate : NSObject, UITextFieldDelegate {
|
||||||
|
var pressedReturn: ((UITextField) -> Void)
|
||||||
|
|
||||||
|
public init(pressedReturn: @escaping ((UITextField) -> Void)) {
|
||||||
|
self.pressedReturn = pressedReturn
|
||||||
|
}
|
||||||
|
|
||||||
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||||
|
pressedReturn(textField)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let delegate = ReturnDelegate(pressedReturn: pressedReturn)
|
||||||
|
objc_setAssociatedObject(textField, "returnDelegate", delegate, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||||
|
textField.delegate = delegate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +200,10 @@ class GeneralSettingsViewController: UIViewController
|
|||||||
placeholderText: "https://sync.server.com",
|
placeholderText: "https://sync.server.com",
|
||||||
textChanged: { newString in
|
textChanged: { newString in
|
||||||
Settings.shared.syncServer = newString
|
Settings.shared.syncServer = newString
|
||||||
}
|
},
|
||||||
|
pressedReturn: { $0.resignFirstResponder() },
|
||||||
|
keyboardType: .URL,
|
||||||
|
returnKeyType: .done
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +233,7 @@ class GeneralSettingsViewController: UIViewController
|
|||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
|
||||||
|
collectionView.delegate = self
|
||||||
tabBarItem.title = "General"
|
tabBarItem.title = "General"
|
||||||
tabBarItem.image = UIImage(systemName: "gear")
|
tabBarItem.image = UIImage(systemName: "gear")
|
||||||
}
|
}
|
||||||
@@ -228,3 +259,9 @@ class GeneralSettingsViewController: UIViewController
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension GeneralSettingsViewController : UICollectionViewDelegate {
|
||||||
|
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -229,13 +229,19 @@ class CreateRedirectRuleViewController: UICollectionViewController
|
|||||||
|
|
||||||
sectionHeaderImageView.contentMode = .scaleAspectFit
|
sectionHeaderImageView.contentMode = .scaleAspectFit
|
||||||
|
|
||||||
fromHostField.placeholder = "https://fromhostname.com"
|
fromHostField.placeholder = "fromhostname.com"
|
||||||
fromHostField.autocorrectionType = .no
|
fromHostField.autocorrectionType = .no
|
||||||
fromHostField.autocapitalizationType = .none
|
fromHostField.autocapitalizationType = .none
|
||||||
|
fromHostField.keyboardType = .URL
|
||||||
|
fromHostField.returnKeyType = .next
|
||||||
|
fromHostField.delegate = self
|
||||||
|
|
||||||
toHostField.placeholder = "https://tohostname.com"
|
toHostField.placeholder = "tohostname.com"
|
||||||
toHostField.autocorrectionType = .no
|
toHostField.autocorrectionType = .no
|
||||||
toHostField.autocapitalizationType = .none
|
toHostField.autocapitalizationType = .none
|
||||||
|
toHostField.keyboardType = .URL
|
||||||
|
toHostField.returnKeyType = .done
|
||||||
|
toHostField.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
@@ -256,3 +262,15 @@ class CreateRedirectRuleViewController: UICollectionViewController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CreateRedirectRuleViewController : UITextFieldDelegate {
|
||||||
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||||
|
if textField == fromHostField {
|
||||||
|
toHostField.becomeFirstResponder()
|
||||||
|
} else if textField == toHostField {
|
||||||
|
toHostField.resignFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user