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 drawHierarchyInKeyWindow parameter #801

Open Jelizondo opened 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
        )
      }
    }

We tried to extend the function in our project but got errors because snapshotView is private!

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 8 months ago

Hello again! I would appreciate a review here! Is this something we can add? Thanks!