Swiftpack.co - mackoj/EnvironmentVariationPreview as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mackoj.
mackoj/EnvironmentVariationPreview 1.1.2
EnvironmentVariationPreview is a SwiftUI library designed to simplify the process of previewing your SwiftUI views in a variety of environments.
⭐️ 1
🕓 5 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/mackoj/EnvironmentVariationPreview.git", from: "1.1.2")


EnvironmentVariationPreview is a SwiftUI library designed to simplify the process of previewing your SwiftUI views in a variety of environments. The code of this library work exclusively with the simulator.

video image
Capture d’écran 2023-03-28 à 22 28 09


Maintaining an app that must work across diverse environments (such as varying dynamic sizes, appearances, accessibility settings, locales, screen sizes, etc.) can be challenging. One way to address this issue is through snapshot testing, which enables you to capture snapshots of all possible configurations and compare them to expected results to prevent regressions. EnvironmentVariationPreview was created to facilitate snapshot testing for your UI library and to provide a streamlined approach for testing your UI against different environment settings.

Capture d’écran 2023-03-28 à 22 29 38


  • Effortlessly modify the rendering of SwiftUI previews with a wide range of environment values.
  • Extensive support for various environment values, including accessibility settings, color schemes, fonts, layout direction, and more.
  • Seamless integration with your SwiftUI projects, enhancing your development workflow.


Swift Package Manager

To add SwiftUI Environment Value Preview to your project using Swift Package Manager, add the following dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/mackoj/EnvironmentVariationPreview.git", from: "1.0.0")


To use EnvironmentVariationPreview in your SwiftUI project, follow these steps:

  • Import the library in your SwiftUI file: import EnvironmentVariationPreview
  • Apply the .environmentVariations() view modifier to your preview.
  • Provide an array of environment values you wish to preview, such as [.colorScheme(.light), .colorScheme(.dark), .layoutDirection(.rightToLeft), .dynamicTypeSize(.xSmall), .dynamicTypeSize(.large), .dynamicTypeSize(.xxxLarge)].

For example:

import Foundation
import SwiftUI
import EnvironmentVariationPreview

struct MyView_Previews: PreviewProvider {
  static var previews: some View {

In order to make it work you just have to add a view modifier in your SwiftUI preview.


SwiftUI Environment Value Preview is released under the MIT License. See LICENSE for details.


We welcome contributions from the community to help improve and expand EnvironmentVariationPreview. If you'd like to contribute, please follow these steps:

  • Fork the repository on GitHub.
  • Create a new branch with a descriptive name, e.g., feature/new-environment-value.
  • Implement your changes or bug fixes, ensuring that your code is clean and well-documented.
  • Submit a pull request, detailing your changes and the purpose behind them.
  • Make sure to keep your pull request up-to-date with the base branch, resolving any conflicts that may arise.
  • By contributing, you agree that your contributions will be licensed under the same license as the original project.

If you have any questions or need help, feel free to open an issue or reach out to the maintainers. We appreciate your support!


Stars: 1
Last commit: 5 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

5 weeks ago

Temporary disabling of ScrollBounceBehavior

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics