Skip to content

Commit

Permalink
Merge pull request #793 from kiwicom/792-is-snapshot-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sjavora authored Apr 12, 2024
2 parents bebbc8e + 7f8b6dd commit 2e10df9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Sources/Orbit/Support/Environment Keys/IsSnapshotTestingKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

enum IsSnapshotTestingKey: EnvironmentKey {
static let defaultValue = false
}

public extension EnvironmentValues {

/// Indicates whether the view is being rendered during snapshot testing.
///
/// Used to modify the view to prevent snapshots from failing due to
/// system animations or timing-related glitches.
var isSnapshotTesting: Bool {
get { self[IsSnapshotTestingKey.self] }
set { self[IsSnapshotTestingKey.self] = newValue }
}
}
3 changes: 2 additions & 1 deletion Sources/Orbit/Support/TextFields/TextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public struct TextField: UIViewRepresentable, TextFieldBuildable {
@Environment(\.textFontWeight) private var textFontWeight
@Environment(\.textColor) private var textColor
@Environment(\.textSize) private var textSize
@Environment(\.isSnapshotTesting) private var isSnapshotTesting

@Binding private var value: String
private var prompt: String
Expand All @@ -52,7 +53,7 @@ public struct TextField: UIViewRepresentable, TextFieldBuildable {

textField.clearsOnBeginEditing = false
textField.adjustsFontForContentSizeCategory = false
textField.tintColor = .blueNormal
textField.tintColor = context.environment.isSnapshotTesting ? .clear : .blueNormal

textField.setContentHuggingPriority(.defaultHigh, for: .vertical)
textField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
Expand Down

0 comments on commit 2e10df9

Please sign in to comment.