Skip to content

Commit

Permalink
Remove snapshotting delay option.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Dec 20, 2024
1 parent d4a977d commit a7c3682
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
17 changes: 0 additions & 17 deletions ElementX/Sources/Other/Extensions/Snapshotting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
import Combine
import SwiftUI

struct SnapshotDelayPreferenceKey: PreferenceKey {
static var defaultValue: TimeInterval = 0.0

static func reduce(value: inout TimeInterval, nextValue: () -> TimeInterval) {
value = nextValue()
}
}

struct SnapshotPrecisionPreferenceKey: PreferenceKey {
static var defaultValue: Float = 1.0

Expand Down Expand Up @@ -74,13 +66,4 @@ extension SwiftUI.View {
.preference(key: SnapshotPerceptualPrecisionPreferenceKey.self, value: perceptualPrecision)
.preference(key: SnapshotFulfillmentPublisherPreferenceKey.self, value: FulfillmentPublisherEquatableWrapper(publisher: fulfillmentPublisher?.eraseToAnyPublisher()))
}

@available(*, deprecated, message: "Use the fulfillment variant instead")
func snapshotPreferences(delay: TimeInterval = .zero,
precision: Float = 1.0,
perceptualPrecision: Float = 0.98) -> some SwiftUI.View {
preference(key: SnapshotDelayPreferenceKey.self, value: delay)
.preference(key: SnapshotPrecisionPreferenceKey.self, value: precision)
.preference(key: SnapshotPerceptualPrecisionPreferenceKey.self, value: perceptualPrecision)
}
}
7 changes: 0 additions & 7 deletions PreviewTests/Sources/PreviewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class PreviewTests: XCTestCase {
let preferences = SnapshotPreferences()

let preferenceReadingView = preview.content
.onPreferenceChange(SnapshotDelayPreferenceKey.self) { preferences.delay = $0 }
.onPreferenceChange(SnapshotPrecisionPreferenceKey.self) { preferences.precision = $0 }
.onPreferenceChange(SnapshotPerceptualPrecisionPreferenceKey.self) { preferences.perceptualPrecision = $0 }
.onPreferenceChange(SnapshotFulfillmentPublisherPreferenceKey.self) { preferences.fulfillmentPublisher = $0?.publisher }
Expand All @@ -64,11 +63,6 @@ class PreviewTests: XCTestCase {
let imageRenderer = ImageRenderer(content: preferenceReadingView)
_ = imageRenderer.uiImage

// Delay the test now - a delay after creating the `snapshotView` results in the underlying view not getting updated for snapshotting.
if preferences.delay != .zero {
wait(for: preferences.delay)
}

if let fulfillmentPublisher = preferences.fulfillmentPublisher {
let deferred = deferFulfillment(fulfillmentPublisher) { $0 == true }
try await deferred.fulfill()
Expand Down Expand Up @@ -141,7 +135,6 @@ class PreviewTests: XCTestCase {
}

private class SnapshotPreferences: @unchecked Sendable {
var delay: TimeInterval = 0
var precision: Float = 1
var perceptualPrecision: Float = 1
var fulfillmentPublisher: AnyPublisher<Bool, Never>?
Expand Down

0 comments on commit a7c3682

Please sign in to comment.