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

Abstract hint service #106

Merged
merged 6 commits into from Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -74,12 +74,6 @@ private extension BoxTextField {
normal: Color.UnderlineTextField.text,
active: Color.UnderlineTextField.text,
disabled: Color.UnderlineTextField.placeholder))
configuration.hint = HintConfiguration(font: UIFont.systemFont(ofSize: 13, weight: .regular),
lineHeight: 17,
colors: ColorConfiguration(error: Color.UnderlineTextField.error,
normal: Color.UnderlineTextField.placeholder,
active: Color.UnderlineTextField.placeholder,
disabled: Color.UnderlineTextField.placeholder))
configuration.passwordMode = PasswordModeConfiguration(secureModeOnImage: UIImage(asset: Asset.customEyeOn),
secureModeOffImage: UIImage(asset: Asset.customEyeOff),
normalColor: Color.UnderlineTextField.ActionButton.normal,
Expand All @@ -92,7 +86,16 @@ private extension BoxTextField {
insets: UIEdgeInsets(top: 13, left: 16, bottom: 0, right: 16),
colors: ColorConfiguration(color: Color.UnderlineTextField.placeholder))
self.setup(placeholderServices: [StaticPlaceholderService(configuration: placeholderConfig)])
self.heightLayoutPolicy = .elastic(minHeight: 130, bottomSpace: 5, ignoreEmptyHint: false)
self.setup(hintService: HintService(configuration: .init(font: UIFont.systemFont(ofSize: 13, weight: .regular),
lineHeight: 17,
colors: ColorConfiguration(error: Color.UnderlineTextField.error,
normal: Color.UnderlineTextField.placeholder,
active: Color.UnderlineTextField.placeholder,
disabled: Color.UnderlineTextField.placeholder)),
visibleHintStates: .all))
self.heightLayoutPolicy = .elastic(policy: .init(minHeight: 130,
bottomOffset: 5,
ignoreEmptyHint: false))
self.validationPolicy = .always
}

Expand Down
Expand Up @@ -103,12 +103,6 @@ private extension SumTextField {
normal: Color.UnderlineTextField.text,
active: Color.UnderlineTextField.text,
disabled: Color.UnderlineTextField.placeholder))
configuration.hint = HintConfiguration(font: UIFont.systemFont(ofSize: 13, weight: .regular),
lineHeight: 17,
colors: ColorConfiguration(error: Color.UnderlineTextField.error,
normal: Color.UnderlineTextField.placeholder,
active: Color.UnderlineTextField.placeholder,
disabled: Color.UnderlineTextField.placeholder))
configuration.background = BackgroundConfiguration(color: Color.Main.background)
self.configuration = configuration

Expand All @@ -127,8 +121,15 @@ private extension SumTextField {
self.supportPlaceholderService = supportPlaceholderService
self.setup(placeholderServices: [StaticPlaceholderService(configuration: staticPlaceholderConfig),
supportPlaceholderService])

self.heightLayoutPolicy = .elastic(minHeight: 102, bottomSpace: 5, ignoreEmptyHint: true)
self.setup(hintService: HintService(configuration: .init(font: UIFont.systemFont(ofSize: 13, weight: .regular),
lineHeight: 17,
colors: ColorConfiguration(error: Color.UnderlineTextField.error,
normal: Color.UnderlineTextField.placeholder,
active: Color.UnderlineTextField.placeholder,
disabled: Color.UnderlineTextField.placeholder))))
self.heightLayoutPolicy = .elastic(policy: .init(minHeight: 102,
bottomOffset: 5,
ignoreEmptyHint: true))
self.validationPolicy = .afterChanges
}

