Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/iOSSnapshotTestCase/SwiftSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ public extension FBSnapshotTestCase {
FBSnapshotVerifyViewOrLayer(layer, identifier: identifier, suffixes: suffixes, perPixelTolerance: perPixelTolerance, overallTolerance: overallTolerance, file: file, line: line)
}

@available(iOS 13, *)
func FBSnapshotVerifyViewForLightDarkMode(_ view: UIView, identifier: String? = nil, delay: TimeInterval = 0, perPixelTolerance: CGFloat = 0, overallTolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
let viewController = UIViewController()
viewController.view.addSubview(view)

FBSnapshotVerifyViewControllerForLightDarkMode(viewController, identifier: identifier, delay: delay, perPixelTolerance: perPixelTolerance, overallTolerance: overallTolerance, file: file, line: line)
}

@available(iOS 13, *)
func FBSnapshotVerifyViewControllerForLightDarkMode(_ viewController: UIViewController, identifier: String? = nil, delay: TimeInterval = 0, perPixelTolerance: CGFloat = 0, overallTolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
let navigationController = UINavigationController(rootViewController: viewController)
let window = UIWindow()
window.rootViewController = navigationController
window.makeKeyAndVisible()

// Take snapshot in light mode
navigationController.overrideUserInterfaceStyle = .light
RunLoop.main.run(until: Date(timeIntervalSinceNow: delay))

let lightId = [identifier, "light"].compactMap { $0 }.joined(separator: "_")
FBSnapshotVerifyView(navigationController.view, identifier: lightId, suffixes: ["Light"], perPixelTolerance: 0, overallTolerance: 0, file: file, line: line)

// Take snapshot in dark mode
window.rootViewController = nil
window.rootViewController = navigationController
navigationController.overrideUserInterfaceStyle = .dark
RunLoop.main.run(until: Date(timeIntervalSinceNow: delay))

let darkId = [identifier, "dark"].compactMap { $0 }.joined(separator: "_")
FBSnapshotVerifyView(navigationController.view, identifier: darkId, suffixes: ["Dark"], perPixelTolerance: 0, overallTolerance: 0, file: file, line: line)

window.rootViewController = nil
}

private func FBSnapshotVerifyViewOrLayer(_ viewOrLayer: AnyObject, identifier: String? = nil, suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), perPixelTolerance: CGFloat = 0, overallTolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
let envReferenceImageDirectory = self.getReferenceImageDirectory(withDefault: nil)
let envImageDiffDirectory = self.getImageDiffDirectory(withDefault: nil)
Expand Down