Skip to content

Commit

Permalink
Minor adjustments based on the evaluation within SpeziAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Nov 3, 2023
1 parent 8c6181a commit bd04a27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ extension View {
}
}

public func receiveValidation<Value>(in state: ValidationState<Value>.Binding) -> some View {

Check failure on line 30 in Sources/SpeziValidation/ValidationState/ReceiveValidationModifier.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Missing Docs Violation: public declarations should be documented (missing_docs)
onPreferenceChange(CapturedValidationStateKey<Value>.self) { entries in
state.wrappedValue = ValidationContext(entries: entries)
}
}

Check warning on line 34 in Sources/SpeziValidation/ValidationState/ReceiveValidationModifier.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziValidation/ValidationState/ReceiveValidationModifier.swift#L30-L34

Added lines #L30 - L34 were not covered by tests

public func receiveValidation<Value>(in state: ValidationState<Value>.Binding, focus: FocusState<Value?>.Binding) -> some View {

Check failure on line 36 in Sources/SpeziValidation/ValidationState/ReceiveValidationModifier.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Missing Docs Violation: public declarations should be documented (missing_docs)
onPreferenceChange(CapturedValidationStateKey<Value>.self) { entries in
state.wrappedValue = ValidationContext(entries: entries, focus: focus)
Expand Down
16 changes: 13 additions & 3 deletions Sources/SpeziValidation/ValidationState/ValidationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct ValidationContext<FocusValue: Hashable> {
///
/// Please refer to the documentation of ``ValidationEngine/inputValid``.
@MainActor
public var inputValid: Bool {
public var allInputValid: Bool {
entries.allSatisfy { $0.inputValid }
}

Expand All @@ -46,6 +46,14 @@ public struct ValidationContext<FocusValue: Hashable> {
result.append(contentsOf: state.displayedValidationResults)
}
}

Check warning on line 48 in Sources/SpeziValidation/ValidationState/ValidationContext.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziValidation/ValidationState/ValidationContext.swift#L44-L48

Added lines #L44 - L48 were not covered by tests

/// Flag that indicates if ``displayedValidationResults`` returns any ``FailedValidationResult``.
///
/// Please refer to the documentation of ``ValidationEngine/isDisplayingValidationErrors``.
@MainActor
public var isDisplayingValidationErrors: Bool {
entries.contains { $0.isDisplayingValidationErrors }
}

Check warning on line 56 in Sources/SpeziValidation/ValidationState/ValidationContext.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziValidation/ValidationState/ValidationContext.swift#L54-L56

Added lines #L54 - L56 were not covered by tests


init() {
Expand Down Expand Up @@ -76,15 +84,17 @@ public struct ValidationContext<FocusValue: Hashable> {
/// If provided, the `FocusState` will be automatically set to the first field
/// that reported a failed validation result.
///
/// - Parameter switchFocus: Flag that controls the automatic focus switching mechanisms. Default turned on.
/// - Returns: Returns `true` if all subviews reported valid data. Returns `false` if at least one
/// subview reported invalid data.
@MainActor
@discardableResult
public func validateSubviews() -> Bool {
public func validateSubviews(switchFocus: Bool = true) -> Bool {
let failedFields = collectFailedFields()

if let first = failedFields.first {
if let focusState,
if switchFocus,
let focusState,
let field = first.field {
focusState.wrappedValue = field
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ValidationControls<FocusValue: Hashable>: View {

var body: some View {
Text("Has Engines: \(!validation.isEmpty ? "Yes" : "No")")
Text("Input Valid: \(validation.inputValid ? "Yes" : "No")")
Text("Input Valid: \(validation.allInputValid ? "Yes" : "No")")
if let lastValid {
Text("Last state: \(lastValid ? "valid" : "invalid")")
}
Expand Down

0 comments on commit bd04a27

Please sign in to comment.