Expand Down
Expand Up @@ -134,6 +134,7 @@ private extension UnderlinedFieldPreset {
textField.maxLength = 20
textField.setup(hint: L10n.Presets.Name.hint)
textField.trimSpaces = true
textField.setup(visibleHintStates: [.normal, .active, .error])

textField.maskFormatter = MaskTextFieldFormatter(mask: FormatterMasks.name, notations: FormatterMasks.customNotations())

Expand Down
16 changes: 12 additions & 4 deletions TextFieldsCatalog.xcodeproj/project.pbxproj
Expand Up @@ -34,6 +34,9 @@
9040B90523C6371000998989 /* TextFieldPasswordModeBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9040B90423C6371000998989 /* TextFieldPasswordModeBehavior.swift */; };
9040B90723C6374400998989 /* AnimationTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9040B90623C6374400998989 /* AnimationTime.swift */; };
9040B90923C637A200998989 /* FlexibleHeightPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9040B90823C637A200998989 /* FlexibleHeightPolicy.swift */; };
90793BA025A4B90200BC8582 /* AbstractHintService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90793B9F25A4B90200BC8582 /* AbstractHintService.swift */; };
90793BA825A4BAB000BC8582 /* HintService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90793BA725A4BAB000BC8582 /* HintService.swift */; };
90793C0025A4D47600BC8582 /* HintVisibleStates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90793BFF25A4D47600BC8582 /* HintVisibleStates.swift */; };
9082577523C367B5000767EB /* FieldContainerState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9082577423C367B5000767EB /* FieldContainerState.swift */; };
909CE8E8235350FF001E3B7F /* ValidationPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909CE8E623534E50001E3B7F /* ValidationPolicy.swift */; };
909DB887220355F000F0C5B7 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 909DB886220355F000F0C5B7 /* String.swift */; };
Expand Down Expand Up @@ -69,7 +72,6 @@
90C0992623C8EF8000312628 /* UITextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C0992523C8EF8000312628 /* UITextField.swift */; };
90C0992823C8F2FF00312628 /* UITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C0992723C8F2FF00312628 /* UITextView.swift */; };
90C6AC7023C617A400D13B8D /* LineService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C6AC6F23C617A400D13B8D /* LineService.swift */; };
90C6AC7223C6201000D13B8D /* HintService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C6AC7123C6201000D13B8D /* HintService.swift */; };
90C6C57223C8E360008DFBED /* FieldService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C6C57123C8E360008DFBED /* FieldService.swift */; };
90D18FCC2452EAD80072BD2C /* AssetManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D18FCB2452EAD80072BD2C /* AssetManager.swift */; };
90D18FCE2452ED1D0072BD2C /* MaskTextFieldFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D18FCD2452ED1D0072BD2C /* MaskTextFieldFormatter.swift */; };
Expand Down Expand Up @@ -134,6 +136,9 @@
9040B90423C6371000998989 /* TextFieldPasswordModeBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldPasswordModeBehavior.swift; sourceTree = "<group>"; };
9040B90623C6374400998989 /* AnimationTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimationTime.swift; sourceTree = "<group>"; };
9040B90823C637A200998989 /* FlexibleHeightPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexibleHeightPolicy.swift; sourceTree = "<group>"; };
90793B9F25A4B90200BC8582 /* AbstractHintService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbstractHintService.swift; sourceTree = "<group>"; };
90793BA725A4BAB000BC8582 /* HintService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HintService.swift; sourceTree = "<group>"; };
90793BFF25A4D47600BC8582 /* HintVisibleStates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HintVisibleStates.swift; sourceTree = "<group>"; };
9082577423C367B5000767EB /* FieldContainerState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FieldContainerState.swift; sourceTree = "<group>"; };
909CE8E623534E50001E3B7F /* ValidationPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidationPolicy.swift; sourceTree = "<group>"; };
909DB886220355F000F0C5B7 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,7 +174,6 @@
90C0992523C8EF8000312628 /* UITextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITextField.swift; sourceTree = "<group>"; };
90C0992723C8F2FF00312628 /* UITextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITextView.swift; sourceTree = "<group>"; };
90C6AC6F23C617A400D13B8D /* LineService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineService.swift; sourceTree = "<group>"; };
90C6AC7123C6201000D13B8D /* HintService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HintService.swift; sourceTree = "<group>"; };
90C6C57123C8E360008DFBED /* FieldService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FieldService.swift; sourceTree = "<group>"; };
90D18FCB2452EAD80072BD2C /* AssetManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetManager.swift; sourceTree = "<group>"; };
90D18FCD2452ED1D0072BD2C /* MaskTextFieldFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaskTextFieldFormatter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -396,6 +400,7 @@
9040B90323C636F600998989 /* Internal */,
9082577423C367B5000767EB /* FieldContainerState.swift */,
90AE548F220582C50054E875 /* HeightLayoutPolicy.swift */,
90793BFF25A4D47600BC8582 /* HintVisibleStates.swift */,
90F487082458329800931146 /* NativePlaceholderBehavior.swift */,
902CE2EE21FF702F00AC21D4 /* SharedRegex.swift */,
90E13DB02320FD3C004995E4 /* TextFieldMode.swift */,
Expand Down Expand Up @@ -467,7 +472,7 @@
children = (
90EE54BA24572DF10099C048 /* Placeholder */,
90C6C57123C8E360008DFBED /* FieldService.swift */,
90C6AC7123C6201000D13B8D /* HintService.swift */,
90793BA725A4BAB000BC8582 /* HintService.swift */,
90C6AC6F23C617A400D13B8D /* LineService.swift */,
);
path = AppearanceServices;
Expand All @@ -486,6 +491,7 @@
isa = PBXGroup;
children = (
90BEBBFC23C4D3FB00991105 /* InputFieldProtocol.swift */,
90793B9F25A4B90200BC8582 /* AbstractHintService.swift */,
90EE54B6245724E60099C048 /* AbstractPlaceholderService.swift */,
);
path = Support;
Expand Down Expand Up @@ -817,6 +823,7 @@
files = (
90C6AC7023C617A400D13B8D /* LineService.swift in Sources */,
902CE2FA21FF710400AC21D4 /* TextFieldConfigurations.swift in Sources */,
90793C0025A4D47600BC8582 /* HintVisibleStates.swift in Sources */,
90F4870724582BBA00931146 /* NativePlaceholderService.swift in Sources */,
90A066902530B59D0065CCD7 /* ToolBarInterface.swift in Sources */,
90BEBBFD23C4D3FB00991105 /* InputFieldProtocol.swift in Sources */,
Expand All @@ -839,6 +846,7 @@
9038640C21FF5A0100BAA761 /* ResetableField.swift in Sources */,
90BEBBF923C4D26E00991105 /* FloatingPlaceholderService.swift in Sources */,
90F487092458329800931146 /* NativePlaceholderBehavior.swift in Sources */,
90793BA825A4BAB000BC8582 /* HintService.swift in Sources */,
9038640821FF59BC00BAA761 /* InnerTextField.swift in Sources */,
90A32B7D228975730036C634 /* PlainPickerView.swift in Sources */,
90E13DAF2320FCAA004995E4 /* FieldState.swift in Sources */,
Expand All @@ -863,7 +871,7 @@
909CE8E8235350FF001E3B7F /* ValidationPolicy.swift in Sources */,
90A5D38D228E9AEF000322A2 /* AccessibilityIdentifiers.swift in Sources */,
902CE2F121FF707E00AC21D4 /* FormatterMasks.swift in Sources */,
90C6AC7223C6201000D13B8D /* HintService.swift in Sources */,
90793BA025A4B90200BC8582 /* AbstractHintService.swift in Sources */,
9038640A21FF59D300BAA761 /* Foundation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
13 changes: 2 additions & 11 deletions TextFieldsCatalog/Resources/Constants/HeightLayoutPolicy.swift
Expand Up @@ -11,18 +11,9 @@ import UIKit
public enum HeightLayoutPolicy {
/// Fixed height of text field
case fixed
/// Flexible height of text field.
/// Also allows you to configure minimal height for text field and bottom space value under hint label.
/// The resulting height is obtained as sum of y-coordinate of the hint label, it's height and bottomSpace value.
@available(*, deprecated, message: "Use `elastic(_,_,_)` instead with ignoreEmptyHint == false for backward capability. It's case will be removed later")
case flexible(CGFloat, CGFloat)
/**
Flexible height of text field.
Flexible height policy for text field.
Also allows you to configure minimal height for text field and bottom space value under hint label.

Final height depends on `ignoreEmptyHint` value:
- if `ignoreEmptyHint` == true, then if you hint is empty - then algoritm will use `minHeight` as view height
- if `ignoreEmptyHint` == false, then resulting height is obtained always as sum of y-coordinate of the hint label, it's height and bottomSpace value
*/
case elastic(minHeight: CGFloat, bottomSpace: CGFloat, ignoreEmptyHint: Bool)
case elastic(policy: FlexibleHeightPolicy)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще как то усложнилась логика - мы в elastic policy указываем flexible policy...
И вызов стал тяжелее
.elastic(policy: .init(minHeight: 77, bottomOffset: 5, ignoreEmptyHint: false))
Но это вкусовщина и ничего лучше я предложить не могу :(

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

понял, погляжу, но скорее всего тоже ничего предложить не смогу :(

}
33 changes: 33 additions & 0 deletions TextFieldsCatalog/Resources/Constants/HintVisibleStates.swift
@@ -0,0 +1,33 @@
//
// HintMessageState.swift
// TextFieldsCatalog
//
// Created by Александр Чаусов on 05.01.2021.
// Copyright © 2021 Александр Чаусов. All rights reserved.
//

/// Option set for managing possible visible states for fields hint message.
///
/// You can provide needed set to hint service init method or
/// change this set for specific field with appropriate method.
/// Hint or error messages will be shown only for specified states.
public struct HintVisibleStates: OptionSet {

// MARK: - Public Properties

public let rawValue: Int

public static let error = HintVisibleStates(rawValue: 1 << 0)
public static let disabled = HintVisibleStates(rawValue: 1 << 1)
public static let normal = HintVisibleStates(rawValue: 1 << 2)
public static let active = HintVisibleStates(rawValue: 1 << 3)

public static let all: HintVisibleStates = [.error, .disabled, .normal, .active]

// MARK: - Initialization

public init(rawValue: Int) {
self.rawValue = rawValue
}

}
Expand Up @@ -8,12 +8,16 @@

import UIKit

/**
Flexible height policy for text field/view.
Also allows you to configure minimal height for input field and bottom space value under hint label.
*/
public struct FlexibleHeightPolicy {

// MARK: - Properties

let minHeight: CGFloat
/// additional offset (usually used for offset between hintLabel and textView)
/// additional offset (usually used for offset between hintLabel and textField/textView)
let bottomOffset: CGFloat
/**
Final height depends on `ignoreEmptyHint` value:
Expand All @@ -26,7 +30,7 @@ public struct FlexibleHeightPolicy {

public init(minHeight: CGFloat,
bottomOffset: CGFloat,
ignoreEmptyHint: Bool = false) {
ignoreEmptyHint: Bool) {
self.minHeight = minHeight
self.bottomOffset = bottomOffset
self.ignoreEmptyHint = ignoreEmptyHint
Expand Down