Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAPBF-457: SMETextField improvements #62

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.5.2",
"release_notes": "Imported `SpreadsheetView` library into codebase"
"version": "1.5.3",
"release_notes": "Added attributedText and tapGesture to footerLabel in SMETextField and added onDoneButtonClicked callback to Keyboard "
}
8 changes: 8 additions & 0 deletions Sources/PashaKit/Extensions/UIColor+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ extension UIColor {
}
}

static var SMETextFieldPlaceholder: UIColor {
return UIColor { (traits) -> UIColor in
return traits.userInterfaceStyle == .dark ?
UIColor(red: 0.922, green: 0.922, blue: 0.961, alpha: 0.6) :
UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.6)
}
}

static var SMETextFieldLabelDisabled: UIColor {
return UIColor { (traits) -> UIColor in
return traits.userInterfaceStyle == .dark ?
Expand Down
63 changes: 55 additions & 8 deletions Sources/PashaKit/PashaBusiness/TextFields/SMETextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ public class SMETextField: UIView {
}
}

/// The attributed text which is displayed under the text field.
///
/// By default text field doesn't create footer label attributed text. If you specify it, text field will be
/// created with the `UILabel` under it.
///

public var footerLabelAttributedText: NSAttributedString? = nil {
didSet {
self.footerLabel.attributedText = self.footerLabelAttributedText
}
}

/// The text which is displayed under the text field.
///
/// By default text field doesn't create footer label text. If you specify it, text field will be
Expand Down Expand Up @@ -315,7 +327,7 @@ public class SMETextField: UIView {
///
/// By default this property will apply black color with alpha value of `0.6`.
///
public var placeholderTextColor: UIColor = UIColor.Colors.SMETextFieldLabel {
public var placeholderTextColor: UIColor = UIColor.Colors.SMETextFieldPlaceholder {
didSet {
if self.placeholderTextColor != oldValue {
self.customPlaceholder.textColor = self.placeholderTextColor
Expand Down Expand Up @@ -369,9 +381,15 @@ public class SMETextField: UIView {
///
public var disableManualInput: Bool = false {
didSet {
self.customTextField.isUserInteractionEnabled = false
self.placeholderTextColor = UIColor.Colors.SMETextFieldLabelDisabled
self.textFieldTextColor = self.placeholderTextColor
if disableManualInput {
self.customTextField.isUserInteractionEnabled = false
self.placeholderTextColor = UIColor.Colors.SMETextFieldLabelDisabled
self.textFieldTextColor = self.placeholderTextColor
} else {
self.customTextField.isUserInteractionEnabled = true
self.placeholderTextColor = UIColor.Colors.SMETextFieldLabel
self.textFieldTextColor = UIColor.Colors.SMETextFieldText
}
}
}

Expand Down Expand Up @@ -459,7 +477,7 @@ public class SMETextField: UIView {
return delegate
}()

private let topPadding: CGFloat = 8.0
private let topPadding: CGFloat = 14.0
private let placeholderFont = UIFont.systemFont(ofSize: 17, weight: .regular)
private let placeholderSizeFactor: CGFloat = 0.73
private let leftPadding: CGFloat = 16
Expand Down Expand Up @@ -564,7 +582,8 @@ public class SMETextField: UIView {
view.numberOfLines = 0
view.translatesAutoresizingMaskIntoConstraints = false
view.textColor = self.placeholderTextColor

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onFooterLabelTap))
view.addGestureRecognizer(tapGestureRecognizer)
return view
}()

Expand Down Expand Up @@ -1100,6 +1119,15 @@ public class SMETextField: UIView {
break
}
}

@objc private func onFooterLabelTap() {
self.onFooterLabelPressed?()
}

@objc private func onKeyboardDoneButtonTapped() {
self.customTextField.resignFirstResponder()
self.onDoneButtonClicked?()
}

/// Changes input accessory view with given view
///
Expand Down Expand Up @@ -1164,7 +1192,18 @@ public class SMETextField: UIView {
}

public func addDoneButtonOnKeyboard(title: String) {
self.customTextField.addDoneButtonOnKeyboard(title: title)

let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
doneToolbar.barStyle = .default

let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: title, style: .done, target: self, action: #selector(self.onKeyboardDoneButtonTapped))
done.tintColor = UIColor.Colors.SMEGreen
let items = [flexSpace, done]
doneToolbar.items = items
doneToolbar.sizeToFit()

self.customTextField.inputAccessoryView = doneToolbar
}

/// Resigns text field from being first responder.
Expand All @@ -1178,11 +1217,19 @@ public class SMETextField: UIView {
}

// MARK: - INPUT DELEGATES

/// Get called when entered text updates.
///
public var onTextUpdate: ((String) -> Void)?

/// Get called when done button clicked on keyboard.
///
public var onDoneButtonClicked: (() -> Void)?

/// Get called when tapped footer label.
///
public var onFooterLabelPressed: (() -> Void)?

/// Gets called when text is setted to field.
///
public var onTextSetted: ((String) -> Void)?
Expand Down
Loading