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

Sync with upstream. #1

Merged
merged 30 commits into from
Jul 2, 2020
Merged
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cbfee17
Make title and error labels independent.
Jan 2, 2019
43a9aff
Code clean-up.
Jan 3, 2019
0778c01
Added errorMessageAlignment option.
Jan 7, 2019
c228a9c
Added comments for new public/open vars.
Feb 18, 2019
e008447
Fixed errorLabel.textAlignment.
Feb 18, 2019
348a556
Added updateErrorLabelColor to updateColors.
Feb 18, 2019
8f9f2ad
Fixed comment about errorColor property.
Feb 18, 2019
807edec
ErrorMessagePlacement: Changed some symbol names to be more Swifty, a…
jaredegan Feb 18, 2019
f173076
Merge pull request #1 from gas-buddy/cusomizations-tweaks
spencerdiniz Feb 18, 2019
f83f1bc
Add example of "errorMessagePlacement" property at the "Setting text …
junioreder May 3, 2019
4908d6a
migrated project to swift 5, added swift 5 build target to travis ci,…
Jun 10, 2019
8f0c6a6
enabled xcode recommended build settings, constituting of just extra …
Jun 10, 2019
f955b89
downgraded bundler version used
Jun 10, 2019
8c1f1ce
inverted swift version conditionals to fix build issue on older versi…
Jun 10, 2019
1a6c155
Added full support for the swift package manager
acecilia Sep 1, 2019
8735603
Merge pull request #290 from jessemx109/swift5
k0nserv Dec 5, 2019
24e84c4
[Podpsec] Revert version to 3.7.0 until release
k0nserv Dec 5, 2019
9cfbd12
[CHANGELOG] Update changelog for Swift 5
k0nserv Dec 5, 2019
4010938
Merge pull request #296 from acecilia/feature/swift-package-manager
k0nserv Dec 5, 2019
bc9eb88
[CHANGELOG] Update CHANGELOG for SPM support
k0nserv Dec 5, 2019
029e3e0
[Gems] Update gmes
k0nserv Dec 5, 2019
9c43ba8
[Release] New tag strategy
k0nserv Dec 5, 2019
6c9a451
[podspec] Use the right method
k0nserv Dec 5, 2019
a90b87d
[Rakefile] Update default SDK/Simulator
k0nserv Dec 5, 2019
d988011
[podspec] Stringify verison
k0nserv Dec 5, 2019
82c0bbb
[Release] Version 3.8.0
k0nserv Dec 5, 2019
981eafa
Merge branch 'master' into customizations
junioreder Dec 18, 2019
365fa35
FIX swiftLint warnings and errors
junioreder Dec 18, 2019
73ef34b
DEV Update bundler version
junioreder Dec 18, 2019
dd82b26
Merge pull request #271 from rethink-eder/customizations
k0nserv Jan 7, 2020
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
Original file line number Diff line number Diff line change
@@ -187,6 +187,19 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
XCTAssertEqual(floatingLabelTextField.lineView.backgroundColor, self.customColor)
}

func test_whenSettingErrorColor_withErrorMessagePlacementIsBottom_thenErrorLabelTextColorIsChangedToThisColor() {
// given
floatingLabelTextField.errorMessagePlacement = .bottom
floatingLabelTextField.errorMessage = "test"

// when
floatingLabelTextField.errorColor = self.customColor

// then
XCTAssertNotEqual(floatingLabelTextField.titleLabel.textColor, self.customColor)
XCTAssertEqual(floatingLabelTextField.errorLabel.textColor, self.customColor)
}

func test_whenSettingSelectedTitleColor_withTextfieldBeingSelected_thenTitleLabelTextColorIsChangedToThisColor() {
// given
floatingLabelTextField.isSelected = true
@@ -895,6 +908,42 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
XCTAssertEqual(size.height, floatingLabelTextField.titleHeight() + floatingLabelTextField.textHeight())
}

// MARK: Error Message Placement
func test_whenSettingErrorMessage_whenErrorMessagePlacementSetToDefault_thenTitleLabelTextIsChanged() {
// given
XCTAssertEqual(floatingLabelTextField.errorMessagePlacement, .default)

// when
floatingLabelTextField.errorMessage = "SAMPLE ERROR"

// then
XCTAssertEqual(floatingLabelTextField.titleLabel.text, "SAMPLE ERROR")
}

func test_whenSettingErrorMessage_whenErrorMessagePlacementSetToBottom_thenErrorLabelTextIsChanged() {
// given
floatingLabelTextField.title = "SAMPLE TITLE"
floatingLabelTextField.errorMessagePlacement = .bottom

// when
floatingLabelTextField.errorMessage = "SAMPLE ERROR"

// then
XCTAssertEqual(floatingLabelTextField.titleLabel.text, "SAMPLE TITLE")
XCTAssertEqual(floatingLabelTextField.errorLabel.text, "SAMPLE ERROR")
}

func test_whenErrorLabelAlignment_thenErrorLabelTextAlignemntIsChanged() {
// given
XCTAssertNotEqual(floatingLabelTextField.errorLabel.textAlignment, .center)

// when
floatingLabelTextField.errorLabelAlignment = .center

// then
XCTAssertEqual(floatingLabelTextField.errorLabel.textAlignment, .center)
}

// MARK: - Helpers

func failOnTimeoutAfterSeconds(_ timeout: TimeInterval) {
65 changes: 30 additions & 35 deletions Sources/SkyFloatingLabelTextField.swift
Original file line number Diff line number Diff line change
@@ -12,13 +12,13 @@
import UIKit

/**
An enum for the possible error labe placements.
.defaultPlacement is the standard (on top) position
.bottomPlacement positions error label below the text field.
An enum for the possible error label placements.
.default is the standard (on top) position; the error message is displayed in the `titleLabel`.
.bottom displays the error below the text field in a dedicated `errorLabel`.
*/
public enum ErrorLabelPlacement {
case defaultPlacement
case bottomPlacement
public enum ErrorMessagePlacement {
case `default`
case bottom
}

/**
@@ -47,9 +47,9 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
errorLabel.textAlignment = .right
}

//Override error message default alignment
if let errorMessageAlignment = errorMessageAlignment {
errorLabel.textAlignment = errorMessageAlignment
// Override error message default alignment
if let errorLabelAlignment = errorLabelAlignment {
errorLabel.textAlignment = errorLabelAlignment
}
}

@@ -90,16 +90,16 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
}
}

/// A ErrorLabelPlacement value that determines where the error label will be placed.
open var errorMessagePlacement: ErrorLabelPlacement = .defaultPlacement {
/// A `ErrorMessagePlacement` value that determines where the error message will be displayed.
open var errorMessagePlacement: ErrorMessagePlacement = .default {
didSet {
updateControl()
updatePlaceholder()
}
}

// An NSTextAlignment value that determines the error message alignment.
open var errorMessageAlignment: NSTextAlignment? {
/// An `NSTextAlignment` value that determines the error label text alignment.
open var errorLabelAlignment: NSTextAlignment? {
didSet {
updateTextAligment()
}
@@ -153,7 +153,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
}
}

/// A UIColor value that determines the color used for the error label
/// A UIColor value that determines the color used for the label displaying the error message
@IBInspectable dynamic open var errorColor: UIColor = .red {
didSet {
updateColors()
@@ -229,7 +229,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
/// The internal `UILabel` that displays the selected, deselected title or error message based on the current state.
open var titleLabel: UILabel!

/// The internal `UILabel` that displays error messsage if errorMessagePlacement is .bottomPlacement.
/// The internal `UILabel` that displays error messsage if `errorMessagePlacement` is `.bottom`.
open var errorLabel: UILabel!

// MARK: Properties
@@ -509,7 +509,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty

if !isEnabled {
titleLabel.textColor = disabledColor
} else if hasErrorMessage && errorMessagePlacement == .defaultPlacement {
} else if hasErrorMessage && errorMessagePlacement == .default {
titleLabel.textColor = titleErrorColor ?? errorColor
} else {
if editingOrSelected || isHighlighted {
@@ -540,7 +540,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
var titleText: String?
var errorText: String?

if errorMessagePlacement == .defaultPlacement {
if errorMessagePlacement == .default {
if hasErrorMessage {
titleText = titleFormatter(errorMessage!)
} else {
@@ -553,8 +553,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
titleText = titleOrPlaceholder()
}
}
}
else {
} else {
if hasErrorMessage {
errorText = titleFormatter(errorMessage!)
}
@@ -602,10 +601,9 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
- returns: True if the title is displayed on the control, false otherwise.
*/
open func isTitleVisible() -> Bool {
if errorMessagePlacement == .defaultPlacement {
if errorMessagePlacement == .default {
return hasText || hasErrorMessage || _titleVisible
}
else {
} else {
return hasText || _titleVisible
}
}
@@ -673,7 +671,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty

var height = superRect.size.height - titleHeight - selectedLineHeight

if errorMessagePlacement == .bottomPlacement {
if errorMessagePlacement == .bottom {
height = height - errorHeight()
}

@@ -697,7 +695,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty

var height = superRect.size.height - titleHeight - selectedLineHeight

if errorMessagePlacement == .bottomPlacement {
if errorMessagePlacement == .bottom {
height = height - errorHeight()
}

@@ -718,7 +716,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
var height = bounds.size.height - titleHeight() - selectedLineHeight

if errorMessagePlacement == .bottomPlacement {
if errorMessagePlacement == .bottom {
height = height - errorHeight()
}

@@ -753,10 +751,9 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
- returns: The rectangle that the title label should render in
*/
open func errorLabelRectForBounds(_ bounds: CGRect, editing: Bool) -> CGRect {
if errorMessagePlacement == .defaultPlacement {
if errorMessagePlacement == .default {
return CGRect.zero
}
else {
} else {
let lineRect = lineViewRectForBounds(bounds, editing: editing)

if editing {
@@ -777,10 +774,9 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
open func lineViewRectForBounds(_ bounds: CGRect, editing: Bool) -> CGRect {
let height = editing ? selectedLineHeight : lineHeight

if errorMessagePlacement == .bottomPlacement {
if errorMessagePlacement == .bottom {
return CGRect(x: 0, y: textRect(forBounds: bounds).maxY, width: bounds.size.width, height: height)
}
else {
} else {
return CGRect(x: 0, y: bounds.size.height - height, width: bounds.size.width, height: height)
}
}
@@ -810,7 +806,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
}

/**
Calcualte the height of the textfield.
Calculate the height of the textfield.
-returns: the calculated height of the textfield. Override to size the textfield with a different height
*/
open func textHeight() -> CGFloat {
@@ -852,10 +848,9 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
- returns: the content size to be used for auto layout
*/
override open var intrinsicContentSize: CGSize {
if errorMessagePlacement == .bottomPlacement {
if errorMessagePlacement == .bottom {
return CGSize(width: bounds.size.width, height: titleHeight() + textHeight() + errorHeight())
}
else {
} else {
return CGSize(width: bounds.size.width, height: titleHeight() + textHeight())
}
}