pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.73k stars 565 forks source link

Adds drawHeirarchyInKeyWindow parameter #800

Closed Jelizondo closed 9 months ago

Jelizondo commented 9 months ago

What does this Pull Request do?

Adds the drawHeirarchyInKeyWindow parameter to the image method in UIViewController.swift file.

    public static func image(
      on config: ViewImageConfig,
      drawHierarchyInKeyWindow: Bool = false,
      precision: Float = 1,
      perceptualPrecision: Float = 1,
      size: CGSize? = nil,
      traits: UITraitCollection = .init()
    )
      -> Snapshotting
    {

      return SimplySnapshotting.image(
        precision: precision, perceptualPrecision: perceptualPrecision, scale: traits.displayScale
      ).asyncPullback { viewController in
        snapshotView(
          config: size.map { .init(safeArea: config.safeArea, size: $0, traits: config.traits) }
            ?? config,
          drawHierarchyInKeyWindow: drawHierarchyInKeyWindow,
          traits: traits,
          view: viewController.view,
          viewController: viewController
        )
      }
    }

Use case:

Noticed other methods similar to this one had the drawHierarchyInKeyWindow parameter. For our use case we are using UIViewControllers as containers to SwiftUI views that contain UIVisualEffects. Without this parameter the UIVisualEffect would appear transparent in the snapshots.

Is this something we can add? Thanks!

Jelizondo commented 9 months ago

Closed in favor of https://github.com/pointfreeco/swift-snapshot-testing/pull/801!