Skip to content

Commit 7d5123f

Browse files
author
Build Pipeline
committed
Merge branch 'release/1.4.0'
2 parents a1830e6 + b7399cb commit 7d5123f

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

Example/FieldValidatorSample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
233233
GCC_WARN_UNUSED_FUNCTION = YES;
234234
GCC_WARN_UNUSED_VARIABLE = YES;
235-
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
235+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
236236
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
237237
MTL_FAST_MATH = YES;
238238
ONLY_ACTIVE_ARCH = YES;
@@ -286,7 +286,7 @@
286286
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
287287
GCC_WARN_UNUSED_FUNCTION = YES;
288288
GCC_WARN_UNUSED_VARIABLE = YES;
289-
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
289+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
290290
MTL_ENABLE_DEBUG_INFO = NO;
291291
MTL_FAST_MATH = YES;
292292
SDKROOT = iphoneos;

Example/FieldValidatorSample/ContentView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ struct FormWithValidator : View {
4646
return nil
4747
}
4848
.autocapitalization(.none)
49-
.padding( usernameValid.padding )
50-
.overlay( ValidatorMessageInline( message: usernameValid.errorMessageOrNilAtBeginning ),alignment: .bottom)
49+
.padding( .bottom, 25 )
50+
.overlay( ValidatorMessageInline( message: usernameValid.errorMessage/*OrNilAtBeginning*/ )
51+
,alignment: .bottom)
5152

5253
}
5354

@@ -63,7 +64,7 @@ struct FormWithValidator : View {
6364
return nil
6465
}
6566
.autocapitalization(.none)
66-
.padding( passwordToggleValid.padding )
67+
.padding( .bottom, 25 )
6768
.overlay( ValidatorMessageInline( message: passwordToggleValid.errorMessageOrNilAtBeginning ),alignment: .bottom)
6869
Button( action: {
6970
self.passwordHidden.toggle()

Example/FieldValidatorSample/PasswordToggleField.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct PasswordToggleField : View {
3535
}
3636
}
3737
.onAppear {
38+
print("\(type(of: self)) onAppear")
3839
self.field.doValidate()
3940
}
4041

FieldValidatorLibrary.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
1616
#
1717

1818
spec.name = "FieldValidatorLibrary"
19-
spec.version = "1.3.0"
19+
spec.version = "1.4.0"
2020
spec.summary = "SwiftUI library supporting 'Form Validation'"
2121

2222
# This description is used to generate tags and improve search results.
@@ -81,7 +81,7 @@ Pod::Spec.new do |spec|
8181
# Supports git, hg, bzr, svn and HTTP.
8282
#
8383

84-
spec.source = { :git => "https://github.com/bsorrentino/swiftui-fieldvalidator.git", :tag => "v1.3.0" }
84+
spec.source = { :git => "https://github.com/bsorrentino/swiftui-fieldvalidator.git", :tag => "v1.4.0" }
8585

8686

8787
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

Sources/FieldValidatorLibrary/FieldValidator.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ public struct FieldChecker {
1818
internal var numberOfCheck = 0
1919
public var errorMessage:String?
2020

21-
public var isFirstCheck:Bool { numberOfCheck == 1 }
21+
public var isFirstCheck:Bool { numberOfCheck == 0 }
2222

2323
public var valid:Bool {
2424
self.errorMessage == nil
2525
}
2626
public init( errorMessage:String? = nil ) {
2727
self.errorMessage = errorMessage
2828
}
29+
2930
}
3031

3132
@available(iOS 13, *)
@@ -38,7 +39,9 @@ public class FieldValidator<T> : ObservableObject where T : Hashable {
3839
@Published public var value:T
3940
{
4041
willSet {
41-
self.doValidate(newValue)
42+
if( newValue != value) {
43+
self.doValidate(value: newValue)
44+
}
4245
}
4346
didSet {
4447
self.bindValue = self.value
@@ -57,14 +60,19 @@ public class FieldValidator<T> : ObservableObject where T : Hashable {
5760
self._checker = checker
5861
}
5962

60-
public func doValidate( _ newValue:T? = nil ) -> Void {
61-
62-
self.checker.errorMessage =
63-
(newValue != nil) ?
64-
self.validator( newValue! ) :
65-
self.validator( self.value )
66-
self.checker.numberOfCheck += 1
63+
fileprivate func doValidate( value newValue:T ) -> Void {
64+
DispatchQueue.main.async {
65+
self.checker.errorMessage = self.validator( newValue )
66+
self.checker.numberOfCheck += 1
67+
}
6768
}
69+
70+
public func doValidate() -> Void {
71+
DispatchQueue.main.async {
72+
self.checker.errorMessage = self.validator( self.value )
73+
}
74+
}
75+
6876
}
6977

7078

@@ -116,6 +124,7 @@ public struct TextFieldWithValidator : ViewWithFieldValidator {
116124
VStack {
117125
TextField( title ?? "", text: $field.value, onCommit: execIfValid(self.onCommit) )
118126
.onAppear { // run validation on appear
127+
// print("\(type(of: self)) onAppear")
119128
self.field.doValidate()
120129
}
121130
}
@@ -148,9 +157,11 @@ public struct SecureFieldWithValidator : ViewWithFieldValidator {
148157
}
149158

150159
public var body: some View {
160+
151161
VStack {
152162
SecureField( title ?? "", text: $field.value, onCommit: execIfValid(self.onCommit) )
153163
.onAppear { // run validation on appear
164+
// print("\(type(of: self)) onAppear")
154165
self.field.doValidate()
155166
}
156167
}

0 commit comments

Comments
 (0)