Skip to content

Commit

Permalink
Mark method as available for iOS 13 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
steve509 committed Dec 4, 2021
1 parent 569a2fd commit a5b642a
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/iOSSnapshotTestCase/SwiftSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,38 @@ 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) {
if #available(iOS 13.0, *) {
let navigationController = UINavigationController(rootViewController: viewController)
let window = UIWindow()
window.rootViewController = navigationController
window.makeKeyAndVisible()
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))
// 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)
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))
// 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)
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
}
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) {
Expand Down

0 comments on commit a5b642a

Please sign in to comment.