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 |
---|---|
![]() |
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.
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 EnvironmentVariationPreview
.environmentVariations()
view modifier to your preview.[.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 {
MyView()
.environmentVariations([
.colorScheme(.light),
.colorScheme(.dark),
.layoutDirection(.rightToLeft),
.dynamicTypeSize(.xSmall),
.dynamicTypeSize(.large),
.dynamicTypeSize(.xxxLarge)
])
}
}
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:
If you have any questions or need help, feel free to open an issue or reach out to the maintainers. We appreciate your support!
link |
Stars: 1 |
Last commit: 5 weeks ago |
Temporary disabling of ScrollBounceBehavior
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics