Skip to content

Conversation

@stotic-dev
Copy link
Contributor

@stotic-dev stotic-dev commented Dec 20, 2025

Short description 📝

Describe here the purpose of your PR.

To get a snapshot of a Liquid Glass component, you need to modify the template and set drawHierarchyInKeyWindow to true as mentioned in #136. However, this is a bit of a hassle, so we've made it possible to set drawHierarchyInKeyWindow to true as an optional setting in prefire.yaml.

Solution 📦

Describe the solution you came up with and the reasons that led you to that solution. If you thought about other solutions don't forget about mentioning them.

The use case we wanted to solve was making it easy to obtain Liquid Glass components. Because Liquid Glass affects the entire app, we determined that there was no setting to switch drawHierarchyInKeyWindow for each Preview. Therefore, our current solution makes it possible to specify a common setting for drawHierarchyInKeyWindow for all Previews.

If there are some use cases where you want to set drawHierarchyInKeyWindow to false, we believe that a separate solution would be to make it possible to specify drawHierarchyInKeyWindow with the snapshot modifier.

Implementation 👩‍💻👨‍💻

Detail in a checklist the steps that you took to implement the PR.

  • Modify the test_configuration in Example/.prefire.yml as follows:
    • Set required_os to 26
    • Add draw_hierarchy_in_key_window_default_enabled: true
  • Add the following Preview under Example/Shared/Examples
#Preview("LiquidGlass") {
    NavigationStack {
        Text("Liquid Glass View")
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    Button {} label: {
                        Image(systemName: "plus")
                    }
                }
            }
    }
}
  • Run the PrefireExampleTests test and confirm that the LiquidGlass snapshot has the LiquidGlass effect as shown below.
image

| `sources` | List of Swift files or folders to scan for previews. Defaults to inferred from the target |
| `imports` | Extra imports added to the generated test or playbook file |
| `testable_imports` | Extra `@testable` imports added to allow test visibility |
| `draw_hierarchy_in_key_window_default_enabled` | Specifies whether to use the simulator's key window to snapshot the UI, rendering `UIAppearance` and `UIVisualEffect`. This option requires a host application for testing and does not work with framework test targets. Default: `true` |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't backward compatibility break off here?
It is important to understand what the default parameter is in SwiftSnapshotTesting.

@BarredEwe
Copy link
Owner

Thanks a lot for the improvements!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants